diff --git a/spec/invidious/channels/about_spec.cr b/spec/invidious/channels/about_spec.cr index abac6e2ad..faf776135 100644 --- a/spec/invidious/channels/about_spec.cr +++ b/spec/invidious/channels/about_spec.cr @@ -200,6 +200,22 @@ Spectator.describe "extract_auto_generated_channel_header" do expect(header[:tags]).to eq(["Gaming"]) end + it "raises an InfoException when the legacy interactive title is missing" do + initdata = JSON.parse(<<-JSON).as_h + { + "header": { + "interactiveTabbedHeaderRenderer": { + "title": {} + } + } + } + JSON + + expect do + extract_auto_generated_channel_header(initdata, "UCMissingTitle") + end.to raise_error(InfoException, /interactive title/) + end + it "falls back to the channel URL when the canonical URL is missing" do initdata = JSON.parse(<<-JSON).as_h { diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.cr index 4677f08d5..97b2fc884 100644 --- a/src/invidious/channels/about.cr +++ b/src/invidious/channels/about.cr @@ -41,7 +41,8 @@ def extract_auto_generated_channel_header(initdata : Hash(String, JSON::Any), uc tags = [] of String if header = initdata.dig?("header", "interactiveTabbedHeaderRenderer") - author = header.dig("title", "simpleText").as_s + author = header.dig?("title", "simpleText").try &.as_s + author ||= raise InfoException.new("Could not extract the interactive title of channel #{ucid}") author_url = initdata.dig?("microformat", "microformatDataRenderer", "urlCanonical").try &.as_s? author_url ||= "https://www.youtube.com/channel/#{ucid}" author_thumbnail = header.dig?("boxArt", "thumbnails", 0, "url").try &.as_s || ""