diff --git a/spec/invidious/channels/about_spec.cr b/spec/invidious/channels/about_spec.cr index abf21809..55936cbe 100644 --- a/spec/invidious/channels/about_spec.cr +++ b/spec/invidious/channels/about_spec.cr @@ -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 diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr index 2e027062..ce5cd2c5 100644 --- a/src/invidious/channels/about.cr +++ b/src/invidious/channels/about.cr @@ -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