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:
EazyHood 2026-08-02 13:35:12 -05:00
parent c81452f2a4
commit 2c6f804d5a
2 changed files with 27 additions and 2 deletions

View File

@ -109,6 +109,29 @@ Spectator.describe "extract_auto_generated_channel_header" do
end.to raise_error(InfoException) end.to raise_error(InfoException)
end 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 it "parses the current pageHeaderRenderer shape" do
# ex: https://www.youtube.com/channel/UCOpNcN46UbXVtpKMrmU4Abg (Gaming) # ex: https://www.youtube.com/channel/UCOpNcN46UbXVtpKMrmU4Abg (Gaming)
initdata = JSON.parse(<<-JSON).as_h initdata = JSON.parse(<<-JSON).as_h

View File

@ -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 = details.dig?("title", "simpleText").try &.as_s
author ||= raise InfoException.new("Could not extract the carousel title of channel #{ucid}") author ||= raise InfoException.new("Could not extract the carousel title of channel #{ucid}")
author_url = "https://www.youtube.com/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 else
raise InfoException.new("Could not extract the header of channel #{ucid}") raise InfoException.new("Could not extract the header of channel #{ucid}")
end end