From 29eb23efb6f4132db2c49d0793f5c3e88453be4f Mon Sep 17 00:00:00 2001 From: liye Date: Tue, 28 Jul 2026 20:15:27 +0800 Subject: [PATCH] Fix collaboration channel links --- .../videos/related_videos_extract_spec.cr | 51 +++++++++++++++++++ src/invidious/yt_backend/extractors.cr | 8 ++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 spec/invidious/videos/related_videos_extract_spec.cr diff --git a/spec/invidious/videos/related_videos_extract_spec.cr b/spec/invidious/videos/related_videos_extract_spec.cr new file mode 100644 index 000000000..b9a4492b9 --- /dev/null +++ b/spec/invidious/videos/related_videos_extract_spec.cr @@ -0,0 +1,51 @@ +require "../../parsers_helper.cr" + +Spectator.describe "parse_related_video" do + it "extracts the primary channel from collaboration bylines" do + related = JSON.parse(<<-JSON) + { + "videoId": "b2_vBMQmi3M", + "title": { "simpleText": "Alpha Beta Gamma" }, + "shortBylineText": { + "runs": [{ + "text": "Primary and Collaborator", + "navigationEndpoint": { + "showDialogCommand": { + "panelLoadingStrategy": { + "inlineContent": { + "dialogViewModel": { + "customContent": { + "listViewModel": { + "listItems": [{ + "listItemViewModel": { + "rendererContext": { + "commandContext": { + "onTap": { + "innertubeCommand": { + "browseEndpoint": { + "browseId": "UClr4yKwH072yt1nUX29dQGg" + } + } + } + } + } + } + }] + } + } + } + } + } + } + } + }] + } + } + JSON + + parsed = Invidious::Videos::Parser.parse_related_video(related).not_nil! + + expect(parsed["author"]).to eq("Primary and Collaborator") + expect(parsed["ucid"]).to eq("UClr4yKwH072yt1nUX29dQGg") + end +end diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index b2226e74d..c599f7815 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -1141,7 +1141,13 @@ module HelperExtractors # Retrieves the ID required for querying the InnerTube browse endpoint. # Returns an empty string when it's unable to do so def self.get_browse_id(container) - return container.dig?("navigationEndpoint", "browseEndpoint", "browseId").try &.as_s || "" + return container.dig?("navigationEndpoint", "browseEndpoint", "browseId").try &.as_s || + container.dig?( + "navigationEndpoint", "showDialogCommand", "panelLoadingStrategy", + "inlineContent", "dialogViewModel", "customContent", "listViewModel", + "listItems", 0, "listItemViewModel", "rendererContext", "commandContext", + "onTap", "innertubeCommand", "browseEndpoint", "browseId" + ).try &.as_s || "" end end