From 4784dfa563a4dbeaee31811824d5aa37a67f5557 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Mon, 13 Mar 2023 00:58:53 -0300 Subject: [PATCH] feat(parser): add InfoPanelContent and InfoPanelContainer nodes These are usually used to add more context to videos that discuss misinformation. Fixes: #326 --- src/parser/classes/InfoPanelContainer.ts | 27 +++++++++++++++++++ src/parser/classes/InfoPanelContent.ts | 33 ++++++++++++++++++++++++ src/parser/map.ts | 6 +++++ 3 files changed, 66 insertions(+) create mode 100644 src/parser/classes/InfoPanelContainer.ts create mode 100644 src/parser/classes/InfoPanelContent.ts diff --git a/src/parser/classes/InfoPanelContainer.ts b/src/parser/classes/InfoPanelContainer.ts new file mode 100644 index 000000000..f1e0416f4 --- /dev/null +++ b/src/parser/classes/InfoPanelContainer.ts @@ -0,0 +1,27 @@ +import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import InfoPanelContent from './InfoPanelContent.js'; +import Menu from './menus/Menu.js'; +import Text from './misc/Text.js'; + +export default class InfoPanelContainer extends YTNode { + static type = 'InfoPanelContainer'; + + icon_type?: string; + title: Text; + menu: Menu | null; + content: YTNode | null; + background: string; + + constructor(data: RawNode) { + super(); + this.title = new Text(data.title); + this.menu = Parser.parseItem(data.menu, Menu); + this.content = Parser.parseItem(data.content, InfoPanelContent); + this.background = data.background; + + if (data.icon?.iconType) { + this.icon_type = data.icon.iconType; + } + } +} \ No newline at end of file diff --git a/src/parser/classes/InfoPanelContent.ts b/src/parser/classes/InfoPanelContent.ts new file mode 100644 index 000000000..e7d2e83fb --- /dev/null +++ b/src/parser/classes/InfoPanelContent.ts @@ -0,0 +1,33 @@ +import { YTNode } from '../helpers.js'; +import { RawNode } from '../index.js'; +import Text from './misc/Text.js'; +import Thumbnail from './misc/Thumbnail.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; + +export default class InfoPanelContent extends YTNode { + static type = 'InfoPanelContent'; + + title: Text; + inline_link_icon_type?: string; + source: Text; + paragraphs: Text[]; + thumbnail: Thumbnail[]; + source_endpoint: NavigationEndpoint; + truncate_paragraphs: boolean; + background: string; + + constructor(data: RawNode) { + super(); + this.title = new Text(data.title); + this.source = new Text(data.source); + this.paragraphs = data.paragraphs.map((p: RawNode) => new Text(p)); + this.thumbnail = Thumbnail.fromResponse(data.thumbnail); + this.source_endpoint = new NavigationEndpoint(data.sourceEndpoint); + this.truncate_paragraphs = !!data.truncateParagraphs; + this.background = data.background; + + if (data.inlineLinkIcon?.iconType) { + this.inline_link_icon_type = data.inlineLinkIcon.iconType; + } + } +} \ No newline at end of file diff --git a/src/parser/map.ts b/src/parser/map.ts index 20c0d7719..820dab35b 100644 --- a/src/parser/map.ts +++ b/src/parser/map.ts @@ -232,6 +232,10 @@ import { default as HorizontalMovieList } from './classes/HorizontalMovieList.js export { HorizontalMovieList }; import { default as IconLink } from './classes/IconLink.js'; export { IconLink }; +import { default as InfoPanelContainer } from './classes/InfoPanelContainer.js'; +export { InfoPanelContainer }; +import { default as InfoPanelContent } from './classes/InfoPanelContent.js'; +export { InfoPanelContent }; import { default as InteractiveTabbedHeader } from './classes/InteractiveTabbedHeader.js'; export { InteractiveTabbedHeader }; import { default as ItemSection } from './classes/ItemSection.js'; @@ -807,6 +811,8 @@ const map: Record = { HorizontalList, HorizontalMovieList, IconLink, + InfoPanelContainer, + InfoPanelContent, InteractiveTabbedHeader, ItemSection, ItemSectionHeader,