mirror of
https://github.com/iv-org/invidious.git
synced 2026-08-16 21:10:53 -05:00
channels: keep rendering carousel channels without an avatar
A missing avatar is a cosmetic gap, not a broken payload: raising on it brings back the 500 this PR is meant to remove. The pageHeaderRenderer branch already falls back to an empty string, so this matches it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
c81452f2a4
commit
2c6f804d5a
@ -109,6 +109,29 @@ Spectator.describe "extract_auto_generated_channel_header" do
|
||||
end.to raise_error(InfoException)
|
||||
end
|
||||
|
||||
it "still renders a carousel channel that carries no avatar" do
|
||||
initdata = JSON.parse(<<-JSON).as_h
|
||||
{
|
||||
"header": {
|
||||
"carouselHeaderRenderer": {
|
||||
"contents": [
|
||||
{
|
||||
"topicChannelDetailsRenderer": {
|
||||
"title": {"simpleText": "Sports"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
JSON
|
||||
|
||||
header = extract_auto_generated_channel_header(initdata, "UCEgdi0XIXXZ-qJOFPf4JSKw")
|
||||
|
||||
expect(header[:author]).to eq("Sports")
|
||||
expect(header[:author_thumbnail]).to eq("")
|
||||
end
|
||||
|
||||
it "parses the current pageHeaderRenderer shape" do
|
||||
# ex: https://www.youtube.com/channel/UCOpNcN46UbXVtpKMrmU4Abg (Gaming)
|
||||
initdata = JSON.parse(<<-JSON).as_h
|
||||
|
||||
@ -82,8 +82,10 @@ def extract_auto_generated_channel_header(initdata : Hash(String, JSON::Any), uc
|
||||
author = details.dig?("title", "simpleText").try &.as_s
|
||||
author ||= raise InfoException.new("Could not extract the carousel title of channel #{ucid}")
|
||||
author_url = "https://www.youtube.com/channel/#{ucid}"
|
||||
author_thumbnail = details.dig?("avatar", "thumbnails", 0, "url").try &.as_s
|
||||
author_thumbnail ||= raise InfoException.new("Could not extract the carousel thumbnail of channel #{ucid}")
|
||||
|
||||
# A missing avatar is not worth failing the whole page over, and the
|
||||
# `pageHeaderRenderer` branch above falls back to an empty string too.
|
||||
author_thumbnail = details.dig?("avatar", "thumbnails", 0, "url").try &.as_s || ""
|
||||
else
|
||||
raise InfoException.new("Could not extract the header of channel #{ucid}")
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user