From 5ae15be63dee2a2393a1aa2a308ca5378140760a Mon Sep 17 00:00:00 2001 From: LuanRT Date: Thu, 30 Nov 2023 23:34:31 -0300 Subject: [PATCH] fix(VideoAttributeView): Fix `image` and `overflow_menu_on_tap` props --- src/parser/classes/VideoAttributeView.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/parser/classes/VideoAttributeView.ts b/src/parser/classes/VideoAttributeView.ts index 8f8fe8170..0c6893b26 100644 --- a/src/parser/classes/VideoAttributeView.ts +++ b/src/parser/classes/VideoAttributeView.ts @@ -5,11 +5,14 @@ import ContentPreviewImageView from './ContentPreviewImageView.js'; import { Parser } from '../index.js'; import type { RawNode } from '../types/index.js'; +import Thumbnail from './misc/Thumbnail.js'; export default class VideoAttributeView extends YTNode { static type = 'VideoAttributeView'; - image: ContentPreviewImageView | null; + image: ContentPreviewImageView | { + sources: Thumbnail[]; + } | null; image_style: string; title: string; subtitle: string; @@ -18,14 +21,20 @@ export default class VideoAttributeView extends YTNode { }; orientation: string; sizing_rule: string; - overflow_menu_on_tap: { - innertube_command: NavigationEndpoint - }; + overflow_menu_on_tap: NavigationEndpoint; overflow_menu_a11y_label: string; constructor(data: RawNode) { super(); - this.image = Parser.parseItem(data.image, ContentPreviewImageView); + // @NOTE: "image" is not a renderer so not sure why we're parsing it as one. Leaving this hack here for now to avoid breaking things. + if (data.image?.sources) { + this.image = { + sources: data.image.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width) + }; + } else { + this.image = Parser.parseItem(data.image, ContentPreviewImageView); + } + this.image_style = data.imageStyle; this.title = data.title; this.subtitle = data.subtitle; @@ -34,9 +43,7 @@ export default class VideoAttributeView extends YTNode { }; this.orientation = data.orientation; this.sizing_rule = data.sizingRule; - this.overflow_menu_on_tap = { - innertube_command: new NavigationEndpoint(data.overflowMenuOnTap.innertubeCommand) - }; + this.overflow_menu_on_tap = new NavigationEndpoint(data.overflowMenuOnTap); this.overflow_menu_a11y_label = data.overflowMenuA11yLabel; } } \ No newline at end of file