fix: link multi-creator related videos

This commit is contained in:
Rudra 2026-08-06 02:52:37 +05:30
parent 0460189a92
commit 313bfa15a4
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,101 @@
require "../../parsers_helper.cr"
Spectator.describe "parse_related_video" do
it "uses a directly linked channel ID" do
related = JSON.parse(<<-JSON)
{
"videoId": "video-id",
"title": {"simpleText": "Video title"},
"shortBylineText": {
"runs": [{
"text": "Channel name",
"navigationEndpoint": {
"browseEndpoint": {"browseId": "UC-direct"}
}
}]
}
}
JSON
video = Invidious::Videos::Parser.parse_related_video(related).not_nil!
expect(video["author"]).to eq("Channel name")
expect(video["ucid"]).to eq("UC-direct")
end
it "links a collaboration byline to the first listed collaborator" do
related = JSON.parse(<<-JSON)
{
"videoId": "collaboration-id",
"title": {"simpleText": "Collaboration"},
"shortBylineText": {
"runs": [{
"text": "First Channel and Second Channel",
"navigationEndpoint": {
"showDialogCommand": {
"panelLoadingStrategy": {
"inlineContent": {
"dialogViewModel": {
"customContent": {
"listViewModel": {
"listItems": [
{
"listItemViewModel": {
"rendererContext": {
"commandContext": {
"onTap": {
"innertubeCommand": {
"browseEndpoint": {"browseId": "UC-first"}
}
}
}
}
}
},
{
"listItemViewModel": {
"rendererContext": {
"commandContext": {
"onTap": {
"innertubeCommand": {
"browseEndpoint": {"browseId": "UC-second"}
}
}
}
}
}
}
]
}
}
}
}
}
}
}
}]
}
}
JSON
video = Invidious::Videos::Parser.parse_related_video(related).not_nil!
expect(video["author"]).to eq("First Channel and Second Channel")
expect(video["ucid"]).to eq("UC-first")
end
it "keeps the channel ID empty when no destination is available" do
related = JSON.parse(<<-JSON)
{
"videoId": "unlinked-id",
"title": {"simpleText": "Unlinked video"},
"shortBylineText": {"runs": [{"text": "Unlinked author"}]}
}
JSON
video = Invidious::Videos::Parser.parse_related_video(related).not_nil!
expect(video["author"]).to eq("Unlinked author")
expect(video["ucid"]).to eq("")
end
end

View File

@ -28,6 +28,18 @@ module Invidious::Videos::Parser
ucid = channel_info.try { |ci| HelperExtractors.get_browse_id(ci) }
# Collaborations use a dialog command instead of linking the combined
# byline directly to a channel. Use the first listed collaborator as the
# destination while preserving YouTube's combined author label.
if ucid.try &.empty?
ucid = channel_info.try &.dig?(
"navigationEndpoint", "showDialogCommand", "panelLoadingStrategy",
"inlineContent", "dialogViewModel", "customContent", "listViewModel",
"listItems", 0, "listItemViewModel", "rendererContext", "commandContext",
"onTap", "innertubeCommand", "browseEndpoint", "browseId"
).try &.as_s
end
short_view_count = related.try do |r|
HelperExtractors.get_short_view_count(r).to_s
end