feat: add PlaylistPanelVideoWrapper parser (#176)

* feat: add `PlaylistPanelVideoWrapper` parser

* fix: `PlaylistPanelVideoWrapper` no counterpart
This commit is contained in:
Patrick Kan
2022-09-10 02:30:21 +08:00
committed by GitHub
parent e00be25bf4
commit bc03c91df9
3 changed files with 22 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import PlaylistPanelVideo from './PlaylistPanelVideo';
import { YTNode } from '../helpers';
import AutomixPreviewVideo from './AutomixPreviewVideo';
import PlaylistPanelVideoWrapper from './PlaylistPanelVideoWrapper';
class PlaylistPanel extends YTNode {
static type = 'PlaylistPanel';
@@ -22,7 +23,7 @@ class PlaylistPanel extends YTNode {
super();
this.title = data.title;
this.title_text = new Text(data.titleText);
this.contents = Parser.parseArray<PlaylistPanelVideo | AutomixPreviewVideo>(data.contents, [ PlaylistPanelVideo, AutomixPreviewVideo ]);
this.contents = Parser.parseArray<PlaylistPanelVideoWrapper | PlaylistPanelVideo | AutomixPreviewVideo>(data.contents);
this.playlist_id = data.playlistId;
this.is_infinite = data.isInfinite;
this.continuation = data.continuations?.[0]?.nextRadioContinuationData?.continuation || data.continuations?.[0]?.nextContinuationData?.continuation;

View File

@@ -0,0 +1,18 @@
import Parser from '..';
import { YTNode } from '../helpers';
import PlaylistPanelVideo from './PlaylistPanelVideo';
class PlaylistPanelVideoWrapper extends YTNode {
static type = 'PlaylistPanelVideoWrapper';
primary: PlaylistPanelVideo | null;
counterpart: Array<PlaylistPanelVideo | null>;
constructor(data: any) {
super();
this.primary = Parser.parseItem<PlaylistPanelVideo>(data.primaryRenderer);
this.counterpart = data.counterpart?.map((item: any) => Parser.parseItem<PlaylistPanelVideo>(item.counterpartRenderer)) || [];
}
}
export default PlaylistPanelVideoWrapper;

View File

@@ -184,6 +184,7 @@ import { default as PlaylistInfoCardContent } from './classes/PlaylistInfoCardCo
import { default as PlaylistMetadata } from './classes/PlaylistMetadata';
import { default as PlaylistPanel } from './classes/PlaylistPanel';
import { default as PlaylistPanelVideo } from './classes/PlaylistPanelVideo';
import { default as PlaylistPanelVideoWrapper } from './classes/PlaylistPanelVideoWrapper';
import { default as PlaylistSidebar } from './classes/PlaylistSidebar';
import { default as PlaylistSidebarPrimaryInfo } from './classes/PlaylistSidebarPrimaryInfo';
import { default as PlaylistSidebarSecondaryInfo } from './classes/PlaylistSidebarSecondaryInfo';
@@ -450,6 +451,7 @@ const map: Record<string, YTNodeConstructor> = {
PlaylistMetadata,
PlaylistPanel,
PlaylistPanelVideo,
PlaylistPanelVideoWrapper,
PlaylistSidebar,
PlaylistSidebarPrimaryInfo,
PlaylistSidebarSecondaryInfo,