fix(parser): link collaborative related videos

This commit is contained in:
Tradi3 2026-07-30 01:04:58 +00:00
parent 9d1291a0b8
commit acbe994989
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,41 @@
require "../../parsers_helper.cr"
Spectator.describe Invidious::Videos::Parser do
it "uses the primary owner channel for collaborative related videos" do
related = JSON.parse(<<-JSON)
{
"videoId": "b2_vBMQmi3M",
"title": {"simpleText": "Collaborative video"},
"shortBylineText": {
"runs": [
{
"text": "D/V and FΛDE",
"navigationEndpoint": {
"showDialogCommand": {
"panelLoadingStrategy": {
"inlineContent": {}
}
}
}
}
]
},
"channelThumbnailSupportedRenderers": {
"channelThumbnailWithLinkRenderer": {
"navigationEndpoint": {
"browseEndpoint": {
"browseId": "UClr4yKwH072yt1nUX29dQGg",
"canonicalBaseUrl": "/@DslashV"
}
}
}
}
}
JSON
result = Invidious::Videos::Parser.parse_related_video(related).not_nil!
expect(result["author"].as_s).to eq("D/V and FΛDE")
expect(result["ucid"].as_s).to eq("UClr4yKwH072yt1nUX29dQGg")
end
end

View File

@ -27,6 +27,13 @@ module Invidious::Videos::Parser
author_verified = has_verified_badge?(related["ownerBadges"]?).to_s
ucid = channel_info.try { |ci| HelperExtractors.get_browse_id(ci) }
if ucid.nil? || ucid.empty?
channel_renderer = related.dig?(
"channelThumbnailSupportedRenderers",
"channelThumbnailWithLinkRenderer"
)
ucid = channel_renderer.try { |renderer| HelperExtractors.get_browse_id(renderer) }
end
short_view_count = related.try do |r|
HelperExtractors.get_short_view_count(r).to_s