diff --git a/src/parser/classes/ChannelFeaturedContent.ts b/src/parser/classes/ChannelFeaturedContent.ts index bf3313b8..733a4943 100644 --- a/src/parser/classes/ChannelFeaturedContent.ts +++ b/src/parser/classes/ChannelFeaturedContent.ts @@ -1,6 +1,6 @@ -import Parser from '../index.js'; -import Text from './misc/Text.js'; import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import Text from './misc/Text.js'; class ChannelFeaturedContent extends YTNode { static type = 'ChannelFeaturedContent'; @@ -8,10 +8,10 @@ class ChannelFeaturedContent extends YTNode { title: Text; items; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); - this.items = Parser.parse(data.items); + this.items = Parser.parseArray(data.items); } } diff --git a/src/parser/classes/CompactVideo.ts b/src/parser/classes/CompactVideo.ts index 6c7b1099..4f4292b7 100644 --- a/src/parser/classes/CompactVideo.ts +++ b/src/parser/classes/CompactVideo.ts @@ -1,13 +1,12 @@ -import Parser from '../index.js'; -import Text from './misc/Text.js'; -import Author from './misc/Author.js'; import { timeToSeconds } from '../../utils/Utils.js'; +import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import Menu from './menus/Menu.js'; +import MetadataBadge from './MetadataBadge.js'; +import Author from './misc/Author.js'; +import Text from './misc/Text.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; -import type Menu from './menus/Menu.js'; -import MetadataBadge from './MetadataBadge.js'; - -import { YTNode } from '../helpers.js'; class CompactVideo extends YTNode { static type = 'CompactVideo'; @@ -31,7 +30,7 @@ class CompactVideo extends YTNode { endpoint: NavigationEndpoint; menu: Menu | null; - constructor(data: any) { + constructor(data: RawNode) { super(); this.id = data.videoId; this.thumbnails = Thumbnail.fromResponse(data.thumbnail) || null; @@ -50,7 +49,7 @@ class CompactVideo extends YTNode { this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); - this.menu = Parser.parseItem(data.menu); + this.menu = Parser.parseItem(data.menu, Menu); } get best_thumbnail() { diff --git a/src/parser/classes/Element.ts b/src/parser/classes/Element.ts index 1471c6dd..b8dd67e2 100644 --- a/src/parser/classes/Element.ts +++ b/src/parser/classes/Element.ts @@ -13,11 +13,11 @@ class Element extends YTNode { super(); if (Reflect.has(data, 'elementRenderer')) { - return Parser.parseItem(data, Element) as Element; + return Parser.parseItem(data, Element) as Element; } const type = data.newElement.type.componentType; - this.model = Parser.parse(type?.model); + this.model = Parser.parseItem(type?.model); if (data.newElement?.childElements) { this.child_elements = data.newElement?.childElements?.map((el: any) => new ChildElement(el)) || null; diff --git a/src/parser/classes/EmergencyOnebox.ts b/src/parser/classes/EmergencyOnebox.ts index da2aaffb..f08218aa 100644 --- a/src/parser/classes/EmergencyOnebox.ts +++ b/src/parser/classes/EmergencyOnebox.ts @@ -1,6 +1,6 @@ -import Text from './misc/Text.js'; -import Parser from '../index.js'; import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import Text from './misc/Text.js'; class EmergencyOnebox extends YTNode { static type = 'EmergencyOnebox'; @@ -9,11 +9,11 @@ class EmergencyOnebox extends YTNode { first_option; menu; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); - this.first_option = Parser.parse(data.firstOption); - this.menu = Parser.parse(data.menu); + this.first_option = Parser.parseItem(data.firstOption); + this.menu = Parser.parseItem(data.menu); } } diff --git a/src/parser/classes/EndScreenVideo.ts b/src/parser/classes/EndScreenVideo.ts index 4a5bd1ac..988f739e 100644 --- a/src/parser/classes/EndScreenVideo.ts +++ b/src/parser/classes/EndScreenVideo.ts @@ -1,9 +1,9 @@ -import Parser from '../index.js'; -import Text from './misc/Text.js'; +import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; import Author from './misc/Author.js'; +import Text from './misc/Text.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; -import { YTNode } from '../helpers.js'; class EndScreenVideo extends YTNode { static type = 'EndScreenVideo'; @@ -22,12 +22,12 @@ class EndScreenVideo extends YTNode { seconds: number; }; - constructor(data: any) { + constructor(data: RawNode) { super(); this.id = data.videoId; this.title = new Text(data.title); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); - this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays); + this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); this.author = new Author(data.shortBylineText, data.ownerBadges); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.short_view_count = new Text(data.shortViewCountText); diff --git a/src/parser/classes/Grid.ts b/src/parser/classes/Grid.ts index 74a9a944..998f2803 100644 --- a/src/parser/classes/Grid.ts +++ b/src/parser/classes/Grid.ts @@ -1,4 +1,4 @@ -import Parser from '../index.js'; +import Parser, { RawNode } from '../index.js'; import { YTNode } from '../helpers.js'; class Grid extends YTNode { @@ -11,13 +11,13 @@ class Grid extends YTNode { continuation: string | null; header?; - constructor(data: any) { + constructor(data: RawNode) { super(); this.items = Parser.parseArray(data.items); if (data.header) { - this.header = Parser.parse(data.header); + this.header = Parser.parseItem(data.header); } if (data.isCollapsible) { diff --git a/src/parser/classes/GridChannel.ts b/src/parser/classes/GridChannel.ts index 817d52f0..7c083cc7 100644 --- a/src/parser/classes/GridChannel.ts +++ b/src/parser/classes/GridChannel.ts @@ -1,8 +1,8 @@ -import Author from './misc/Author.js'; -import Parser from '../index.js'; -import NavigationEndpoint from './NavigationEndpoint.js'; -import Text from './misc/Text.js'; import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import Author from './misc/Author.js'; +import Text from './misc/Text.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; class GridChannel extends YTNode { static type = 'GridChannel'; @@ -14,7 +14,7 @@ class GridChannel extends YTNode { endpoint: NavigationEndpoint; subscribe_button; - constructor(data: any) { + constructor(data: RawNode) { super(); this.id = data.channelId; @@ -26,7 +26,7 @@ class GridChannel extends YTNode { this.subscribers = new Text(data.subscriberCountText); this.video_count = new Text(data.videoCountText); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); - this.subscribe_button = Parser.parse(data.subscribeButton); + this.subscribe_button = Parser.parseItem(data.subscribeButton); } } diff --git a/src/parser/classes/GridPlaylist.ts b/src/parser/classes/GridPlaylist.ts index 2ba18c8d..497678d1 100644 --- a/src/parser/classes/GridPlaylist.ts +++ b/src/parser/classes/GridPlaylist.ts @@ -1,9 +1,9 @@ -import Text from './misc/Text.js'; -import Parser from '../index.js'; -import Thumbnail from './misc/Thumbnail.js'; -import PlaylistAuthor from './misc/PlaylistAuthor.js'; -import NavigationEndpoint from './NavigationEndpoint.js'; import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import PlaylistAuthor from './misc/PlaylistAuthor.js'; +import Text from './misc/Text.js'; +import Thumbnail from './misc/Thumbnail.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; class GridPlaylist extends YTNode { static type = 'GridPlaylist'; @@ -20,7 +20,7 @@ class GridPlaylist extends YTNode { video_count: Text; video_count_short: Text; - constructor(data: any) { + constructor(data: RawNode) { super(); this.id = data.playlistId; this.title = new Text(data.title); @@ -29,11 +29,11 @@ class GridPlaylist extends YTNode { this.author = new PlaylistAuthor(data.shortBylineText, data.ownerBadges); } - this.badges = Parser.parse(data.ownerBadges); + this.badges = Parser.parseArray(data.ownerBadges); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.view_playlist = new Text(data.viewPlaylistText); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); - this.thumbnail_renderer = Parser.parse(data.thumbnailRenderer); + this.thumbnail_renderer = Parser.parseItem(data.thumbnailRenderer); this.sidebar_thumbnails = [].concat(...data.sidebarThumbnails?.map((thumbnail: any) => Thumbnail.fromResponse(thumbnail)) || []) || null; this.video_count = new Text(data.thumbnailText); this.video_count_short = new Text(data.videoCountShortText); diff --git a/src/parser/classes/GridVideo.ts b/src/parser/classes/GridVideo.ts index 9a653d58..8d87455a 100644 --- a/src/parser/classes/GridVideo.ts +++ b/src/parser/classes/GridVideo.ts @@ -1,4 +1,4 @@ -import Parser from '../index.js'; +import Parser, { RawNode } from '../index.js'; import Text from './misc/Text.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; @@ -24,14 +24,14 @@ class GridVideo extends YTNode { endpoint: NavigationEndpoint; menu: Menu | null; - constructor(data: any) { + constructor(data: RawNode) { super(); const length_alt = data.thumbnailOverlays.find((overlay: any) => overlay.hasOwnProperty('thumbnailOverlayTimeStatusRenderer'))?.thumbnailOverlayTimeStatusRenderer; this.id = data.videoId; this.title = new Text(data.title); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); - this.rich_thumbnail = data.richThumbnail && Parser.parse(data.richThumbnail); + this.rich_thumbnail = data.richThumbnail && Parser.parseItem(data.richThumbnail); this.published = new Text(data.publishedTimeText); this.duration = data.lengthText ? new Text(data.lengthText) : length_alt?.text ? new Text(length_alt.text) : null; this.author = data.shortBylineText && new Author(data.shortBylineText, data.ownerBadges); diff --git a/src/parser/classes/LiveChat.ts b/src/parser/classes/LiveChat.ts index 9ee9210e..a6dcfb52 100644 --- a/src/parser/classes/LiveChat.ts +++ b/src/parser/classes/LiveChat.ts @@ -1,6 +1,6 @@ -import Parser from '../index.js'; -import Text from './misc/Text.js'; import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; +import Text from './misc/Text.js'; class LiveChat extends YTNode { static type = 'LiveChat'; @@ -19,9 +19,9 @@ class LiveChat extends YTNode { is_replay: boolean; - constructor(data: any) { + constructor(data: RawNode) { super(); - this.header = Parser.parse(data.header); + this.header = Parser.parseItem(data.header); this.initial_display_state = data.initialDisplayState; this.continuation = data.continuations[0]?.reloadContinuationData?.continuation; diff --git a/src/parser/classes/MerchandiseShelf.ts b/src/parser/classes/MerchandiseShelf.ts index 95a96227..e53b52ed 100644 --- a/src/parser/classes/MerchandiseShelf.ts +++ b/src/parser/classes/MerchandiseShelf.ts @@ -1,5 +1,5 @@ -import Parser from '../index.js'; import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; class MerchandiseShelf extends YTNode { static type = 'MerchandiseShelf'; @@ -8,11 +8,11 @@ class MerchandiseShelf extends YTNode { menu; items; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = data.title; - this.menu = Parser.parse(data.actionButton); - this.items = Parser.parse(data.items); + this.menu = Parser.parseItem(data.actionButton); + this.items = Parser.parseArray(data.items); } // XXX: alias for consistency diff --git a/src/parser/classes/Movie.ts b/src/parser/classes/Movie.ts index bec15e79..5c9e9adf 100644 --- a/src/parser/classes/Movie.ts +++ b/src/parser/classes/Movie.ts @@ -1,4 +1,4 @@ -import Parser from '../index.js'; +import Parser, { RawNode } from '../index.js'; import Author from './misc/Author.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; @@ -28,7 +28,7 @@ class Movie extends YTNode { show_action_menu: boolean; menu; - constructor(data: any) { + constructor(data: RawNode) { super(); const overlay_time_status = data.thumbnailOverlays .find((overlay: any) => overlay.thumbnailOverlayTimeStatusRenderer) @@ -39,7 +39,7 @@ class Movie extends YTNode { this.description_snippet = data.descriptionSnippet ? new Text(data.descriptionSnippet) : null; this.top_metadata_items = new Text(data.topMetadataItems); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); - this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays); + this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); this.author = new Author(data.longBylineText, data.ownerBadges, data.channelThumbnailSupportedRenderers?.channelThumbnailWithLinkRenderer?.thumbnail); this.duration = { @@ -51,7 +51,7 @@ class Movie extends YTNode { this.badges = Parser.parse(data.badges); this.use_vertical_poster = data.useVerticalPoster; this.show_action_menu = data.showActionMenu; - this.menu = Parser.parse(data.menu); + this.menu = Parser.parseItem(data.menu); } } diff --git a/src/parser/classes/MusicDetailHeader.ts b/src/parser/classes/MusicDetailHeader.ts index b40b009f..82f5d810 100644 --- a/src/parser/classes/MusicDetailHeader.ts +++ b/src/parser/classes/MusicDetailHeader.ts @@ -1,9 +1,9 @@ +import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; import Text from './misc/Text.js'; import TextRun from './misc/TextRun.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; -import Parser from '../index.js'; -import { YTNode } from '../helpers.js'; class MusicDetailHeader extends YTNode { static type = 'MusicDetailHeader'; @@ -24,7 +24,7 @@ class MusicDetailHeader extends YTNode { }; menu; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); this.description = new Text(data.description); @@ -46,7 +46,7 @@ class MusicDetailHeader extends YTNode { }; } - this.menu = Parser.parse(data.menu); + this.menu = Parser.parseItem(data.menu); } } diff --git a/src/parser/classes/MusicEditablePlaylistDetailHeader.ts b/src/parser/classes/MusicEditablePlaylistDetailHeader.ts index bf411878..febec930 100644 --- a/src/parser/classes/MusicEditablePlaylistDetailHeader.ts +++ b/src/parser/classes/MusicEditablePlaylistDetailHeader.ts @@ -1,4 +1,4 @@ -import Parser from '../index.js'; +import Parser, { RawNode } from '../index.js'; import { YTNode } from '../helpers.js'; class MusicEditablePlaylistDetailHeader extends YTNode { @@ -6,9 +6,9 @@ class MusicEditablePlaylistDetailHeader extends YTNode { header; - constructor(data: any) { + constructor(data: RawNode) { super(); - this.header = Parser.parse(data.header); + this.header = Parser.parseItem(data.header); // TODO: Should we also parse data.editHeader.musicPlaylistEditHeaderRenderer? // It doesn't seem practical to do so... diff --git a/src/parser/classes/MusicHeader.ts b/src/parser/classes/MusicHeader.ts index bfbaf7bb..0e9beda7 100644 --- a/src/parser/classes/MusicHeader.ts +++ b/src/parser/classes/MusicHeader.ts @@ -1,4 +1,4 @@ -import Parser from '../index.js'; +import Parser, { RawNode } from '../index.js'; import { YTNode } from '../helpers.js'; import Text from './misc/Text.js'; @@ -8,11 +8,11 @@ class MusicHeader extends YTNode { header?; title?: Text; - constructor(data: any) { + constructor(data: RawNode) { super(); if (data.header) { - this.header = Parser.parse(data.header); + this.header = Parser.parseItem(data.header); } if (data.title) { diff --git a/src/parser/classes/Notification.ts b/src/parser/classes/Notification.ts index 965a548b..05f0fb97 100644 --- a/src/parser/classes/Notification.ts +++ b/src/parser/classes/Notification.ts @@ -1,8 +1,8 @@ -import Parser from '../index.js'; +import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; import Text from './misc/Text.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; -import { YTNode } from '../helpers.js'; class Notification extends YTNode { static type = 'Notification'; @@ -11,13 +11,13 @@ class Notification extends YTNode { video_thumbnails: Thumbnail[]; short_message: Text; sent_time: Text; - notification_id: any; + notification_id: string; endpoint: NavigationEndpoint; record_click_endpoint: NavigationEndpoint; menu; read: boolean; - constructor(data: any) { + constructor(data: RawNode) { super(); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.video_thumbnails = Thumbnail.fromResponse(data.videoThumbnail); @@ -26,7 +26,7 @@ class Notification extends YTNode { this.notification_id = data.notificationId; this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.record_click_endpoint = new NavigationEndpoint(data.recordClickEndpoint); - this.menu = Parser.parse(data.contextualMenu); + this.menu = Parser.parseItem(data.contextualMenu); this.read = data.read; } } diff --git a/src/parser/classes/PlayerAnnotationsExpanded.ts b/src/parser/classes/PlayerAnnotationsExpanded.ts index 8b8130c7..37b63774 100644 --- a/src/parser/classes/PlayerAnnotationsExpanded.ts +++ b/src/parser/classes/PlayerAnnotationsExpanded.ts @@ -1,34 +1,36 @@ -import Parser from '../index.js'; +import { YTNode } from '../helpers.js'; +import Parser, { RawNode } from '../index.js'; import Thumbnail from './misc/Thumbnail.js'; import NavigationEndpoint from './NavigationEndpoint.js'; -import { YTNode, SuperParsedResult } from '../helpers.js'; class PlayerAnnotationsExpanded extends YTNode { static type = 'PlayerAnnotationsExpanded'; - featured_channel: { + featured_channel?: { start_time_ms: number; end_time_ms: number; watermark: Thumbnail[]; channel_name: string; endpoint: NavigationEndpoint; - subscribe_button: SuperParsedResult; + subscribe_button: YTNode | null; }; allow_swipe_dismiss: boolean; annotation_id: string; - constructor(data: any) { + constructor(data: RawNode) { super(); - this.featured_channel = { - start_time_ms: data.featuredChannel.startTimeMs, - end_time_ms: data.featuredChannel.endTimeMs, - watermark: Thumbnail.fromResponse(data.featuredChannel.watermark), - channel_name: data.featuredChannel.channelName, - endpoint: new NavigationEndpoint(data.featuredChannel.navigationEndpoint), - subscribe_button: Parser.parse(data.featuredChannel.subscribeButton) - }; + if (Reflect.has(data, 'featuredChannel')) { + this.featured_channel = { + start_time_ms: data.featuredChannel.startTimeMs, + end_time_ms: data.featuredChannel.endTimeMs, + watermark: Thumbnail.fromResponse(data.featuredChannel.watermark), + channel_name: data.featuredChannel.channelName, + endpoint: new NavigationEndpoint(data.featuredChannel.navigationEndpoint), + subscribe_button: Parser.parseItem(data.featuredChannel.subscribeButton) + }; + } this.allow_swipe_dismiss = data.allowSwipeDismiss; this.annotation_id = data.annotationId; diff --git a/src/parser/classes/PlayerOverlay.ts b/src/parser/classes/PlayerOverlay.ts index 91e2c658..bfe73123 100644 --- a/src/parser/classes/PlayerOverlay.ts +++ b/src/parser/classes/PlayerOverlay.ts @@ -1,34 +1,34 @@ -import Parser from '../index.js'; -import Menu from './menus/Menu.js'; +import Parser, { RawNode } from '../index.js'; import Button from './Button.js'; -import WatchNextEndScreen from './WatchNextEndScreen.js'; +import DecoratedPlayerBar from './DecoratedPlayerBar.js'; +import Menu from './menus/Menu.js'; import PlayerOverlayAutoplay from './PlayerOverlayAutoplay.js'; -import type DecoratedPlayerBar from './DecoratedPlayerBar.js'; +import WatchNextEndScreen from './WatchNextEndScreen.js'; import { YTNode } from '../helpers.js'; class PlayerOverlay extends YTNode { static type = 'PlayerOverlay'; - end_screen; - autoplay; - share_button; - add_to_menu; + end_screen: WatchNextEndScreen | null; + autoplay: PlayerOverlayAutoplay | null; + share_button: Button | null; + add_to_menu: Menu | null; fullscreen_engagement; actions; browser_media_session; - decorated_player_bar; + decorated_player_bar: DecoratedPlayerBar | null; - constructor(data: any) { + constructor(data: RawNode) { super(); - this.end_screen = Parser.parseItem(data.endScreen, WatchNextEndScreen); - this.autoplay = Parser.parseItem(data.autoplay, PlayerOverlayAutoplay); - this.share_button = Parser.parseItem