From e86cd8a7779826e5a34753ab84d724ecbaa29192 Mon Sep 17 00:00:00 2001 From: EazyHood Date: Wed, 2 Sep 2026 10:58:38 -0500 Subject: [PATCH] channels: report missing interactive titles cleanly Use optional lookup for title.simpleText and raise the same InfoException used for incomplete carousel headers. Add a focused regression fixture for the missing nested title text. --- spec/invidious/channels/about_spec.cr | 16 ++++++++++++++++ src/invidious/channels/about.cr | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) 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 || ""