Fix collaboration channel links

This commit is contained in:
liye 2026-07-28 20:15:27 +08:00
parent 9d1291a0b8
commit 29eb23efb6
2 changed files with 58 additions and 1 deletions

View File

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

View File

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