Merge 7064f4898e28791a6af5c2adeec3ab5370d0b901 into 5cfe294063c9317928d8da3387004e3eaddc991a

This commit is contained in:
Fijxu 2025-10-20 09:18:41 +05:30 committed by GitHub
commit 71827ad74c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View File

@ -144,10 +144,14 @@ def translate(locale : String?, key : String, text : String | Hash(String, Strin
return translation return translation
end end
def translate_count(locale : String, key : String, count : Int, format = NumberFormatting::None) : String def translate_count(locale : String, key : String, count : Int | String, format = NumberFormatting::None) : String
# Fallback on english if locale doesn't exist # Fallback on english if locale doesn't exist
locale = "en-US" if !LOCALES.has_key?(locale) locale = "en-US" if !LOCALES.has_key?(locale)
if count.is_a?(String)
return translate(locale, count)
end
# Retrieve suffix # Retrieve suffix
suffix = I18next::Plurals::RESOLVER.get_suffix(locale, count) suffix = I18next::Plurals::RESOLVER.get_suffix(locale, count)
plural_key = key + suffix plural_key = key + suffix

View File

@ -167,7 +167,7 @@ struct SearchPlaylist
property id : String property id : String
property author : String property author : String
property ucid : String property ucid : String
property video_count : Int32 property video_count : Int32 | String
property videos : Array(SearchPlaylistVideo) property videos : Array(SearchPlaylistVideo)
property thumbnail : String? property thumbnail : String?
property author_verified : Bool property author_verified : Bool

View File

@ -674,9 +674,17 @@ private module Parsers
.compact_map(&.dig?("thumbnailOverlayBadgeViewModel", "thumbnailBadges").try &.as_a) .compact_map(&.dig?("thumbnailOverlayBadgeViewModel", "thumbnailBadges").try &.as_a)
.flatten .flatten
.find(nil, &.dig?("thumbnailBadgeViewModel", "text").try { |node| .find(nil, &.dig?("thumbnailBadgeViewModel", "text").try { |node|
{"episodes", "videos"}.any? { |str| node.as_s.ends_with?(str) } {"episodes", "videos", "video", "Mix"}.any? { |str| node.as_s.ends_with?(str) }
}) })
.try &.dig("thumbnailBadgeViewModel", "text").as_s.to_i(strict: false) .try &.dig("thumbnailBadgeViewModel", "text").to_s
if video_count
# Tries to convert it to a number, video_count_n will be nil
# if `video_count` equals to `"Mix"`.
if video_count_n = video_count.to_i?(strict: false)
video_count = video_count_n
end
end
metadata = item_contents.dig("metadata", "lockupMetadataViewModel") metadata = item_contents.dig("metadata", "lockupMetadataViewModel")
title = metadata.dig("title", "content").as_s title = metadata.dig("title", "content").as_s
@ -695,7 +703,7 @@ private module Parsers
id: playlist_id, id: playlist_id,
author: author_fallback.name, author: author_fallback.name,
ucid: author_fallback.id, ucid: author_fallback.id,
video_count: video_count || -1, video_count: video_count || -1, # -1 if a fallback value in case video count is nil
videos: [] of SearchPlaylistVideo, videos: [] of SearchPlaylistVideo,
thumbnail: thumbnail, thumbnail: thumbnail,
author_verified: false, author_verified: false,