Fix playlists video count for playlists cataloged as "Mix" and "1 video"

This commit is contained in:
Fijxu 2025-10-08 12:44:05 -03:00
parent 325e013e0d
commit 7064f4898e
No known key found for this signature in database
GPG Key ID: 32C1DDF333EDA6A4
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
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
locale = "en-US" if !LOCALES.has_key?(locale)
if count.is_a?(String)
return translate(locale, count)
end
# Retrieve suffix
suffix = I18next::Plurals::RESOLVER.get_suffix(locale, count)
plural_key = key + suffix

View File

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

View File

@ -674,9 +674,17 @@ private module Parsers
.compact_map(&.dig?("thumbnailOverlayBadgeViewModel", "thumbnailBadges").try &.as_a)
.flatten
.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")
title = metadata.dig("title", "content").as_s
@ -695,7 +703,7 @@ private module Parsers
id: playlist_id,
author: author_fallback.name,
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,
thumbnail: thumbnail,
author_verified: false,