diff --git a/src/parser/classes/BackstageImage.ts b/src/parser/classes/BackstageImage.ts index dbafe522..fa03bdaa 100644 --- a/src/parser/classes/BackstageImage.ts +++ b/src/parser/classes/BackstageImage.ts @@ -1,14 +1,17 @@ import Thumbnail from './misc/Thumbnail'; +import NavigationEndpoint from './NavigationEndpoint'; import { YTNode } from '../helpers'; class BackstageImage extends YTNode { static type = 'BackstageImage'; image: Thumbnail[]; + endpoint: NavigationEndpoint; constructor(data: any) { super(); this.image = Thumbnail.fromResponse(data.image); + this.endpoint = new NavigationEndpoint(data.command); } } diff --git a/src/parser/classes/BackstagePost.ts b/src/parser/classes/BackstagePost.ts index 2ed7ad10..8fbc5031 100644 --- a/src/parser/classes/BackstagePost.ts +++ b/src/parser/classes/BackstagePost.ts @@ -2,6 +2,8 @@ import Parser from '../index'; import Author from './misc/Author'; import Text from './misc/Text'; import NavigationEndpoint from './NavigationEndpoint'; +import type CommentActionButtons from './comments/CommentActionButtons'; +import type Menu from './menus/Menu'; import { YTNode } from '../helpers'; @@ -12,19 +14,18 @@ class BackstagePost extends YTNode { author: Author; content: Text; published: Text; - poll_status: string; - vote_status: string; - likes: Text; - menu; - actions; + poll_status?: string; + vote_status?: string; + vote_count?: Text; + menu?: Menu | null; + action_buttons; vote_button; surface: string; - endpoint: NavigationEndpoint; + endpoint?: NavigationEndpoint; attachment; constructor(data: any) { super(); - this.id = data.postId; this.author = new Author({ @@ -34,15 +35,40 @@ class BackstagePost extends YTNode { this.content = new Text(data.contentText); this.published = new Text(data.publishedTimeText); - this.poll_status = data.pollStatus; - this.vote_status = data.voteStatus; - this.likes = new Text(data.voteCount); - this.menu = Parser.parse(data.actionMenu) || null; - this.actions = Parser.parse(data.actionButtons); - this.vote_button = Parser.parse(data.voteButton); + + if (data.pollStatus) { + this.poll_status = data.pollStatus; + } + + if (data.voteStatus) { + this.vote_status = data.voteStatus; + } + + if (data.voteCount) { + this.vote_count = new Text(data.voteCount); + } + + if (data.actionMenu) { + this.menu = Parser.parseItem(data.actionMenu); + } + + if (data.actionButtons) { + this.action_buttons = Parser.parseItem(data.actionButtons); + } + + if (data.voteButton) { + this.vote_button = Parser.parseItem(data.voteButton); + } + + if (data.navigationEndpoint) { + this.endpoint = new NavigationEndpoint(data.navigationEndpoint); + } + + if (data.backstageAttachment) { + this.attachment = Parser.parseItem(data.backstageAttachment); + } + this.surface = data.surface; - this.endpoint = new NavigationEndpoint(data.navigationEndpoint); - this.attachment = Parser.parse(data.backstageAttachment) || null; } } diff --git a/src/parser/classes/BackstagePostThread.ts b/src/parser/classes/BackstagePostThread.ts index a43c5240..24d97253 100644 --- a/src/parser/classes/BackstagePostThread.ts +++ b/src/parser/classes/BackstagePostThread.ts @@ -8,7 +8,7 @@ class BackstagePostThread extends YTNode { constructor(data: any) { super(); - this.post = Parser.parse(data.post); + this.post = Parser.parseItem(data.post); } } diff --git a/src/parser/classes/Playlist.ts b/src/parser/classes/Playlist.ts index e65c2957..d9b18efc 100644 --- a/src/parser/classes/Playlist.ts +++ b/src/parser/classes/Playlist.ts @@ -33,12 +33,12 @@ class Playlist extends YTNode { this.thumbnails = Thumbnail.fromResponse(data.thumbnail || { thumbnails: data.thumbnails.map((th: any) => th.thumbnails).flat(1) }); this.video_count = new Text(data.thumbnailText); this.video_count_short = new Text(data.videoCountShortText); - this.first_videos = Parser.parse(data.videos) || []; + this.first_videos = Parser.parseArray(data.videos); this.share_url = data.shareUrl || null; - this.menu = Parser.parse(data.menu); - this.badges = Parser.parse(data.ownerBadges); + this.menu = Parser.parseItem(data.menu); + this.badges = Parser.parseArray(data.ownerBadges); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); - this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays) || []; + this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); } } diff --git a/src/parser/classes/Poll.ts b/src/parser/classes/Poll.ts index 278a7132..8de91522 100644 --- a/src/parser/classes/Poll.ts +++ b/src/parser/classes/Poll.ts @@ -7,25 +7,25 @@ class Poll extends YTNode { static type = 'Poll'; choices: { - text: string; + text: Text; select_endpoint: NavigationEndpoint | null; deselect_endpoint: NavigationEndpoint | null; - vote_ratio_if_selected: number | string | null; - vote_percentage_if_selected: number | string | null; - vote_ratio_if_not_selected: number | string| null; - vote_percentage_if_not_selected: number | string | null; + vote_ratio_if_selected: number | null; + vote_percentage_if_selected: Text; + vote_ratio_if_not_selected: number | null; + vote_percentage_if_not_selected: Text; image: Thumbnail[] | null; }[]; - poll_type; - total_votes; - live_chat_poll_id; + poll_type?: string; + total_votes?: Text; + live_chat_poll_id?: string; constructor(data: any) { super(); this.choices = data.choices.map((choice: any) => ({ - text: new Text(choice.text).toString(), + text: new Text(choice.text), select_endpoint: choice.selectServiceEndpoint ? new NavigationEndpoint(choice.selectServiceEndpoint) : null, deselect_endpoint: choice.deselectServiceEndpoint ? new NavigationEndpoint(choice.deselectServiceEndpoint) : null, vote_ratio_if_selected: choice?.voteRatioIfSelected || null,