diff --git a/spec/invidious/videos/related_video_parser_spec.cr b/spec/invidious/videos/related_video_parser_spec.cr new file mode 100644 index 000000000..936a2f0aa --- /dev/null +++ b/spec/invidious/videos/related_video_parser_spec.cr @@ -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 diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr index 914c59634..0c5a87e64 100644 --- a/src/invidious/videos/parser.cr +++ b/src/invidious/videos/parser.cr @@ -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