Skip to content

Commit

Permalink
feat(parser): add InfoPanelContent and InfoPanelContainer nodes
Browse files Browse the repository at this point in the history
These are usually used to add more context to videos that discuss misinformation.

Fixes: #326
  • Loading branch information
LuanRT committed Mar 13, 2023
1 parent 3e4d41b commit 4784dfa
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/parser/classes/InfoPanelContainer.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
33 changes: 33 additions & 0 deletions src/parser/classes/InfoPanelContent.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 6 additions & 0 deletions src/parser/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -807,6 +811,8 @@ const map: Record<string, YTNodeConstructor> = {
HorizontalList,
HorizontalMovieList,
IconLink,
InfoPanelContainer,
InfoPanelContent,
InteractiveTabbedHeader,
ItemSection,
ItemSectionHeader,
Expand Down

0 comments on commit 4784dfa

Please sign in to comment.