Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/invidious/helpers/i18n.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/invidious/helpers/serialized_yt_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/invidious/yt_backend/extractors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading