Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for author thumbnails in search api for videos #5072

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion src/invidious/helpers/serialized_yt_data.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct SearchVideo
property length_seconds : Int32
property premiere_timestamp : Time?
property author_verified : Bool
property author_thumbnail : String?
property badges : VideoBadges

def to_xml(auto_generated, query_params, xml : XML::Builder)
Expand Down Expand Up @@ -88,6 +89,24 @@ struct SearchVideo
json.field "authorUrl", "/channel/#{self.ucid}"
json.field "authorVerified", self.author_verified

author_thumbnail = self.author_thumbnail

if author_thumbnail
json.field "authorThumbnails" do
json.array do
qualities = {32, 48, 76, 100, 176, 512}

qualities.each do |quality|
json.object do
json.field "url", author_thumbnail.gsub(/=s\d+/, "=s#{quality}")
json.field "width", quality
json.field "height", quality
end
end
end
end
end

json.field "videoThumbnails" do
Invidious::JSONify::APIv1.thumbnails(json, self.id)
end
Expand Down Expand Up @@ -223,7 +242,7 @@ struct SearchChannel

qualities.each do |quality|
json.object do
json.field "url", self.author_thumbnail.gsub(/=\d+/, "=s#{quality}")
json.field "url", self.author_thumbnail.gsub(/=s\d+/, "=s#{quality}")
json.field "width", quality
json.field "height", quality
end
Expand Down
1 change: 1 addition & 0 deletions src/invidious/routes/feeds.cr
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ module Invidious::Routes::Feeds
length_seconds: 0,
premiere_timestamp: nil,
author_verified: false,
author_thumbnail: nil,
badges: VideoBadges::None,
})
end
Expand Down
5 changes: 5 additions & 0 deletions src/invidious/yt_backend/extractors.cr
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private module Parsers
author_id = author_fallback.id
end

author_thumbnail = item_contents.dig?("channelThumbnailSupportedRenderers", "channelThumbnailWithLinkRenderer", "thumbnail", "thumbnails", 0, "url").try &.as_s

author_verified = has_verified_badge?(item_contents["ownerBadges"]?)

# For live videos (and possibly recently premiered videos) there is no published information.
Expand Down Expand Up @@ -148,6 +150,7 @@ private module Parsers
length_seconds: length_seconds,
premiere_timestamp: premiere_timestamp,
author_verified: author_verified,
author_thumbnail: author_thumbnail,
badges: badges,
})
end
Expand Down Expand Up @@ -579,6 +582,7 @@ private module Parsers
length_seconds: duration,
premiere_timestamp: Time.unix(0),
author_verified: false,
author_thumbnail: nil,
badges: VideoBadges::None,
})
end
Expand Down Expand Up @@ -708,6 +712,7 @@ private module Parsers
length_seconds: duration,
premiere_timestamp: Time.unix(0),
author_verified: false,
author_thumbnail: nil,
badges: VideoBadges::None,
})
end
Expand Down
Loading