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.
This commit is contained in:
EazyHood 2026-09-02 10:58:38 -05:00
parent d1962c9f21
commit e86cd8a777
2 changed files with 18 additions and 1 deletions

View File

@ -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
{

View File

@ -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 || ""