Fix missing author_thumbnail and premiere_timestamp for SearchVideo on channel routes

This commit is contained in:
sergiobuilds 2026-08-12 01:47:08 +09:00
parent 471c1170e6
commit b793ad5c40
2 changed files with 17 additions and 14 deletions

View File

@ -11,6 +11,7 @@ module Invidious::Channel::Tabs
def get_videos(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest") def get_videos(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest")
return get_videos( return get_videos(
channel.author, channel.ucid, channel.author, channel.ucid,
author_thumbnail: channel.author_thumbnail,
continuation: continuation, sort_by: sort_by continuation: continuation, sort_by: sort_by
) )
end end
@ -21,15 +22,16 @@ module Invidious::Channel::Tabs
def get_videos(channel : InvidiousChannel, *, continuation : String? = nil, sort_by = "newest") def get_videos(channel : InvidiousChannel, *, continuation : String? = nil, sort_by = "newest")
return get_videos( return get_videos(
channel.author, channel.id, channel.author, channel.id,
author_thumbnail: channel.author_thumbnail,
continuation: continuation, sort_by: sort_by continuation: continuation, sort_by: sort_by
) )
end end
def get_videos(author : String, ucid : String, *, continuation : String? = nil, sort_by = "newest") def get_videos(author : String, ucid : String, *, continuation : String? = nil, sort_by = "newest", author_thumbnail : String? = nil)
continuation ||= make_initial_videos_ctoken(ucid, sort_by) continuation ||= make_initial_videos_ctoken(ucid, sort_by)
initial_data = YoutubeAPI.browse(continuation: continuation) initial_data = YoutubeAPI.browse(continuation: continuation)
return extract_items(initial_data, author, ucid) return extract_items(initial_data, author, ucid, author_thumbnail)
end end
def get_60_videos(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest") def get_60_videos(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest")
@ -59,7 +61,7 @@ module Invidious::Channel::Tabs
continuation ||= make_initial_shorts_ctoken(channel.ucid, sort_by) continuation ||= make_initial_shorts_ctoken(channel.ucid, sort_by)
initial_data = YoutubeAPI.browse(continuation: continuation) initial_data = YoutubeAPI.browse(continuation: continuation)
return extract_items(initial_data, channel.author, channel.ucid) return extract_items(initial_data, channel.author, channel.ucid, channel.author_thumbnail)
end end
# ------------------- # -------------------
@ -70,7 +72,7 @@ module Invidious::Channel::Tabs
continuation ||= make_initial_livestreams_ctoken(channel.ucid, sort_by) continuation ||= make_initial_livestreams_ctoken(channel.ucid, sort_by)
initial_data = YoutubeAPI.browse(continuation: continuation) initial_data = YoutubeAPI.browse(continuation: continuation)
return extract_items(initial_data, channel.author, channel.ucid) return extract_items(initial_data, channel.author, channel.ucid, channel.author_thumbnail)
end end
def get_60_livestreams(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest") def get_60_livestreams(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest")

View File

@ -26,7 +26,7 @@ private ITEM_PARSERS = {
private alias InitialData = Hash(String, JSON::Any) private alias InitialData = Hash(String, JSON::Any)
record AuthorFallback, name : String, id : String record AuthorFallback, name : String, id : String, thumbnail : String? = nil
# Namespace for logic relating to parsing InnerTube data into various datastructs. # Namespace for logic relating to parsing InnerTube data into various datastructs.
# #
@ -618,9 +618,9 @@ private module Parsers
views: view_count, views: view_count,
description_html: "", description_html: "",
length_seconds: duration, length_seconds: duration,
premiere_timestamp: Time.unix(0), premiere_timestamp: nil,
author_verified: false, author_verified: false,
author_thumbnail: nil, author_thumbnail: author_fallback.thumbnail,
badges: VideoBadges::None, badges: VideoBadges::None,
}) })
end end
@ -684,9 +684,9 @@ private module Parsers
views: view_count, views: view_count,
description_html: "", description_html: "",
length_seconds: length_seconds || 0, length_seconds: length_seconds || 0,
premiere_timestamp: Time.unix(0), premiere_timestamp: nil,
author_verified: false, author_verified: false,
author_thumbnail: nil, author_thumbnail: author_fallback.thumbnail,
badges: VideoBadges::None, badges: VideoBadges::None,
}) })
# If it's a playlist, it's content_type would be "LOCKUP_CONTENT_TYPE_PLAYLIST" # If it's a playlist, it's content_type would be "LOCKUP_CONTENT_TYPE_PLAYLIST"
@ -881,9 +881,9 @@ private module Parsers
views: view_count, views: view_count,
description_html: "", description_html: "",
length_seconds: duration, length_seconds: duration,
premiere_timestamp: Time.unix(0), premiere_timestamp: nil,
author_verified: false, author_verified: false,
author_thumbnail: nil, author_thumbnail: author_fallback.thumbnail,
badges: VideoBadges::None, badges: VideoBadges::None,
}) })
end end
@ -1147,11 +1147,11 @@ end
# Parses an item from Youtube's JSON response into a more usable structure. # Parses an item from Youtube's JSON response into a more usable structure.
# The end result can either be a SearchVideo, SearchPlaylist or SearchChannel. # The end result can either be a SearchVideo, SearchPlaylist or SearchChannel.
def parse_item(item : JSON::Any, author_fallback : String? = "", author_id_fallback : String? = "") def parse_item(item : JSON::Any, author_fallback : String? = "", author_id_fallback : String? = "", author_thumbnail_fallback : String? = nil)
# We "allow" nil values but secretly use empty strings instead. This is to save us the # We "allow" nil values but secretly use empty strings instead. This is to save us the
# hassle of modifying every author_fallback and author_id_fallback arg usage # hassle of modifying every author_fallback and author_id_fallback arg usage
# which is more often than not nil. # which is more often than not nil.
author_fallback = AuthorFallback.new(author_fallback || "", author_id_fallback || "") author_fallback = AuthorFallback.new(author_fallback || "", author_id_fallback || "", author_thumbnail_fallback)
# Cycles through all of the item parsers and attempt to parse the raw YT JSON data. # Cycles through all of the item parsers and attempt to parse the raw YT JSON data.
# Each parser automatically validates the data given to see if the data is # Each parser automatically validates the data given to see if the data is
@ -1201,12 +1201,13 @@ def extract_items(
initial_data : InitialData, initial_data : InitialData,
author_fallback : String? = nil, author_fallback : String? = nil,
author_id_fallback : String? = nil, author_id_fallback : String? = nil,
author_thumbnail_fallback : String? = nil,
) : {Array(SearchItem), String?} ) : {Array(SearchItem), String?}
items = [] of SearchItem items = [] of SearchItem
continuation = nil continuation = nil
extract_items(initial_data) do |item| extract_items(initial_data) do |item|
parsed = parse_item(item, author_fallback, author_id_fallback) parsed = parse_item(item, author_fallback, author_id_fallback, author_thumbnail_fallback)
case parsed case parsed
when .is_a?(Continuation) then continuation = parsed.token when .is_a?(Continuation) then continuation = parsed.token