diff --git a/examples/comments/README.md b/examples/comments/README.md index ab3e4163..398b6a7f 100644 --- a/examples/comments/README.md +++ b/examples/comments/README.md @@ -5,7 +5,7 @@ YouTube.js has full support for comments, including comment actions such as liki Get a [`Comments`](../../lib/parser/youtube/Comments.js) instance: ```js -const comments = await session.getComments(VIDEO_ID); +const comments = await yt.getComments(VIDEO_ID); ``` ## API diff --git a/examples/livechat/README.md b/examples/livechat/README.md index 3288ba32..fd94350b 100644 --- a/examples/livechat/README.md +++ b/examples/livechat/README.md @@ -7,7 +7,7 @@ The library's Live Chat parser and poller were heavily based on YouTube's origin Before fetching a Live Chat, you have to retrieve the target livestream's info: ```js -const info = await session.getInfo('video_id'); +const info = await yt.getInfo('video_id'); ``` Then you may request a Live Chat instance: diff --git a/examples/livechat/index.ts b/examples/livechat/index.ts index d5c3cbbb..47b08d49 100644 --- a/examples/livechat/index.ts +++ b/examples/livechat/index.ts @@ -22,8 +22,8 @@ import LiveChatPaidMessage from 'youtubei.js/dist/src/parser/classes/livechat/it /** * Initial info is what you see when you first open a Live Chat — this is; inital actions (pinned messages, top donations..), account's info and so on. */ - - console.info(`Hey ${initial_data.viewer_name}, welcome to ${info.basic_info.channel.name}\'s Live Chat!`); + + console.info(`Hey ${initial_data.viewer_name || 'N/A'}, welcome to Live Chat!`); }); livechat.on('chat-update', (action: ChatAction) => { @@ -49,7 +49,7 @@ import LiveChatPaidMessage from 'youtubei.js/dist/src/parser/classes/livechat/it switch (item.type) { case 'LiveChatTextMessage': console.info( - `${hours} - ${item.as(LiveChatTextMessage).author.name.toString()}:\n` + + `${hours} - ${item.as(LiveChatTextMessage).author?.name.toString()}:\n` + `${item.as(LiveChatTextMessage).message.toString()}\n` ); break; diff --git a/src/parser/classes/BackstageImage.js b/src/parser/classes/BackstageImage.ts similarity index 73% rename from src/parser/classes/BackstageImage.js rename to src/parser/classes/BackstageImage.ts index 208defad..dbafe522 100644 --- a/src/parser/classes/BackstageImage.js +++ b/src/parser/classes/BackstageImage.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class BackstageImage extends YTNode { static type = 'BackstageImage'; - constructor(data) { + image: Thumbnail[]; + + constructor(data: any) { super(); this.image = Thumbnail.fromResponse(data.image); } diff --git a/src/parser/classes/BackstagePost.js b/src/parser/classes/BackstagePost.ts similarity index 74% rename from src/parser/classes/BackstagePost.js rename to src/parser/classes/BackstagePost.ts index ae6e20b9..2ed7ad10 100644 --- a/src/parser/classes/BackstagePost.js +++ b/src/parser/classes/BackstagePost.ts @@ -8,8 +8,23 @@ import { YTNode } from '../helpers'; class BackstagePost extends YTNode { static type = 'BackstagePost'; - constructor(data) { + id: string; + author: Author; + content: Text; + published: Text; + poll_status: string; + vote_status: string; + likes: Text; + menu; + actions; + vote_button; + surface: string; + endpoint: NavigationEndpoint; + attachment; + + constructor(data: any) { super(); + this.id = data.postId; this.author = new Author({ @@ -17,7 +32,7 @@ class BackstagePost extends YTNode { navigationEndpoint: data.authorEndpoint }, null, data.authorThumbnail); - this.content = new Text(data.contentText, ''); + this.content = new Text(data.contentText); this.published = new Text(data.publishedTimeText); this.poll_status = data.pollStatus; this.vote_status = data.voteStatus; diff --git a/src/parser/classes/BackstagePostThread.js b/src/parser/classes/BackstagePostThread.ts similarity index 75% rename from src/parser/classes/BackstagePostThread.js rename to src/parser/classes/BackstagePostThread.ts index 2406daa9..a43c5240 100644 --- a/src/parser/classes/BackstagePostThread.js +++ b/src/parser/classes/BackstagePostThread.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class BackstagePostThread extends YTNode { static type = 'BackstagePostThread'; - constructor(data) { + post; + + constructor(data: any) { super(); this.post = Parser.parse(data.post); } diff --git a/src/parser/classes/Button.js b/src/parser/classes/Button.ts similarity index 75% rename from src/parser/classes/Button.js rename to src/parser/classes/Button.ts index 07f8b0ad..bbae93a3 100644 --- a/src/parser/classes/Button.js +++ b/src/parser/classes/Button.ts @@ -5,7 +5,16 @@ import { YTNode } from '../helpers'; class Button extends YTNode { static type = 'Button'; - constructor(data) { + + text: string; + + label; + tooltip; + icon_type; + + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.text = new Text(data.text).toString(); @@ -18,7 +27,7 @@ class Button extends YTNode { } if (data.icon?.iconType) { - this.iconType = data.icon?.iconType; + this.icon_type = data.icon?.iconType; } this.endpoint = new NavigationEndpoint(data.navigationEndpoint || data.serviceEndpoint || data.command); diff --git a/src/parser/classes/CallToActionButton.js b/src/parser/classes/CallToActionButton.ts similarity index 70% rename from src/parser/classes/CallToActionButton.js rename to src/parser/classes/CallToActionButton.ts index d4bbf6cb..32702c1d 100644 --- a/src/parser/classes/CallToActionButton.js +++ b/src/parser/classes/CallToActionButton.ts @@ -4,7 +4,11 @@ import { YTNode } from '../helpers'; class CallToActionButton extends YTNode { static type = 'CallToActionButton'; - constructor(data) { + label: Text; + icon_type: string; + style: string; + + constructor(data: any) { super(); this.label = new Text(data.label); this.icon_type = data.icon.iconType; diff --git a/src/parser/classes/Card.js b/src/parser/classes/Card.ts similarity index 61% rename from src/parser/classes/Card.js rename to src/parser/classes/Card.ts index feea6bf7..444f78ec 100644 --- a/src/parser/classes/Card.js +++ b/src/parser/classes/Card.ts @@ -4,14 +4,26 @@ import { YTNode } from '../helpers'; class Card extends YTNode { static type = 'Card'; - constructor(data) { + teaser; + content; + card_id: string; + feature: string; + + cue_ranges: { + start_card_active_ms: string; + end_card_active_ms: string; + teaser_duration_ms: string; + icon_after_teaser_ms: string; + }[]; + + constructor(data: any) { super(); this.teaser = Parser.parse(data.teaser); this.content = Parser.parse(data.content); this.card_id = data.cardId; this.feature = data.feature; - this.cue_ranges = data.cueRanges.map((cr) => ({ + this.cue_ranges = data.cueRanges.map((cr: any) => ({ start_card_active_ms: cr.startCardActiveMs, end_card_active_ms: cr.endCardActiveMs, teaser_duration_ms: cr.teaserDurationMs, diff --git a/src/parser/classes/CardCollection.js b/src/parser/classes/CardCollection.ts similarity index 74% rename from src/parser/classes/CardCollection.js rename to src/parser/classes/CardCollection.ts index 25752acf..78f5b380 100644 --- a/src/parser/classes/CardCollection.js +++ b/src/parser/classes/CardCollection.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class CardCollection extends YTNode { static type = 'CardCollection'; - constructor(data) { + cards; + header: Text; + allow_teaser_dismiss: boolean; + + constructor(data: any) { super(); this.cards = Parser.parse(data.cards); this.header = new Text(data.headerText); diff --git a/src/parser/classes/Channel.js b/src/parser/classes/Channel.ts similarity index 78% rename from src/parser/classes/Channel.js rename to src/parser/classes/Channel.ts index 745eb203..0754bbe5 100644 --- a/src/parser/classes/Channel.js +++ b/src/parser/classes/Channel.ts @@ -6,7 +6,14 @@ import { YTNode } from '../helpers'; class Channel extends YTNode { static type = 'Channel'; - constructor(data) { + id: string; + author: Author; + subscribers: Text; + videos: Text; + endpoint: NavigationEndpoint; + description_snippet: Text; + + constructor(data: any) { super(); this.id = data.channelId; diff --git a/src/parser/classes/ChannelAboutFullMetadata.js b/src/parser/classes/ChannelAboutFullMetadata.ts similarity index 74% rename from src/parser/classes/ChannelAboutFullMetadata.js rename to src/parser/classes/ChannelAboutFullMetadata.ts index 0238f870..80e74e82 100644 --- a/src/parser/classes/ChannelAboutFullMetadata.js +++ b/src/parser/classes/ChannelAboutFullMetadata.ts @@ -7,7 +7,19 @@ import { YTNode } from '../helpers'; class ChannelAboutFullMetadata extends YTNode { static type = 'ChannelAboutFullMetadata'; - constructor(data) { + id: string; + name: Text; + avatar: Thumbnail[]; + canonical_channel_url: string; + views: Text; + joined: Text; + description: Text; + email_reveal: NavigationEndpoint; + can_reveal_email: boolean; + country: Text; + buttons; + + constructor(data: any) { super(); this.id = data.channelId; this.name = new Text(data.title); diff --git a/src/parser/classes/ChannelFeaturedContent.js b/src/parser/classes/ChannelFeaturedContent.ts similarity index 76% rename from src/parser/classes/ChannelFeaturedContent.js rename to src/parser/classes/ChannelFeaturedContent.ts index 7b6a34e0..607cd5ad 100644 --- a/src/parser/classes/ChannelFeaturedContent.js +++ b/src/parser/classes/ChannelFeaturedContent.ts @@ -5,7 +5,10 @@ import { YTNode } from '../helpers'; class ChannelFeaturedContent extends YTNode { static type = 'ChannelFeaturedContent'; - constructor(data) { + title: Text; + items; + + constructor(data: any) { super(); this.title = new Text(data.title); this.items = Parser.parse(data.items); diff --git a/src/parser/classes/ChannelHeaderLinks.js b/src/parser/classes/ChannelHeaderLinks.ts similarity index 53% rename from src/parser/classes/ChannelHeaderLinks.js rename to src/parser/classes/ChannelHeaderLinks.ts index 2ac4b9d0..93d40a7e 100644 --- a/src/parser/classes/ChannelHeaderLinks.js +++ b/src/parser/classes/ChannelHeaderLinks.ts @@ -4,7 +4,11 @@ import Thumbnail from './misc/Thumbnail'; import { YTNode } from '../helpers'; class HeaderLink { - constructor(data) { + endpoint: NavigationEndpoint; + icon: Thumbnail[]; + title: Text; + + constructor(data: any) { this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.icon = Thumbnail.fromResponse(data.icon); this.title = new Text(data.title); @@ -14,10 +18,13 @@ class HeaderLink { class ChannelHeaderLinks extends YTNode { static type = 'ChannelHeaderLinks'; - constructor(data) { + primary: HeaderLink[]; + secondary: HeaderLink[]; + + constructor(data: any) { super(); - this.primary = data.primaryLinks?.map((link) => new HeaderLink(link)) || []; - this.secondary = data.secondaryLinks?.map((link) => new HeaderLink(link)) || []; + this.primary = data.primaryLinks?.map((link: any) => new HeaderLink(link)) || []; + this.secondary = data.secondaryLinks?.map((link: any) => new HeaderLink(link)) || []; } } diff --git a/src/parser/classes/ChannelMetadata.js b/src/parser/classes/ChannelMetadata.ts similarity index 66% rename from src/parser/classes/ChannelMetadata.js rename to src/parser/classes/ChannelMetadata.ts index 9fec9b23..b44d12a8 100644 --- a/src/parser/classes/ChannelMetadata.js +++ b/src/parser/classes/ChannelMetadata.ts @@ -4,7 +4,21 @@ import { YTNode } from '../helpers'; class ChannelMetadata extends YTNode { static type = 'ChannelMetadata'; - constructor(data) { + title: string; + description: string; + url: string; + rss_urls: any; // Array? + vanity_channel_url: string; + external_id: string; + is_family_safe: boolean; + keywords: string[]; + avatar: Thumbnail[]; + available_countries: string[]; + android_deep_link: string; + android_appindexing_link: string; + ios_appindexing_link: string; + + constructor(data: any) { super(); this.title = data.title; this.description = data.description; diff --git a/src/parser/classes/ChannelMobileHeader.js b/src/parser/classes/ChannelMobileHeader.ts similarity index 73% rename from src/parser/classes/ChannelMobileHeader.js rename to src/parser/classes/ChannelMobileHeader.ts index 45afc384..1848dc92 100644 --- a/src/parser/classes/ChannelMobileHeader.js +++ b/src/parser/classes/ChannelMobileHeader.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class ChannelMobileHeader extends YTNode { static type = 'ChannelMobileHeader'; - constructor(data) { + title: Text; + + constructor(data: any) { super(); this.title = new Text(data.title); } diff --git a/src/parser/classes/ChannelThumbnailWithLink.js b/src/parser/classes/ChannelThumbnailWithLink.ts similarity index 75% rename from src/parser/classes/ChannelThumbnailWithLink.js rename to src/parser/classes/ChannelThumbnailWithLink.ts index 022c4111..ba897edc 100644 --- a/src/parser/classes/ChannelThumbnailWithLink.js +++ b/src/parser/classes/ChannelThumbnailWithLink.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class ChannelThumbnailWithLink extends YTNode { static type = 'ChannelThumbnailWithLink'; - constructor(data) { + thumbnails: Thumbnail[]; + endpoint: NavigationEndpoint; + label: string; + + constructor(data: any) { super(); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); diff --git a/src/parser/classes/ChannelVideoPlayer.js b/src/parser/classes/ChannelVideoPlayer.js deleted file mode 100644 index 65997397..00000000 --- a/src/parser/classes/ChannelVideoPlayer.js +++ /dev/null @@ -1,17 +0,0 @@ -import Text from './misc/Text'; -import { YTNode } from '../helpers'; - -class ChannelVideoPlayer extends YTNode { - static type = 'ChannelVideoPlayer'; - - constructor(data) { - super(); - this.id = data.videoId; - this.title = new Text(data.title, ''); - this.description = new Text(data.description, ''); - this.views = new Text(data.viewCountText, ''); - this.published_at = new Text(data.publishedTimeText, ''); - } -} - -export default ChannelVideoPlayer; \ No newline at end of file diff --git a/src/parser/classes/ChannelVideoPlayer.ts b/src/parser/classes/ChannelVideoPlayer.ts new file mode 100644 index 00000000..f98b7a97 --- /dev/null +++ b/src/parser/classes/ChannelVideoPlayer.ts @@ -0,0 +1,23 @@ +import Text from './misc/Text'; +import { YTNode } from '../helpers'; + +class ChannelVideoPlayer extends YTNode { + static type = 'ChannelVideoPlayer'; + + id: string; + title: Text; + description: Text; + views: Text; + published: Text; + + constructor(data: any) { + super(); + this.id = data.videoId; + this.title = new Text(data.title); + this.description = new Text(data.description); + this.views = new Text(data.viewCountText); + this.published = new Text(data.publishedTimeText); + } +} + +export default ChannelVideoPlayer; \ No newline at end of file diff --git a/src/parser/classes/ChildVideo.js b/src/parser/classes/ChildVideo.ts similarity index 75% rename from src/parser/classes/ChildVideo.js rename to src/parser/classes/ChildVideo.ts index cd12e7b9..8d6ea4ed 100644 --- a/src/parser/classes/ChildVideo.js +++ b/src/parser/classes/ChildVideo.ts @@ -7,7 +7,17 @@ import { YTNode } from '../helpers'; class ChildVideo extends YTNode { static type = 'ChildVideo'; - constructor(data) { + id: string; + title: Text; + + duration: { + text: string; + seconds: number; + }; + + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.id = data.videoId; this.title = new Text(data.title); @@ -21,4 +31,4 @@ class ChildVideo extends YTNode { } } -export default ChildVideo; +export default ChildVideo; \ No newline at end of file diff --git a/src/parser/classes/ChipCloud.js b/src/parser/classes/ChipCloud.ts similarity index 69% rename from src/parser/classes/ChipCloud.js rename to src/parser/classes/ChipCloud.ts index 80cb0aee..11e53ccf 100644 --- a/src/parser/classes/ChipCloud.js +++ b/src/parser/classes/ChipCloud.ts @@ -5,10 +5,16 @@ import ChipCloudChip from './ChipCloudChip'; class ChipCloud extends YTNode { static type = 'ChipCloud'; - constructor(data) { + + chips; + next_button; + previous_button; + horizontal_scrollable; + + constructor(data: any) { super(); // TODO: check this assumption that chipcloudchip is always returned - this.chips = Parser.parse(data.chips, true, ChipCloudChip); + this.chips = Parser.parseArray(data.chips, ChipCloudChip); this.next_button = Parser.parse(data.nextButton); this.previous_button = Parser.parse(data.previousButton); this.horizontal_scrollable = data.horizontalScrollable; diff --git a/src/parser/classes/ChipCloudChip.js b/src/parser/classes/ChipCloudChip.ts similarity index 76% rename from src/parser/classes/ChipCloudChip.js rename to src/parser/classes/ChipCloudChip.ts index 23f5afe4..00eba4d5 100644 --- a/src/parser/classes/ChipCloudChip.js +++ b/src/parser/classes/ChipCloudChip.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class ChipCloudChip extends YTNode { static type = 'ChipCloudChip'; - constructor(data) { + is_selected: boolean; + endpoint: NavigationEndpoint | undefined; + text: string; + + constructor(data: any) { super(); // TODO: is this isSelected or just selected this.is_selected = data.isSelected; diff --git a/src/parser/classes/CollageHeroImage.js b/src/parser/classes/CollageHeroImage.ts similarity index 75% rename from src/parser/classes/CollageHeroImage.js rename to src/parser/classes/CollageHeroImage.ts index ffb53fec..3aab28fe 100644 --- a/src/parser/classes/CollageHeroImage.js +++ b/src/parser/classes/CollageHeroImage.ts @@ -5,7 +5,12 @@ import { YTNode } from '../helpers'; class CollageHeroImage extends YTNode { static type = 'CollageHeroImage'; - constructor(data) { + left: Thumbnail[]; + top_right: Thumbnail[]; + bottom_right: Thumbnail[]; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.left = Thumbnail.fromResponse(data.leftThumbnail); this.top_right = Thumbnail.fromResponse(data.topRightThumbnail); diff --git a/src/parser/classes/CompactLink.js b/src/parser/classes/CompactLink.ts similarity index 74% rename from src/parser/classes/CompactLink.js rename to src/parser/classes/CompactLink.ts index 5f570634..82a0b98c 100644 --- a/src/parser/classes/CompactLink.js +++ b/src/parser/classes/CompactLink.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class CompactLink extends YTNode { static type = 'CompactLink'; - constructor(data) { + title: string; + endpoint: NavigationEndpoint; + style: string; + + constructor(data: any) { super(); this.title = new Text(data.title).toString(); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); diff --git a/src/parser/classes/CompactMix.js b/src/parser/classes/CompactMix.ts similarity index 70% rename from src/parser/classes/CompactMix.js rename to src/parser/classes/CompactMix.ts index d41d15b9..f41b0220 100644 --- a/src/parser/classes/CompactMix.js +++ b/src/parser/classes/CompactMix.ts @@ -3,7 +3,7 @@ import Playlist from './Playlist'; class CompactMix extends Playlist { static type = 'CompactMix'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/CompactPlaylist.js b/src/parser/classes/CompactPlaylist.ts similarity index 70% rename from src/parser/classes/CompactPlaylist.js rename to src/parser/classes/CompactPlaylist.ts index 3fbcfaf9..bd11eba0 100644 --- a/src/parser/classes/CompactPlaylist.js +++ b/src/parser/classes/CompactPlaylist.ts @@ -3,7 +3,7 @@ import Playlist from './Playlist'; class CompactPlaylist extends Playlist { static type = 'CompactPlaylist'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/CompactVideo.js b/src/parser/classes/CompactVideo.ts similarity index 78% rename from src/parser/classes/CompactVideo.js rename to src/parser/classes/CompactVideo.ts index 42c64da0..f1a17080 100644 --- a/src/parser/classes/CompactVideo.js +++ b/src/parser/classes/CompactVideo.ts @@ -9,7 +9,25 @@ import { YTNode } from '../helpers'; class CompactVideo extends YTNode { static type = 'CompactVideo'; - constructor(data) { + id: string; + thumbnails: Thumbnail[]; + rich_thumbnail; + title: Text; + author: Author; + view_count: Text; + short_view_count: Text; + published: Text; + + duration: { + text: string; + seconds: number; + }; + + thumbnail_overlays; + endpoint: NavigationEndpoint; + menu; + + constructor(data: any) { super(); this.id = data.videoId; this.thumbnails = Thumbnail.fromResponse(data.thumbnail) || null; diff --git a/src/parser/classes/ContinuationItem.js b/src/parser/classes/ContinuationItem.ts similarity index 76% rename from src/parser/classes/ContinuationItem.js rename to src/parser/classes/ContinuationItem.ts index 46dd543b..cbf12615 100644 --- a/src/parser/classes/ContinuationItem.js +++ b/src/parser/classes/ContinuationItem.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class ContinuationItem extends YTNode { static type = 'ContinuationItem'; - constructor(data) { + trigger: string; + button?; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.trigger = data.trigger; diff --git a/src/parser/classes/DidYouMean.js b/src/parser/classes/DidYouMean.ts similarity index 75% rename from src/parser/classes/DidYouMean.js rename to src/parser/classes/DidYouMean.ts index 218fa704..06eb137e 100644 --- a/src/parser/classes/DidYouMean.js +++ b/src/parser/classes/DidYouMean.ts @@ -5,7 +5,10 @@ import { YTNode } from '../helpers'; class DidYouMean extends YTNode { static type = 'DidYouMean'; - constructor(data) { + corrected_query: Text; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.corrected_query = new Text(data.correctedQuery); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); diff --git a/src/parser/classes/DownloadButton.js b/src/parser/classes/DownloadButton.ts similarity index 67% rename from src/parser/classes/DownloadButton.js rename to src/parser/classes/DownloadButton.ts index a03ed14b..4c936f4d 100644 --- a/src/parser/classes/DownloadButton.js +++ b/src/parser/classes/DownloadButton.ts @@ -4,7 +4,12 @@ import { YTNode } from '../helpers'; class DownloadButton extends YTNode { static type = 'DownloadButton'; - constructor(data) { + style: string; + size: string; // TODO: check this + endpoint: NavigationEndpoint; + target_id: string; + + constructor(data: any) { super(); this.style = data.style; this.size = data.size; diff --git a/src/parser/classes/Element.js b/src/parser/classes/Element.ts similarity index 83% rename from src/parser/classes/Element.js rename to src/parser/classes/Element.ts index e0626cb5..66efada1 100644 --- a/src/parser/classes/Element.js +++ b/src/parser/classes/Element.ts @@ -3,9 +3,10 @@ import { YTNode } from '../helpers'; class Element extends YTNode { static type = 'Element'; + model; - constructor(data) { + constructor(data: any) { super(); const type = data.newElement.type.componentType; this.model = Parser.parse(type.model); diff --git a/src/parser/classes/EmergencyOnebox.js b/src/parser/classes/EmergencyOnebox.ts similarity index 77% rename from src/parser/classes/EmergencyOnebox.js rename to src/parser/classes/EmergencyOnebox.ts index 35696570..c132c6e8 100644 --- a/src/parser/classes/EmergencyOnebox.js +++ b/src/parser/classes/EmergencyOnebox.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class EmergencyOnebox extends YTNode { static type = 'EmergencyOnebox'; - constructor(data) { + title: Text; + first_option; + menu; + + constructor(data: any) { super(); this.title = new Text(data.title); this.first_option = Parser.parse(data.firstOption); diff --git a/src/parser/classes/EndScreenPlaylist.js b/src/parser/classes/EndScreenPlaylist.ts similarity index 75% rename from src/parser/classes/EndScreenPlaylist.js rename to src/parser/classes/EndScreenPlaylist.ts index b2a8875f..ae58e36c 100644 --- a/src/parser/classes/EndScreenPlaylist.js +++ b/src/parser/classes/EndScreenPlaylist.ts @@ -5,7 +5,15 @@ import { YTNode } from '../helpers'; class EndScreenPlaylist extends YTNode { static type = 'EndScreenPlaylist'; - constructor(data) { + + id: string; + title: Text; + author: Text; + endpoint: NavigationEndpoint; + thumbnails: Thumbnail[]; + video_count: Text; + + constructor(data: any) { super(); this.id = data.playlistId; this.title = new Text(data.title); diff --git a/src/parser/classes/EndScreenVideo.js b/src/parser/classes/EndScreenVideo.ts similarity index 70% rename from src/parser/classes/EndScreenVideo.js rename to src/parser/classes/EndScreenVideo.ts index 2a90dda7..109e4777 100644 --- a/src/parser/classes/EndScreenVideo.js +++ b/src/parser/classes/EndScreenVideo.ts @@ -8,7 +8,21 @@ import { YTNode } from '../helpers'; class EndScreenVideo extends YTNode { static type = 'EndScreenVideo'; - constructor(data) { + id: string; + title: Text; + thumbnails: Thumbnail[]; + thumbnail_overlays; + author: Author; + endpoint: NavigationEndpoint; + short_view_count: Text; + badges; + + duration: { + text: string; + seconds: number; + }; + + constructor(data: any) { super(); this.id = data.videoId; this.title = new Text(data.title); @@ -16,7 +30,7 @@ class EndScreenVideo extends YTNode { this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays); this.author = new Author(data.shortBylineText, data.ownerBadges); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); - this.short_view_count_text = new Text(data.shortViewCountText); + this.short_view_count = new Text(data.shortViewCountText); this.badges = Parser.parse(data.badges); this.duration = { text: new Text(data.lengthText).toString(), diff --git a/src/parser/classes/Endscreen.js b/src/parser/classes/Endscreen.ts similarity index 70% rename from src/parser/classes/Endscreen.js rename to src/parser/classes/Endscreen.ts index c683fc66..fc8f308d 100644 --- a/src/parser/classes/Endscreen.js +++ b/src/parser/classes/Endscreen.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class Endscreen extends YTNode { static type = 'Endscreen'; - constructor(data) { + elements; + start_ms: string; // Or number? + + constructor(data: any) { super(); this.elements = Parser.parse(data.elements); this.start_ms = data.startMs; diff --git a/src/parser/classes/ExpandableTab.js b/src/parser/classes/ExpandableTab.ts similarity index 77% rename from src/parser/classes/ExpandableTab.js rename to src/parser/classes/ExpandableTab.ts index 1f795501..cb963e51 100644 --- a/src/parser/classes/ExpandableTab.js +++ b/src/parser/classes/ExpandableTab.ts @@ -5,7 +5,12 @@ import { YTNode } from '../helpers'; class ExpandableTab extends YTNode { static type = 'ExpandableTab'; - constructor(data) { + title: string; + endpoint: NavigationEndpoint; + selected: boolean; + content; + + constructor(data: any) { super(); this.title = data.title; this.endpoint = new NavigationEndpoint(data.endpoint); diff --git a/src/parser/classes/ExpandedShelfContents.js b/src/parser/classes/ExpandedShelfContents.ts similarity index 80% rename from src/parser/classes/ExpandedShelfContents.js rename to src/parser/classes/ExpandedShelfContents.ts index 8c321dde..5fc3e8ad 100644 --- a/src/parser/classes/ExpandedShelfContents.js +++ b/src/parser/classes/ExpandedShelfContents.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class ExpandedShelfContents extends YTNode { static type = 'ExpandedShelfContents'; - constructor(data) { + items; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); } diff --git a/src/parser/classes/FeedFilterChipBar.js b/src/parser/classes/FeedFilterChipBar.ts similarity index 74% rename from src/parser/classes/FeedFilterChipBar.js rename to src/parser/classes/FeedFilterChipBar.ts index 421fe489..6983ac82 100644 --- a/src/parser/classes/FeedFilterChipBar.js +++ b/src/parser/classes/FeedFilterChipBar.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class FeedFilterChipBar extends YTNode { static type = 'FeedFilterChipBar'; - constructor(data) { + contents; + + constructor(data: any) { super(); this.contents = Parser.parse(data.contents); } diff --git a/src/parser/classes/FeedTabbedHeader.js b/src/parser/classes/FeedTabbedHeader.ts similarity index 72% rename from src/parser/classes/FeedTabbedHeader.js rename to src/parser/classes/FeedTabbedHeader.ts index d94801e3..abf7ddfc 100644 --- a/src/parser/classes/FeedTabbedHeader.js +++ b/src/parser/classes/FeedTabbedHeader.ts @@ -4,9 +4,12 @@ import { YTNode } from '../helpers'; class FeedTabbedHeader extends YTNode { static type = 'FeedTabbedHeader'; - constructor(data) { + title: Text; + + constructor(data: any) { super(); this.title = new Text(data.title); } } + export default FeedTabbedHeader; \ No newline at end of file diff --git a/src/parser/classes/Grid.js b/src/parser/classes/Grid.ts similarity index 76% rename from src/parser/classes/Grid.js rename to src/parser/classes/Grid.ts index 70cf0e08..05ac3622 100644 --- a/src/parser/classes/Grid.js +++ b/src/parser/classes/Grid.ts @@ -4,7 +4,14 @@ import { YTNode } from '../helpers'; class Grid extends YTNode { static type = 'Grid'; - constructor(data) { + items; + is_collapsible: boolean; + visible_row_count: string; + target_id: string; + continuation: string | null; + header?; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); this.is_collapsible = data.isCollapsible; diff --git a/src/parser/classes/GridChannel.js b/src/parser/classes/GridChannel.ts similarity index 79% rename from src/parser/classes/GridChannel.js rename to src/parser/classes/GridChannel.ts index 17529723..2df28983 100644 --- a/src/parser/classes/GridChannel.js +++ b/src/parser/classes/GridChannel.ts @@ -7,7 +7,14 @@ import { YTNode } from '../helpers'; class GridChannel extends YTNode { static type = 'GridChannel'; - constructor(data) { + id: string; + author: Author; + subscribers: Text; + video_count: Text; + endpoint: NavigationEndpoint; + subscribe_button; + + constructor(data: any) { super(); this.id = data.channelId; diff --git a/src/parser/classes/GridPlaylist.js b/src/parser/classes/GridPlaylist.ts similarity index 68% rename from src/parser/classes/GridPlaylist.js rename to src/parser/classes/GridPlaylist.ts index 0c3005c2..ffccc00d 100644 --- a/src/parser/classes/GridPlaylist.js +++ b/src/parser/classes/GridPlaylist.ts @@ -9,7 +9,19 @@ import { YTNode } from '../helpers'; class GridPlaylist extends YTNode { static type = 'GridPlaylist'; - constructor(data) { + id: string; + title: Text; + author?: PlaylistAuthor; + badges; + endpoint: NavigationEndpoint; + view_playlist: NavigatableText; + thumbnails: Thumbnail[]; + thumbnail_renderer; + sidebar_thumbnails: Thumbnail[] | null; + video_count: Text; + video_count_short: Text; + + constructor(data: any) { super(); this.id = data.playlistId; this.title = new Text(data.title); @@ -23,9 +35,9 @@ class GridPlaylist extends YTNode { this.view_playlist = new NavigatableText(data.viewPlaylistText); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.thumbnail_renderer = Parser.parse(data.thumbnailRenderer); - this.sidebar_thumbnails = [].concat(...data.sidebarThumbnails?.map((thumbnail) => Thumbnail.fromResponse(thumbnail)) || []) || null; + this.sidebar_thumbnails = [].concat(...data.sidebarThumbnails?.map((thumbnail: any) => Thumbnail.fromResponse(thumbnail)) || []) || null; this.video_count = new Text(data.thumbnailText); - this.video_count_short_text = new Text(data.videoCountShortText); + this.video_count_short = new Text(data.videoCountShortText); } } diff --git a/src/parser/classes/GridVideo.js b/src/parser/classes/GridVideo.ts similarity index 70% rename from src/parser/classes/GridVideo.js rename to src/parser/classes/GridVideo.ts index 44c191e6..0c250f07 100644 --- a/src/parser/classes/GridVideo.js +++ b/src/parser/classes/GridVideo.ts @@ -8,9 +8,22 @@ import { YTNode } from '../helpers'; class GridVideo extends YTNode { static type = 'GridVideo'; - constructor(data) { + id: string; + title: Text; + thumbnails: Thumbnail[]; + thumbnail_overlays; + rich_thumbnail; + published: Text; + duration: Text | string; + author: Author; + views: Text; + short_view_count: Text; + endpoint: NavigationEndpoint; + menu; + + constructor(data: any) { super(); - const length_alt = data.thumbnailOverlays.find((overlay) => overlay.hasOwnProperty('thumbnailOverlayTimeStatusRenderer'))?.thumbnailOverlayTimeStatusRenderer; + 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); diff --git a/src/parser/classes/HistorySuggestion.js b/src/parser/classes/HistorySuggestion.ts similarity index 73% rename from src/parser/classes/HistorySuggestion.js rename to src/parser/classes/HistorySuggestion.ts index d68e057e..4cb46d49 100644 --- a/src/parser/classes/HistorySuggestion.js +++ b/src/parser/classes/HistorySuggestion.ts @@ -3,7 +3,7 @@ import SearchSuggestion from './SearchSuggestion'; class HistorySuggestion extends SearchSuggestion { static type = 'HistorySuggestion'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/HorizontalCardList.js b/src/parser/classes/HorizontalCardList.ts similarity index 76% rename from src/parser/classes/HorizontalCardList.js rename to src/parser/classes/HorizontalCardList.ts index e7cd7fca..27963329 100644 --- a/src/parser/classes/HorizontalCardList.js +++ b/src/parser/classes/HorizontalCardList.ts @@ -4,7 +4,12 @@ import { YTNode } from '../helpers'; class HorizontalCardList extends YTNode { static type = 'HorizontalCardList'; - constructor(data) { + cards; + header; + previous_button; + next_button; + + constructor(data: any) { super(); this.cards = Parser.parse(data.cards); this.header = Parser.parse(data.header); diff --git a/src/parser/classes/HorizontalList.js b/src/parser/classes/HorizontalList.ts similarity index 77% rename from src/parser/classes/HorizontalList.js rename to src/parser/classes/HorizontalList.ts index fba006f4..d814053d 100644 --- a/src/parser/classes/HorizontalList.js +++ b/src/parser/classes/HorizontalList.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class HorizontalList extends YTNode { static type = 'HorizontalList'; - constructor(data) { + visible_item_count: string; + items; + + constructor(data: any) { super(); this.visible_item_count = data.visibleItemCount; this.items = Parser.parse(data.items); diff --git a/src/parser/classes/LikeButton.js b/src/parser/classes/LikeButton.ts similarity index 56% rename from src/parser/classes/LikeButton.js rename to src/parser/classes/LikeButton.ts index baa65f46..8135f443 100644 --- a/src/parser/classes/LikeButton.js +++ b/src/parser/classes/LikeButton.ts @@ -4,8 +4,17 @@ import { YTNode } from '../helpers'; class LikeButton extends YTNode { static type = 'LikeButton'; - constructor(data) { + target: { + video_id: string; + }; + + like_status: string; + likes_allowed: string; + endpoints?: NavigationEndpoint[]; + + constructor(data: any) { super(); + this.target = { video_id: data.target.videoId }; @@ -14,7 +23,7 @@ class LikeButton extends YTNode { this.likes_allowed = data.likesAllowed; if (data.serviceEndpoints) { - this.endpoints = data.serviceEndpoints?.map((endpoint) => new NavigationEndpoint(endpoint)); + this.endpoints = data.serviceEndpoints?.map((endpoint: any) => new NavigationEndpoint(endpoint)); } } } diff --git a/src/parser/classes/LiveChat.js b/src/parser/classes/LiveChat.ts similarity index 72% rename from src/parser/classes/LiveChat.js rename to src/parser/classes/LiveChat.ts index c749422c..6aacc05c 100644 --- a/src/parser/classes/LiveChat.js +++ b/src/parser/classes/LiveChat.ts @@ -5,7 +5,21 @@ import { YTNode } from '../helpers'; class LiveChat extends YTNode { static type = 'LiveChat'; - constructor(data) { + header; + initial_display_state: string; + continuation: string; + + client_messages: { + reconnect_message: Text; + unable_to_reconnect_message: Text; + fatal_error: Text; + reconnected_message: Text; + generic_error: Text; + }; + + is_replay: boolean; + + constructor(data: any) { super(); this.header = Parser.parse(data.header); this.initial_display_state = data.initialDisplayState; diff --git a/src/parser/classes/LiveChatAuthorBadge.js b/src/parser/classes/LiveChatAuthorBadge.ts similarity index 74% rename from src/parser/classes/LiveChatAuthorBadge.js rename to src/parser/classes/LiveChatAuthorBadge.ts index 2f1751c6..7c8fb203 100644 --- a/src/parser/classes/LiveChatAuthorBadge.js +++ b/src/parser/classes/LiveChatAuthorBadge.ts @@ -4,7 +4,9 @@ import Thumbnail from './misc/Thumbnail'; class LiveChatAuthorBadge extends MetadataBadge { static type = 'LiveChatAuthorBadge'; - constructor(data) { + custom_thumbnail: Thumbnail[] | null; + + constructor(data: any) { super(data); this.custom_thumbnail = data.customThumbnail ? Thumbnail.fromResponse(data.customThumbnail) : null; } diff --git a/src/parser/classes/LiveChatHeader.js b/src/parser/classes/LiveChatHeader.ts similarity index 75% rename from src/parser/classes/LiveChatHeader.js rename to src/parser/classes/LiveChatHeader.ts index bc9218ef..d1cd1613 100644 --- a/src/parser/classes/LiveChatHeader.js +++ b/src/parser/classes/LiveChatHeader.ts @@ -4,7 +4,11 @@ import { YTNode } from '../helpers'; class LiveChatHeader extends YTNode { static type = 'LiveChatHeader'; - constructor(data) { + overflow_menu; + collapse_button; + view_selector; + + constructor(data: any) { super(); this.overflow_menu = Parser.parse(data.overflowMenu); this.collapse_button = Parser.parse(data.collapseButton); diff --git a/src/parser/classes/LiveChatItemList.js b/src/parser/classes/LiveChatItemList.ts similarity index 71% rename from src/parser/classes/LiveChatItemList.js rename to src/parser/classes/LiveChatItemList.ts index 6b8f3edd..75c3ce6d 100644 --- a/src/parser/classes/LiveChatItemList.js +++ b/src/parser/classes/LiveChatItemList.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class LiveChatItemList extends YTNode { static type = 'LiveChatItemList'; - constructor(data) { + max_items_to_display: string; + more_comments_below_button; + + constructor(data: any) { super(); this.max_items_to_display = data.maxItemsToDisplay; this.more_comments_below_button = Parser.parse(data.moreCommentsBelowButton); diff --git a/src/parser/classes/LiveChatMessageInput.js b/src/parser/classes/LiveChatMessageInput.ts similarity index 75% rename from src/parser/classes/LiveChatMessageInput.js rename to src/parser/classes/LiveChatMessageInput.ts index 3fc43e7a..0708da59 100644 --- a/src/parser/classes/LiveChatMessageInput.js +++ b/src/parser/classes/LiveChatMessageInput.ts @@ -6,7 +6,12 @@ import { YTNode } from '../helpers'; class LiveChatMessageInput extends YTNode { static type = 'LiveChatMessageInput'; - constructor(data) { + author_name: Text; + author_photo: Thumbnail[]; + send_button; + target_id: string; + + constructor(data: any) { super(); this.author_name = new Text(data.authorName); this.author_photo = Thumbnail.fromResponse(data.authorPhoto); diff --git a/src/parser/classes/LiveChatParticipant.js b/src/parser/classes/LiveChatParticipant.ts similarity index 78% rename from src/parser/classes/LiveChatParticipant.js rename to src/parser/classes/LiveChatParticipant.ts index c997f97a..79a12fb5 100644 --- a/src/parser/classes/LiveChatParticipant.js +++ b/src/parser/classes/LiveChatParticipant.ts @@ -6,7 +6,11 @@ import { YTNode } from '../helpers'; class LiveChatParticipant extends YTNode { static type = 'LiveChatParticipant'; - constructor(data) { + name: Text; + photo: Thumbnail[]; + badges; + + constructor(data: any) { super(); this.name = new Text(data.authorName); this.photo = Thumbnail.fromResponse(data.authorPhoto); diff --git a/src/parser/classes/LiveChatParticipantsList.js b/src/parser/classes/LiveChatParticipantsList.ts similarity index 75% rename from src/parser/classes/LiveChatParticipantsList.js rename to src/parser/classes/LiveChatParticipantsList.ts index 1e3763de..f191169e 100644 --- a/src/parser/classes/LiveChatParticipantsList.js +++ b/src/parser/classes/LiveChatParticipantsList.ts @@ -5,7 +5,10 @@ import { YTNode } from '../helpers'; class LiveChatParticipantsList extends YTNode { static type = 'LiveChatParticipantsList'; - constructor(data) { + title: Text; + participants; + + constructor(data: any) { super(); this.title = new Text(data.title); this.participants = Parser.parse(data.participants); diff --git a/src/parser/classes/MerchandiseItem.js b/src/parser/classes/MerchandiseItem.ts similarity index 68% rename from src/parser/classes/MerchandiseItem.js rename to src/parser/classes/MerchandiseItem.ts index 4b7a4681..f08c0bd9 100644 --- a/src/parser/classes/MerchandiseItem.js +++ b/src/parser/classes/MerchandiseItem.ts @@ -5,7 +5,19 @@ import { YTNode } from '../helpers'; class MerchandiseItem extends YTNode { static type = 'MerchandiseItem'; - constructor(data) { + title: string; + description: string; + thumbnails: Thumbnail[]; + price: string; + vendor_name: string; + button_text: string; + button_accessibility_text: string; + from_vendor_text: string; + additional_fees_text: string; + region_format: string; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.title = data.title; this.description = data.description; diff --git a/src/parser/classes/MerchandiseShelf.js b/src/parser/classes/MerchandiseShelf.ts similarity index 79% rename from src/parser/classes/MerchandiseShelf.js rename to src/parser/classes/MerchandiseShelf.ts index 42b4bf12..326a9ea3 100644 --- a/src/parser/classes/MerchandiseShelf.js +++ b/src/parser/classes/MerchandiseShelf.ts @@ -4,7 +4,11 @@ import { YTNode } from '../helpers'; class MerchandiseShelf extends YTNode { static type = 'MerchandiseShelf'; - constructor(data) { + title: string; + menu; + items; + + constructor(data: any) { super(); this.title = data.title; this.menu = Parser.parse(data.actionButton); diff --git a/src/parser/classes/Message.js b/src/parser/classes/Message.ts similarity index 74% rename from src/parser/classes/Message.js rename to src/parser/classes/Message.ts index 93380203..bfc41982 100644 --- a/src/parser/classes/Message.js +++ b/src/parser/classes/Message.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class Message extends YTNode { static type = 'Message'; - constructor(data) { + text: string; + + constructor(data: any) { super(); this.text = new Text(data.text).toString(); } diff --git a/src/parser/classes/MetadataBadge.js b/src/parser/classes/MetadataBadge.ts similarity index 72% rename from src/parser/classes/MetadataBadge.js rename to src/parser/classes/MetadataBadge.ts index fba59d2e..bb829690 100644 --- a/src/parser/classes/MetadataBadge.js +++ b/src/parser/classes/MetadataBadge.ts @@ -3,7 +3,11 @@ import { YTNode } from '../helpers'; class MetadataBadge extends YTNode { static type = 'MetadataBadge'; - constructor(data) { + icon_type?: string; + style?: string; + tooltip: string | null; + + constructor(data: any) { super(); if (data?.icon) { diff --git a/src/parser/classes/MetadataRowHeader.js b/src/parser/classes/MetadataRowHeader.ts similarity index 70% rename from src/parser/classes/MetadataRowHeader.js rename to src/parser/classes/MetadataRowHeader.ts index 5258185f..886bda63 100644 --- a/src/parser/classes/MetadataRowHeader.js +++ b/src/parser/classes/MetadataRowHeader.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class MetadataRowHeader extends YTNode { static type = 'MetadataRowHeader'; - constructor(data) { + content: Text; + has_divider_line: boolean; + + constructor(data: any) { super(); this.content = new Text(data.content); this.has_divider_line = data.hasDividerLine; diff --git a/src/parser/classes/MicroformatData.js b/src/parser/classes/MicroformatData.ts similarity index 60% rename from src/parser/classes/MicroformatData.js rename to src/parser/classes/MicroformatData.ts index ab10c28d..9b2c29ad 100644 --- a/src/parser/classes/MicroformatData.js +++ b/src/parser/classes/MicroformatData.ts @@ -4,12 +4,36 @@ import { YTNode } from '../helpers'; class MicroformatData extends YTNode { static type = 'MicroformatData'; - constructor(data) { + url_canonical: string; + title: string; + description: string; + thumbnail: Thumbnail[] | null; + site_name: string; + app_name: string; + android_package: string; + ios_app_store_id: string; + ios_app_arguments: string; + og_type: string; + url_applinks_web: string; + url_applinks_ios: string; + url_applinks_android: string; + url_twitter_ios: string; + url_twitter_android: string; + twitter_card_type: string; + twitter_site_handle: string; + schema_dot_org_type: string; + noindex: string; + is_unlisted: boolean; + is_family_safe: boolean; + tags: any; // TODO: string array? + available_countries: string[]; + + constructor(data: any) { super(); this.url_canonical = data.urlCanonical; this.title = data.title; this.description = data.description; - this.thumbnail = data.thumbnail && Thumbnail.fromResponse(data.thumbnail); + this.thumbnail = data.thumbnail ? Thumbnail.fromResponse(data.thumbnail) : null; this.site_name = data.siteName; this.app_name = data.appName; this.android_package = data.androidPackage; diff --git a/src/parser/classes/Mix.js b/src/parser/classes/Mix.ts similarity index 71% rename from src/parser/classes/Mix.js rename to src/parser/classes/Mix.ts index 3d426255..9886591e 100644 --- a/src/parser/classes/Mix.js +++ b/src/parser/classes/Mix.ts @@ -3,7 +3,7 @@ import Playlist from './Playlist'; class Mix extends Playlist { static type = 'Mix'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/Movie.js b/src/parser/classes/Movie.ts similarity index 74% rename from src/parser/classes/Movie.js rename to src/parser/classes/Movie.ts index 4ea3f843..311dabe3 100644 --- a/src/parser/classes/Movie.js +++ b/src/parser/classes/Movie.ts @@ -9,15 +9,34 @@ import { YTNode } from '../helpers'; class Movie extends YTNode { static type = 'Movie'; - constructor(data) { + id: string; + title: Text; + description_snippet: Text | null; + top_metadata_items: Text; + thumbnails: Thumbnail[]; + thumbnail_overlays; + author: Author; + + duration: { + text: string; + seconds: number; + }; + + endpoint: NavigationEndpoint; + badges; + use_vertical_poster: boolean; + show_action_menu: boolean; + menu; + + constructor(data: any) { super(); const overlay_time_status = data.thumbnailOverlays - .find((overlay) => overlay.thumbnailOverlayTimeStatusRenderer) + .find((overlay: any) => overlay.thumbnailOverlayTimeStatusRenderer) ?.thumbnailOverlayTimeStatusRenderer.text || 'N/A'; this.id = data.videoId; this.title = new Text(data.title); - this.description_snippet = data.descriptionSnippet ? new Text(data.descriptionSnippet, '') : null; + 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); diff --git a/src/parser/classes/MovingThumbnail.js b/src/parser/classes/MovingThumbnail.ts similarity index 63% rename from src/parser/classes/MovingThumbnail.js rename to src/parser/classes/MovingThumbnail.ts index bab3fd01..3bc986ed 100644 --- a/src/parser/classes/MovingThumbnail.js +++ b/src/parser/classes/MovingThumbnail.ts @@ -4,9 +4,9 @@ import { YTNode } from '../helpers'; class MovingThumbnail extends YTNode { static type = 'MovingThumbnail'; - constructor(data) { + constructor(data: any) { super(); - return data.movingThumbnailDetails?.thumbnails.map((thumbnail) => new Thumbnail(thumbnail)).sort((a, b) => b.width - a.width); + return data.movingThumbnailDetails?.thumbnails.map((thumbnail: any) => new Thumbnail(thumbnail)).sort((a: any, b: any) => b.width - a.width); } } diff --git a/src/parser/classes/MusicDescriptionShelf.js b/src/parser/classes/MusicDescriptionShelf.ts similarity index 73% rename from src/parser/classes/MusicDescriptionShelf.js rename to src/parser/classes/MusicDescriptionShelf.ts index 3beb5797..075bb90e 100644 --- a/src/parser/classes/MusicDescriptionShelf.js +++ b/src/parser/classes/MusicDescriptionShelf.ts @@ -4,7 +4,12 @@ import { YTNode } from '../helpers'; class MusicDescriptionShelf extends YTNode { static type = 'MusicDescriptionShelf'; - constructor(data) { + description: Text; + max_collapsed_lines?: string; + max_expanded_lines?: string; + footer: Text; + + constructor(data: any) { super(); this.description = new Text(data.description); diff --git a/src/parser/classes/MusicDetailHeader.js b/src/parser/classes/MusicDetailHeader.js deleted file mode 100644 index bc34a00e..00000000 --- a/src/parser/classes/MusicDetailHeader.js +++ /dev/null @@ -1,35 +0,0 @@ -import Text from './misc/Text'; -import Thumbnail from './misc/Thumbnail'; -import Parser from '../index'; -import { YTNode } from '../helpers'; - -class MusicDetailHeader extends YTNode { - static type = 'MusicDetailHeader'; - - constructor(data) { - super(); - this.title = new Text(data.title); - this.description = new Text(data.description); - this.subtitle = new Text(data.subtitle); - this.second_subtitle = new Text(data.secondSubtitle); - this.year = this.subtitle.runs.find((run) => (/^[12][0-9]{3}$/).test(run.text))?.text || null; - this.song_count = this.second_subtitle.runs[0].text; - this.total_duration = this.second_subtitle.runs[2]?.text || ''; - this.thumbnails = Thumbnail.fromResponse(data.thumbnail.croppedSquareThumbnailRenderer.thumbnail); - this.badges = Parser.parse(data.subtitleBadges); - - const author = this.subtitle.runs.find((run) => run.endpoint?.browse?.id.startsWith('UC')); - - if (author) { - this.author = { - name: author.text, - channel_id: author.endpoint.browse.id, - endpoint: author.endpoint - }; - } - - this.menu = Parser.parse(data.menu); - } -} - -export default MusicDetailHeader; \ No newline at end of file diff --git a/src/parser/classes/MusicDetailHeader.ts b/src/parser/classes/MusicDetailHeader.ts new file mode 100644 index 00000000..20f1bec6 --- /dev/null +++ b/src/parser/classes/MusicDetailHeader.ts @@ -0,0 +1,53 @@ +import Text from './misc/Text'; +import TextRun from './misc/TextRun'; +import Thumbnail from './misc/Thumbnail'; +import NavigationEndpoint from './NavigationEndpoint'; +import Parser from '../index'; +import { YTNode } from '../helpers'; + +class MusicDetailHeader extends YTNode { + static type = 'MusicDetailHeader'; + + title: Text; + description: Text; + subtitle: Text; + second_subtitle: Text; + year: string; + song_count: string; + total_duration: string; + thumbnails: Thumbnail[]; + badges; + author?: { + name: string; + channel_id: string; + endpoint: NavigationEndpoint | undefined; + }; + menu; + + constructor(data: any) { + super(); + this.title = new Text(data.title); + this.description = new Text(data.description); + this.subtitle = new Text(data.subtitle); + this.second_subtitle = new Text(data.secondSubtitle); + this.year = this.subtitle.runs?.find((run) => (/^[12][0-9]{3}$/).test(run.text))?.text || ''; + this.song_count = this.second_subtitle.runs?.[0]?.text || ''; + this.total_duration = this.second_subtitle.runs?.[2]?.text || ''; + this.thumbnails = Thumbnail.fromResponse(data.thumbnail.croppedSquareThumbnailRenderer.thumbnail); + this.badges = Parser.parse(data.subtitleBadges); + + const author = this.subtitle.runs?.find((run) => (run as TextRun)?.endpoint?.browse?.id.startsWith('UC')); + + if (author) { + this.author = { + name: (author as TextRun).text, + channel_id: (author as TextRun).endpoint?.browse?.id, + endpoint: (author as TextRun).endpoint + }; + } + + this.menu = Parser.parse(data.menu); + } +} + +export default MusicDetailHeader; \ No newline at end of file diff --git a/src/parser/classes/MusicHeader.js b/src/parser/classes/MusicHeader.ts similarity index 80% rename from src/parser/classes/MusicHeader.js rename to src/parser/classes/MusicHeader.ts index 6091f652..63ce0ad4 100644 --- a/src/parser/classes/MusicHeader.js +++ b/src/parser/classes/MusicHeader.ts @@ -5,7 +5,10 @@ import Text from './misc/Text'; class MusicHeader extends YTNode { static type = 'MusicHeader'; - constructor(data) { + header?; + title?: Text; + + constructor(data: any) { super(); if (data.header) { diff --git a/src/parser/classes/MusicInlineBadge.js b/src/parser/classes/MusicInlineBadge.ts similarity index 71% rename from src/parser/classes/MusicInlineBadge.js rename to src/parser/classes/MusicInlineBadge.ts index 305f8aea..b18fd2e8 100644 --- a/src/parser/classes/MusicInlineBadge.js +++ b/src/parser/classes/MusicInlineBadge.ts @@ -3,7 +3,10 @@ import { YTNode } from '../helpers'; class MusicInlineBadge extends YTNode { static type = 'MusicInlineBadge'; - constructor(data) { + icon_type: string; + label: string; + + constructor(data: any) { super(); this.icon_type = data.icon.iconType; this.label = data.accessibilityData.accessibilityData.label; diff --git a/src/parser/classes/MusicItemThumbnailOverlay.js b/src/parser/classes/MusicItemThumbnailOverlay.ts similarity index 72% rename from src/parser/classes/MusicItemThumbnailOverlay.js rename to src/parser/classes/MusicItemThumbnailOverlay.ts index 4485d815..976779d2 100644 --- a/src/parser/classes/MusicItemThumbnailOverlay.js +++ b/src/parser/classes/MusicItemThumbnailOverlay.ts @@ -4,7 +4,11 @@ import { YTNode } from '../helpers'; class MusicItemThumbnailOverlay extends YTNode { static type = 'MusicItemThumbnailOverlay'; - constructor(data) { + content; + content_position; + display_style: string; + + constructor(data: any) { super(); this.content = Parser.parse(data.content); this.content_position = data.contentPosition; diff --git a/src/parser/classes/MusicPlayButton.js b/src/parser/classes/MusicPlayButton.ts similarity index 76% rename from src/parser/classes/MusicPlayButton.js rename to src/parser/classes/MusicPlayButton.ts index 71200691..5e689b99 100644 --- a/src/parser/classes/MusicPlayButton.js +++ b/src/parser/classes/MusicPlayButton.ts @@ -4,7 +4,14 @@ import { YTNode } from '../helpers'; class MusicPlayButton extends YTNode { static type = 'MusicPlayButton'; - constructor(data) { + endpoint: NavigationEndpoint; + play_icon_type: string; + pause_icon_type: string; + play_label; + pause_label; + icon_color: string; + + constructor(data: any) { super(); this.endpoint = new NavigationEndpoint(data.playNavigationEndpoint); this.play_icon_type = data.playIcon.iconType; diff --git a/src/parser/classes/MusicQueue.js b/src/parser/classes/MusicQueue.ts similarity index 75% rename from src/parser/classes/MusicQueue.js rename to src/parser/classes/MusicQueue.ts index f4a75d5e..1813fb7a 100644 --- a/src/parser/classes/MusicQueue.js +++ b/src/parser/classes/MusicQueue.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class MusicQueue extends YTNode { static type = 'MusicQueue'; - constructor(data) { + content; + + constructor(data: any) { super(); this.content = Parser.parse(data.content); } diff --git a/src/parser/classes/MusicResponsiveListItemFixedColumn.js b/src/parser/classes/MusicResponsiveListItemFixedColumn.ts similarity index 71% rename from src/parser/classes/MusicResponsiveListItemFixedColumn.js rename to src/parser/classes/MusicResponsiveListItemFixedColumn.ts index 1d3fe52b..ff75c87d 100644 --- a/src/parser/classes/MusicResponsiveListItemFixedColumn.js +++ b/src/parser/classes/MusicResponsiveListItemFixedColumn.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class MusicResponsiveListItemFixedColumn extends YTNode { static type = 'musicResponsiveListItemFlexColumnRenderer'; - constructor(data) { + title: Text; + display_priority: string; + + constructor(data: any) { super(); this.title = new Text(data.text); this.display_priority = data.displayPriority; diff --git a/src/parser/classes/MusicResponsiveListItemFlexColumn.js b/src/parser/classes/MusicResponsiveListItemFlexColumn.ts similarity index 71% rename from src/parser/classes/MusicResponsiveListItemFlexColumn.js rename to src/parser/classes/MusicResponsiveListItemFlexColumn.ts index 37c9f507..c0950690 100644 --- a/src/parser/classes/MusicResponsiveListItemFlexColumn.js +++ b/src/parser/classes/MusicResponsiveListItemFlexColumn.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class MusicResponsiveListItemFlexColumn extends YTNode { static type = 'musicResponsiveListItemFlexColumnRenderer'; - constructor(data) { + title: Text; + display_priority: string; + + constructor(data: any) { super(); this.title = new Text(data.text); this.display_priority = data.displayPriority; diff --git a/src/parser/classes/MusicTwoRowItem.js b/src/parser/classes/MusicTwoRowItem.ts similarity index 53% rename from src/parser/classes/MusicTwoRowItem.js rename to src/parser/classes/MusicTwoRowItem.ts index 3c5ee90a..87f3bdfd 100644 --- a/src/parser/classes/MusicTwoRowItem.js +++ b/src/parser/classes/MusicTwoRowItem.ts @@ -1,5 +1,8 @@ +// TODO: refactor this + import Parser from '../index'; import Text from './misc/Text'; +import TextRun from './misc/TextRun'; import Thumbnail from './misc/Thumbnail'; import NavigationEndpoint from './NavigationEndpoint'; import { YTNode } from '../helpers'; @@ -7,7 +10,36 @@ import { YTNode } from '../helpers'; class MusicTwoRowItem extends YTNode { static type = 'MusicTwoRowItem'; - constructor(data) { + title: Text; + endpoint: NavigationEndpoint; + id: string | undefined; + subtitle: Text; + badges; + + item_type: string; + + subscribers?: string; + item_count?: string | null; + year?: string; + views?: string; + + artists?: { + name: string; + channel_id: string; + endpoint: NavigationEndpoint | undefined; + }[]; + + author?: { + name: string; + channel_id: string; + endpoint: NavigationEndpoint | undefined; + }; + + thumbnail: Thumbnail[]; + thumbnail_overlay; + menu; + + constructor(data: any) { super(); this.title = new Text(data.title); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); @@ -26,22 +58,23 @@ class MusicTwoRowItem extends YTNode { break; case 'MUSIC_PAGE_TYPE_PLAYLIST': this.item_type = 'playlist'; - this.item_count = this.subtitle.runs - .find((run) => run.text.match(/\d+ songs|song/))?.item || null; + + const item_count_run = this.subtitle.runs?.find((run) => run.text.match(/\d+ songs|song/)); + this.item_count = item_count_run ? (item_count_run as TextRun).text : null; break; case 'MUSIC_PAGE_TYPE_ALBUM': this.item_type = 'album'; - const artists = this.subtitle.runs.filter((run) => run.endpoint?.browse?.id.startsWith('UC')); + const artists = this.subtitle.runs?.filter((run: any) => run.endpoint?.browse?.id.startsWith('UC')); if (artists) { - this.artists = artists.map((artist) => ({ + this.artists = artists.map((artist: any) => ({ name: artist.text, channel_id: artist.endpoint.browse.id, endpoint: artist.endpoint })); } - this.year = this.subtitle.runs.slice(-1)[0].text; - if (isNaN(this.year)) + this.year = this.subtitle.runs?.slice(-1)[0].text; + if (isNaN(Number(this.year))) delete this.year; break; default: @@ -58,24 +91,23 @@ class MusicTwoRowItem extends YTNode { } if (this.item_type == 'video') { - this.views = this.subtitle.runs - .find((run) => run?.text.match(/(.*?) views/))?.text || 'N/A'; + this.views = this?.subtitle.runs?.find((run) => run?.text.match(/(.*?) views/))?.text || 'N/A'; - const author = this.subtitle.runs.find((run) => run.endpoint?.browse?.id.startsWith('UC')); + const author = this.subtitle.runs?.find((run: any) => run.endpoint?.browse?.id?.startsWith('UC')); if (author) { this.author = { - name: author.text, - channel_id: author.endpoint.browse.id, - endpoint: author.endpoint + name: (author as TextRun)?.text, + channel_id: (author as TextRun)?.endpoint?.browse?.id, + endpoint: (author as TextRun)?.endpoint }; } } else if (this.item_type == 'song') { - const artists = this.subtitle.runs.filter((run) => run.endpoint?.browse?.id.startsWith('UC')); + const artists = this.subtitle.runs?.filter((run: any) => run.endpoint?.browse?.id.startsWith('UC')); if (artists) { - this.artists = artists.map((artist) => ({ - name: artist.text, - channel_id: artist.endpoint.browse.id, - endpoint: artist.endpoint + this.artists = artists.map((artist: any) => ({ + name: (artist as TextRun)?.text, + channel_id: (artist as TextRun)?.endpoint?.browse?.id, + endpoint: (artist as TextRun)?.endpoint })); } } @@ -88,4 +120,4 @@ class MusicTwoRowItem extends YTNode { } } -export default MusicTwoRowItem; +export default MusicTwoRowItem; \ No newline at end of file diff --git a/src/parser/classes/NavigationEndpoint.ts b/src/parser/classes/NavigationEndpoint.ts index efe35572..3160685a 100644 --- a/src/parser/classes/NavigationEndpoint.ts +++ b/src/parser/classes/NavigationEndpoint.ts @@ -8,13 +8,13 @@ class NavigationEndpoint extends YTNode { static type = 'NavigationEndpoint'; payload; - dialog; + dialog?; metadata: { url?: string; api_url?: string; page_type?: string; - send_post?: boolean; // TODO: is this boolean? + send_post?: boolean; // TODO: is this a boolean? }; // TODO: these should be given proper types, currently infered diff --git a/src/parser/classes/Notification.js b/src/parser/classes/Notification.ts similarity index 73% rename from src/parser/classes/Notification.js rename to src/parser/classes/Notification.ts index b7da28af..8ab22939 100644 --- a/src/parser/classes/Notification.js +++ b/src/parser/classes/Notification.ts @@ -7,7 +7,17 @@ import { YTNode } from '../helpers'; class Notification extends YTNode { static type = 'Notification'; - constructor(data) { + thumbnails: Thumbnail[]; + video_thumbnails: Thumbnail[]; + short_message: Text; + sent_time: Text; + notification_id: any; + endpoint: NavigationEndpoint; + record_click_endpoint: NavigationEndpoint; + menu; + read: boolean; + + constructor(data: any) { super(); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.video_thumbnails = Thumbnail.fromResponse(data.videoThumbnail); diff --git a/src/parser/classes/PlayerAnnotationsExpanded.js b/src/parser/classes/PlayerAnnotationsExpanded.ts similarity index 65% rename from src/parser/classes/PlayerAnnotationsExpanded.js rename to src/parser/classes/PlayerAnnotationsExpanded.ts index c9a7c31c..a7c0cf9a 100644 --- a/src/parser/classes/PlayerAnnotationsExpanded.js +++ b/src/parser/classes/PlayerAnnotationsExpanded.ts @@ -1,12 +1,24 @@ import Parser from '../index'; import Thumbnail from './misc/Thumbnail'; import NavigationEndpoint from './NavigationEndpoint'; -import { YTNode } from '../helpers'; +import { YTNode, SuperParsedResult } from '../helpers'; class PlayerAnnotationsExpanded extends YTNode { static type = 'PlayerAnnotationsExpanded'; - constructor(data) { + featured_channel: { + start_time_ms: number; + end_time_ms: number; + watermark: Thumbnail[]; + channel_name: string; + endpoint: NavigationEndpoint; + subscribe_button: SuperParsedResult; + }; + + allow_swipe_dismiss: boolean; + annotation_id: string; + + constructor(data: any) { super(); this.featured_channel = { diff --git a/src/parser/classes/PlayerCaptionsTracklist.js b/src/parser/classes/PlayerCaptionsTracklist.ts similarity index 53% rename from src/parser/classes/PlayerCaptionsTracklist.js rename to src/parser/classes/PlayerCaptionsTracklist.ts index a7efa1ef..99d089e2 100644 --- a/src/parser/classes/PlayerCaptionsTracklist.js +++ b/src/parser/classes/PlayerCaptionsTracklist.ts @@ -4,9 +4,27 @@ import { YTNode } from '../helpers'; class PlayerCaptionsTracklist extends YTNode { static type = 'PlayerCaptionsTracklist'; - constructor(data) { + caption_tracks: { + base_url: string; + name: Text; + vss_id: string; + language_code: string; + kind: string; + is_translatable: boolean; + }[]; + + audio_tracks: { + caption_track_indices: number; + }[]; + + translation_languages: { + language_code: string; + language_name: Text; + }[]; + + constructor(data: any) { super(); - this.caption_tracks = data.captionTracks.map((ct) => ({ + this.caption_tracks = data.captionTracks.map((ct: any) => ({ base_url: ct.baseUrl, name: new Text(ct.name), vss_id: ct.vssId, @@ -15,11 +33,11 @@ class PlayerCaptionsTracklist extends YTNode { is_translatable: ct.isTranslatable })); - this.audio_tracks = data.audioTracks.map((at) => ({ + this.audio_tracks = data.audioTracks.map((at: any) => ({ caption_track_indices: at.captionTrackIndices })); - this.translation_languages = data.translationLanguages.map((tl) => ({ + this.translation_languages = data.translationLanguages.map((tl: any) => ({ language_code: tl.languageCode, language_name: new Text(tl.languageName) })); diff --git a/src/parser/classes/PlayerErrorMessage.js b/src/parser/classes/PlayerErrorMessage.ts similarity index 75% rename from src/parser/classes/PlayerErrorMessage.js rename to src/parser/classes/PlayerErrorMessage.ts index 0f2f456f..8a14f080 100644 --- a/src/parser/classes/PlayerErrorMessage.js +++ b/src/parser/classes/PlayerErrorMessage.ts @@ -6,7 +6,13 @@ import { YTNode } from '../helpers'; class PlayerErrorMessage extends YTNode { static type = 'PlayerErrorMessage'; - constructor(data) { + subreason: Text; + reason: Text; + proceed_button; + thumbnails: Thumbnail[]; + icon_type: string; + + constructor(data: any) { super(); this.subreason = new Text(data.subreason); this.reason = new Text(data.reason); diff --git a/src/parser/classes/PlayerLiveStoryboardSpec.js b/src/parser/classes/PlayerLiveStoryboardSpec.ts similarity index 100% rename from src/parser/classes/PlayerLiveStoryboardSpec.js rename to src/parser/classes/PlayerLiveStoryboardSpec.ts diff --git a/src/parser/classes/PlayerMicroformat.js b/src/parser/classes/PlayerMicroformat.ts similarity index 66% rename from src/parser/classes/PlayerMicroformat.js rename to src/parser/classes/PlayerMicroformat.ts index 2737a82d..5dbab4d2 100644 --- a/src/parser/classes/PlayerMicroformat.js +++ b/src/parser/classes/PlayerMicroformat.ts @@ -5,7 +5,37 @@ import { YTNode } from '../helpers'; class PlayerMicroformat extends YTNode { static type = 'PlayerMicroformat'; - constructor(data) { + title: Text; + description: Text; + thumbnails; + + embed: { + iframe_url: string; + flash_url: string; + flash_secure_url: string; + // TODO: check these + width: any; + height: any; + }; + + length_seconds: number; + + channel: { + id: string; + name: string; + url: string; + }; + + is_family_safe: boolean; + is_unlisted: boolean; + has_ypc_metadata: boolean; + view_count: number; + category: string; + publish_date: string; + upload_date: string; + available_countries: string[]; + + constructor(data: any) { super(); this.title = new Text(data.title); this.description = new Text(data.description); diff --git a/src/parser/classes/PlayerOverlay.js b/src/parser/classes/PlayerOverlay.ts similarity index 76% rename from src/parser/classes/PlayerOverlay.js rename to src/parser/classes/PlayerOverlay.ts index c39a9931..33174246 100644 --- a/src/parser/classes/PlayerOverlay.js +++ b/src/parser/classes/PlayerOverlay.ts @@ -4,7 +4,13 @@ import { YTNode } from '../helpers'; class PlayerOverlay extends YTNode { static type = 'PlayerOverlay'; - constructor(data) { + end_screen; + autoplay; + share_button; + add_to_menu; + fullscreen_engagement; + + constructor(data: any) { super(); this.end_screen = Parser.parse(data.endScreen); this.autoplay = Parser.parse(data.autoplay); diff --git a/src/parser/classes/PlayerOverlayAutoplay.js b/src/parser/classes/PlayerOverlayAutoplay.ts similarity index 74% rename from src/parser/classes/PlayerOverlayAutoplay.js rename to src/parser/classes/PlayerOverlayAutoplay.ts index 3935c107..9b0e1ad4 100644 --- a/src/parser/classes/PlayerOverlayAutoplay.js +++ b/src/parser/classes/PlayerOverlayAutoplay.ts @@ -7,7 +7,21 @@ import { YTNode } from '../helpers'; class PlayerOverlayAutoplay extends YTNode { static type = 'PlayerOverlayAutoplay'; - constructor(data) { + title: Text; + video_id: string; + video_title: Text; + short_view_count: Text; + prefer_immediate_redirect: any; + count_down_secs_for_fullscreen: any; + published: Text; + background: Thumbnail[]; + thumbnail_overlays; + author: Author; + cancel_button; + next_button; + close_button; + + constructor(data: any) { super(); this.title = new Text(data.title); this.video_id = data.videoId; diff --git a/src/parser/classes/PlayerStoryboardSpec.js b/src/parser/classes/PlayerStoryboardSpec.js deleted file mode 100644 index c3c674f0..00000000 --- a/src/parser/classes/PlayerStoryboardSpec.js +++ /dev/null @@ -1,37 +0,0 @@ -import { YTNode } from '../helpers'; - -class PlayerStoryboardSpec extends YTNode { - static type = 'PlayerStoryboardSpec'; - - constructor(data) { - super(); - - const parts = data.spec.split('|'); - const url = new URL(parts.shift()); - - this.boards = parts.map((part, i) => { - let [ thumbnail_width, thumbnail_height, thumbnail_count, columns, rows, interval, name, sigh ] = part.split('#'); - - url.searchParams.set('sigh', sigh); - - thumbnail_count = parseInt(thumbnail_count, 10); - columns = parseInt(columns, 10); - rows = parseInt(rows, 10); - - const storyboard_count = Math.ceil(thumbnail_count / (columns * rows)); - - return { - template_url: url.toString().replace('$L', i).replace('$N', name), - thumbnail_width: parseInt(thumbnail_width, 10), - thumbnail_height: parseInt(thumbnail_height, 10), - thumbnail_count, - interval: parseInt(interval, 10), - columns, - rows, - storyboard_count - }; - }); - } -} - -export default PlayerStoryboardSpec; \ No newline at end of file diff --git a/src/parser/classes/PlayerStoryboardSpec.ts b/src/parser/classes/PlayerStoryboardSpec.ts new file mode 100644 index 00000000..05c2eba5 --- /dev/null +++ b/src/parser/classes/PlayerStoryboardSpec.ts @@ -0,0 +1,44 @@ +import { YTNode } from '../helpers'; + +class PlayerStoryboardSpec extends YTNode { + static type = 'PlayerStoryboardSpec'; + + boards: { + template_url: string; + thumbnail_width: number; + thumbnail_height: number; + thumbnail_count: number; + interval: number; + columns: number; + rows: number; + storyboard_count: number; + }; + + constructor(data: any) { + super(); + + const parts = data.spec.split('|'); + const url = new URL(parts.shift()); + + this.boards = parts.map((part: any, i: any) => { + const [ thumbnail_width, thumbnail_height, thumbnail_count, columns, rows, interval, name, sigh ] = part.split('#'); + + url.searchParams.set('sigh', sigh); + + const storyboard_count = Math.ceil(parseInt(thumbnail_count, 10) / (parseInt(columns, 10) * parseInt(rows, 10))); + + return { + template_url: url.toString().replace('$L', i).replace('$N', name), + thumbnail_width: parseInt(thumbnail_width, 10), + thumbnail_height: parseInt(thumbnail_height, 10), + thumbnail_count: parseInt(thumbnail_count, 10), + interval: parseInt(interval, 10), + columns: parseInt(columns, 10), + rows: parseInt(rows, 10), + storyboard_count + }; + }); + } +} + +export default PlayerStoryboardSpec; \ No newline at end of file diff --git a/src/parser/classes/Poll.js b/src/parser/classes/Poll.ts similarity index 67% rename from src/parser/classes/Poll.js rename to src/parser/classes/Poll.ts index 20c531fa..278a7132 100644 --- a/src/parser/classes/Poll.js +++ b/src/parser/classes/Poll.ts @@ -6,10 +6,25 @@ import { YTNode } from '../helpers'; class Poll extends YTNode { static type = 'Poll'; - constructor(data) { + choices: { + text: string; + 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; + image: Thumbnail[] | null; + }[]; + + poll_type; + total_votes; + live_chat_poll_id; + + constructor(data: any) { super(); - this.choices = data.choices.map((choice) => ({ + this.choices = data.choices.map((choice: any) => ({ text: new Text(choice.text).toString(), select_endpoint: choice.selectServiceEndpoint ? new NavigationEndpoint(choice.selectServiceEndpoint) : null, deselect_endpoint: choice.deselectServiceEndpoint ? new NavigationEndpoint(choice.deselectServiceEndpoint) : null, diff --git a/src/parser/classes/Post.js b/src/parser/classes/Post.ts similarity index 73% rename from src/parser/classes/Post.js rename to src/parser/classes/Post.ts index fefdd77f..d0f6db2b 100644 --- a/src/parser/classes/Post.js +++ b/src/parser/classes/Post.ts @@ -3,7 +3,7 @@ import BackstagePost from './BackstagePost'; class Post extends BackstagePost { static type = 'Post'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/ProfileColumn.js b/src/parser/classes/ProfileColumn.ts similarity index 81% rename from src/parser/classes/ProfileColumn.js rename to src/parser/classes/ProfileColumn.ts index 3d73d1e4..3f073714 100644 --- a/src/parser/classes/ProfileColumn.js +++ b/src/parser/classes/ProfileColumn.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class ProfileColumn extends YTNode { static type = 'ProfileColumn'; - constructor(data) { + items; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); } diff --git a/src/parser/classes/ProfileColumnStats.js b/src/parser/classes/ProfileColumnStats.ts similarity index 80% rename from src/parser/classes/ProfileColumnStats.js rename to src/parser/classes/ProfileColumnStats.ts index c08050ad..48a2a698 100644 --- a/src/parser/classes/ProfileColumnStats.js +++ b/src/parser/classes/ProfileColumnStats.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class ProfileColumnStats extends YTNode { static type = 'ProfileColumnStats'; - constructor(data) { + items; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); } diff --git a/src/parser/classes/ProfileColumnStatsEntry.js b/src/parser/classes/ProfileColumnStatsEntry.ts similarity index 72% rename from src/parser/classes/ProfileColumnStatsEntry.js rename to src/parser/classes/ProfileColumnStatsEntry.ts index b73e738a..edcb20d5 100644 --- a/src/parser/classes/ProfileColumnStatsEntry.js +++ b/src/parser/classes/ProfileColumnStatsEntry.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class ProfileColumnStatsEntry extends YTNode { static type = 'ProfileColumnStatsEntry'; - constructor(data) { + label: Text; + value: Text; + + constructor(data: any) { super(); this.label = new Text(data.label); this.value = new Text(data.value); diff --git a/src/parser/classes/ProfileColumnUserInfo.js b/src/parser/classes/ProfileColumnUserInfo.ts similarity index 74% rename from src/parser/classes/ProfileColumnUserInfo.js rename to src/parser/classes/ProfileColumnUserInfo.ts index ecdddba1..f9e44db2 100644 --- a/src/parser/classes/ProfileColumnUserInfo.js +++ b/src/parser/classes/ProfileColumnUserInfo.ts @@ -5,7 +5,10 @@ import { YTNode } from '../helpers'; class ProfileColumnUserInfo extends YTNode { static type = 'ProfileColumnUserInfo'; - constructor(data) { + title: Text; + thumbnails: Thumbnail[]; + + constructor(data: any) { super(); this.title = new Text(data.title); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); diff --git a/src/parser/classes/ReelItem.js b/src/parser/classes/ReelItem.ts similarity index 62% rename from src/parser/classes/ReelItem.js rename to src/parser/classes/ReelItem.ts index 534861af..15579ead 100644 --- a/src/parser/classes/ReelItem.js +++ b/src/parser/classes/ReelItem.ts @@ -6,12 +6,18 @@ import { YTNode } from '../helpers'; class ReelItem extends YTNode { static type = 'ReelItem'; - constructor(data) { + id: string; + title: Text; + thumbnails: Thumbnail[]; + views: Text; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.id = data.videoId; - this.title = new Text(data.headline, ''); + this.title = new Text(data.headline); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); - this.views = new Text(data.viewCountText, ''); + this.views = new Text(data.viewCountText); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); } } diff --git a/src/parser/classes/ReelShelf.js b/src/parser/classes/ReelShelf.ts similarity index 80% rename from src/parser/classes/ReelShelf.js rename to src/parser/classes/ReelShelf.ts index 825fad5f..5003b52a 100644 --- a/src/parser/classes/ReelShelf.js +++ b/src/parser/classes/ReelShelf.ts @@ -6,7 +6,11 @@ import { YTNode } from '../helpers'; class ReelShelf extends YTNode { static type = 'ReelShelf'; - constructor(data) { + title: Text; + items; + endpoint: NavigationEndpoint | null; + + constructor(data: any) { super(); this.title = new Text(data.title); this.items = Parser.parse(data.items); diff --git a/src/parser/classes/RelatedChipCloud.js b/src/parser/classes/RelatedChipCloud.ts similarity index 75% rename from src/parser/classes/RelatedChipCloud.js rename to src/parser/classes/RelatedChipCloud.ts index a1ac784c..0e75c040 100644 --- a/src/parser/classes/RelatedChipCloud.js +++ b/src/parser/classes/RelatedChipCloud.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class RelatedChipCloud extends YTNode { static type = 'RelatedChipCloud'; - constructor(data) { + content; + + constructor(data: any) { super(); this.content = Parser.parse(data.content); } diff --git a/src/parser/classes/RichGrid.js b/src/parser/classes/RichGrid.ts similarity index 84% rename from src/parser/classes/RichGrid.js rename to src/parser/classes/RichGrid.ts index 1980dfa0..06d75698 100644 --- a/src/parser/classes/RichGrid.js +++ b/src/parser/classes/RichGrid.ts @@ -4,7 +4,11 @@ import { YTNode } from '../helpers'; class RichGrid extends YTNode { static type = 'RichGrid'; - constructor(data) { + + header; + contents; + + constructor(data: any) { super(); // XXX: we don't parse the masthead since it is usually an advertisement // XXX: reflowOptions aren't parsed, I think its only used internally for layout @@ -12,4 +16,5 @@ class RichGrid extends YTNode { this.contents = Parser.parse(data.contents); } } -export default RichGrid; + +export default RichGrid; \ No newline at end of file diff --git a/src/parser/classes/RichItem.js b/src/parser/classes/RichItem.ts similarity index 52% rename from src/parser/classes/RichItem.js rename to src/parser/classes/RichItem.ts index f66f47e2..6289322d 100644 --- a/src/parser/classes/RichItem.js +++ b/src/parser/classes/RichItem.ts @@ -4,9 +4,12 @@ import { YTNode } from '../helpers'; class RichItem extends YTNode { static type = 'RichItem'; - constructor(data) { + content; + + constructor(data: any) { super(); - return Parser.parse(data.content); + // TODO: check this + this.content = Parser.parse(data.content); } } diff --git a/src/parser/classes/RichListHeader.js b/src/parser/classes/RichListHeader.ts similarity index 72% rename from src/parser/classes/RichListHeader.js rename to src/parser/classes/RichListHeader.ts index d17a04b4..bd4f7e77 100644 --- a/src/parser/classes/RichListHeader.js +++ b/src/parser/classes/RichListHeader.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class RichListHeader extends YTNode { static type = 'RichListHeader'; - constructor(data) { + title: Text; + icon_type: string; + + constructor(data: any) { super(); this.title = new Text(data.title); this.icon_type = data.icon.iconType; diff --git a/src/parser/classes/RichSection.js b/src/parser/classes/RichSection.ts similarity index 75% rename from src/parser/classes/RichSection.js rename to src/parser/classes/RichSection.ts index 81a2eb0c..f17eb41a 100644 --- a/src/parser/classes/RichSection.js +++ b/src/parser/classes/RichSection.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class RichSection extends YTNode { static type = 'RichSection'; - constructor(data) { + contents; + + constructor(data: any) { super(); this.contents = Parser.parse(data.content); } diff --git a/src/parser/classes/RichShelf.js b/src/parser/classes/RichShelf.ts similarity index 77% rename from src/parser/classes/RichShelf.js rename to src/parser/classes/RichShelf.ts index bca7ea33..9fb870e9 100644 --- a/src/parser/classes/RichShelf.js +++ b/src/parser/classes/RichShelf.ts @@ -6,7 +6,11 @@ import { YTNode } from '../helpers'; class RichShelf extends YTNode { static type = 'RichShelf'; - constructor(data) { + title: Text; + contents; + endpoint: NavigationEndpoint | null; + + constructor(data: any) { super(); this.title = new Text(data.title); this.contents = Parser.parse(data.contents); diff --git a/src/parser/classes/SearchBox.js b/src/parser/classes/SearchBox.ts similarity index 76% rename from src/parser/classes/SearchBox.js rename to src/parser/classes/SearchBox.ts index 220d8c98..d1355371 100644 --- a/src/parser/classes/SearchBox.js +++ b/src/parser/classes/SearchBox.ts @@ -6,7 +6,12 @@ import { YTNode } from '../helpers'; class SearchBox extends YTNode { static type = 'SearchBox'; - constructor(data) { + endpoint: NavigationEndpoint; + search_button; + clear_button; + placeholder_text: Text; + + constructor(data: any) { super(); this.endpoint = new NavigationEndpoint(data.endpoint); this.search_button = Parser.parse(data.searchButton); diff --git a/src/parser/classes/SearchRefinementCard.js b/src/parser/classes/SearchRefinementCard.ts similarity index 76% rename from src/parser/classes/SearchRefinementCard.js rename to src/parser/classes/SearchRefinementCard.ts index a391814c..63ce0c64 100644 --- a/src/parser/classes/SearchRefinementCard.js +++ b/src/parser/classes/SearchRefinementCard.ts @@ -6,7 +6,11 @@ import { YTNode } from '../helpers'; class SearchRefinementCard extends YTNode { static type = 'SearchRefinementCard'; - constructor(data) { + thumbnails: Thumbnail[]; + endpoint: NavigationEndpoint; + query: string; + + constructor(data: any) { super(); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.endpoint = new NavigationEndpoint(data.searchEndpoint); diff --git a/src/parser/classes/SearchSuggestion.js b/src/parser/classes/SearchSuggestion.ts similarity index 76% rename from src/parser/classes/SearchSuggestion.js rename to src/parser/classes/SearchSuggestion.ts index 14fcf1b4..575bb2c3 100644 --- a/src/parser/classes/SearchSuggestion.js +++ b/src/parser/classes/SearchSuggestion.ts @@ -5,7 +5,12 @@ import { YTNode } from '../helpers'; class SearchSuggestion extends YTNode { static type = 'SearchSuggestion'; - constructor(data) { + suggestion: Text; + endpoint: NavigationEndpoint; + icon_type: string; + service_endpoint; + + constructor(data: any) { super(); this.suggestion = new Text(data.suggestion); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); diff --git a/src/parser/classes/SearchSuggestionsSection.js b/src/parser/classes/SearchSuggestionsSection.ts similarity index 74% rename from src/parser/classes/SearchSuggestionsSection.js rename to src/parser/classes/SearchSuggestionsSection.ts index eb309987..83fa0cd9 100644 --- a/src/parser/classes/SearchSuggestionsSection.js +++ b/src/parser/classes/SearchSuggestionsSection.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class SearchSuggestionsSection extends YTNode { static type = 'SearchSuggestionsSection'; - constructor(data) { + contents; + + constructor(data: any) { super(); this.contents = Parser.parse(data.contents); } diff --git a/src/parser/classes/SecondarySearchContainer.js b/src/parser/classes/SecondarySearchContainer.ts similarity index 74% rename from src/parser/classes/SecondarySearchContainer.js rename to src/parser/classes/SecondarySearchContainer.ts index 45085024..29e5ae33 100644 --- a/src/parser/classes/SecondarySearchContainer.js +++ b/src/parser/classes/SecondarySearchContainer.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class SecondarySearchContainer extends YTNode { static type = 'SecondarySearchContainer'; - constructor(data) { + contents; + + constructor(data: any) { super(); this.contents = Parser.parse(data.contents); } diff --git a/src/parser/classes/SectionList.js b/src/parser/classes/SectionList.ts similarity index 86% rename from src/parser/classes/SectionList.js rename to src/parser/classes/SectionList.ts index a202f153..65342b4f 100644 --- a/src/parser/classes/SectionList.js +++ b/src/parser/classes/SectionList.ts @@ -4,7 +4,12 @@ import { YTNode } from '../helpers'; class SectionList extends YTNode { static type = 'SectionList'; - constructor(data) { + target_id; + contents; + continuation; + header; + + constructor(data: any) { super(); if (data.targetId) { this.target_id = data.targetId; diff --git a/src/parser/classes/Shelf.js b/src/parser/classes/Shelf.ts similarity index 84% rename from src/parser/classes/Shelf.js rename to src/parser/classes/Shelf.ts index 12e41b50..a1038bc4 100644 --- a/src/parser/classes/Shelf.js +++ b/src/parser/classes/Shelf.ts @@ -6,7 +6,13 @@ import { YTNode } from '../helpers'; class Shelf extends YTNode { static type = 'Shelf'; - constructor(data) { + title: Text; + endpoint; + content; + icon_type; + menu; + + constructor(data: any) { super(); this.title = new Text(data.title); diff --git a/src/parser/classes/ShowingResultsFor.js b/src/parser/classes/ShowingResultsFor.ts similarity index 72% rename from src/parser/classes/ShowingResultsFor.js rename to src/parser/classes/ShowingResultsFor.ts index 47931b99..7be99d77 100644 --- a/src/parser/classes/ShowingResultsFor.js +++ b/src/parser/classes/ShowingResultsFor.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class ShowingResultsFor extends YTNode { static type = 'ShowingResultsFor'; - constructor(data) { + corrected_query: Text; + endpoint: NavigationEndpoint; + original_query_endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.corrected_query = new Text(data.correctedQuery); this.endpoint = new NavigationEndpoint(data.correctedQueryEndpoint); diff --git a/src/parser/classes/SimpleCardTeaser.js b/src/parser/classes/SimpleCardTeaser.ts similarity index 67% rename from src/parser/classes/SimpleCardTeaser.js rename to src/parser/classes/SimpleCardTeaser.ts index 4d44ba1c..05ea5f26 100644 --- a/src/parser/classes/SimpleCardTeaser.js +++ b/src/parser/classes/SimpleCardTeaser.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class SimpleCardTeaser extends YTNode { static type = 'SimpleCardTeaser'; - constructor(data) { + message: Text; + prominent: boolean; // TODO: or string? + + constructor(data: any) { super(); this.message = new Text(data.message); this.prominent = data.prominent; diff --git a/src/parser/classes/SingleActionEmergencySupport.js b/src/parser/classes/SingleActionEmergencySupport.ts similarity index 73% rename from src/parser/classes/SingleActionEmergencySupport.js rename to src/parser/classes/SingleActionEmergencySupport.ts index 06e8a758..43dfd318 100644 --- a/src/parser/classes/SingleActionEmergencySupport.js +++ b/src/parser/classes/SingleActionEmergencySupport.ts @@ -5,7 +5,13 @@ import { YTNode } from '../helpers'; class SingleActionEmergencySupport extends YTNode { static type = 'SingleActionEmergencySupport'; - constructor(data) { + action_text: Text; + nav_text: Text; + details: Text; + icon_type: string; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.action_text = new Text(data.actionText); this.nav_text = new Text(data.navigationText); diff --git a/src/parser/classes/SingleColumnMusicWatchNextResults.js b/src/parser/classes/SingleColumnMusicWatchNextResults.ts similarity index 72% rename from src/parser/classes/SingleColumnMusicWatchNextResults.js rename to src/parser/classes/SingleColumnMusicWatchNextResults.ts index f973fbf6..e680e484 100644 --- a/src/parser/classes/SingleColumnMusicWatchNextResults.js +++ b/src/parser/classes/SingleColumnMusicWatchNextResults.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class SingleColumnMusicWatchNextResults extends YTNode { static type = 'SingleColumnMusicWatchNextResults'; - constructor(data) { + contents; + + constructor(data: any) { super(); this.contents = Parser.parse(data); } diff --git a/src/parser/classes/SingleHeroImage.js b/src/parser/classes/SingleHeroImage.ts similarity index 55% rename from src/parser/classes/SingleHeroImage.js rename to src/parser/classes/SingleHeroImage.ts index 04c44714..f17d74b3 100644 --- a/src/parser/classes/SingleHeroImage.js +++ b/src/parser/classes/SingleHeroImage.ts @@ -4,9 +4,12 @@ import { YTNode } from '../helpers'; class SingleHeroImage extends YTNode { static type = 'SingleHeroImage'; - constructor(data) { + thumbnails: Thumbnail[]; + style: string; + + constructor(data: any) { super(); - this.thumbnails = new Thumbnail(data.thumbnail).thumbnails; + this.thumbnails = Thumbnail.fromResponse(data.thumbnail); this.style = data.style; } } diff --git a/src/parser/classes/SortFilterSubMenu.js b/src/parser/classes/SortFilterSubMenu.ts similarity index 57% rename from src/parser/classes/SortFilterSubMenu.js rename to src/parser/classes/SortFilterSubMenu.ts index 6f7814fd..787e7e63 100644 --- a/src/parser/classes/SortFilterSubMenu.js +++ b/src/parser/classes/SortFilterSubMenu.ts @@ -1,17 +1,26 @@ -import { observe } from '../helpers'; import { YTNode } from '../helpers'; class SortFilterSubMenu extends YTNode { static type = 'SortFilterSubMenu'; - constructor(data) { + sub_menu_items: { + title: string; + selected: boolean; + continuation: string; + subtitle: string; + }[]; + + label: string; + + constructor(data: any) { super(); - this.sub_menu_items = observe(data.subMenuItems.map((item) => ({ + + this.sub_menu_items = data.subMenuItems.map((item: any) => ({ title: item.title, selected: item.selected, continuation: item.continuation?.reloadContinuationData.continuation, subtitle: item.subtitle - }))); + })); this.label = data.accessibility.accessibilityData.label; } diff --git a/src/parser/classes/SubFeedOption.js b/src/parser/classes/SubFeedOption.ts similarity index 74% rename from src/parser/classes/SubFeedOption.js rename to src/parser/classes/SubFeedOption.ts index 68cbbd9f..32746fcf 100644 --- a/src/parser/classes/SubFeedOption.js +++ b/src/parser/classes/SubFeedOption.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class SubFeedOption extends YTNode { static type = 'SubFeedOption'; - constructor(data) { + name: Text; + is_selected: boolean; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.name = new Text(data.name); this.is_selected = data.isSelected; diff --git a/src/parser/classes/SubFeedSelector.js b/src/parser/classes/SubFeedSelector.ts similarity index 76% rename from src/parser/classes/SubFeedSelector.js rename to src/parser/classes/SubFeedSelector.ts index 1782cd52..6c394275 100644 --- a/src/parser/classes/SubFeedSelector.js +++ b/src/parser/classes/SubFeedSelector.ts @@ -5,7 +5,10 @@ import { YTNode } from '../helpers'; class SubFeedSelector extends YTNode { static type = 'SubFeedSelector'; - constructor(data) { + title: Text; + options; + + constructor(data: any) { super(); this.title = new Text(data.title); this.options = Parser.parse(data.options); diff --git a/src/parser/classes/SubscribeButton.js b/src/parser/classes/SubscribeButton.ts similarity index 69% rename from src/parser/classes/SubscribeButton.js rename to src/parser/classes/SubscribeButton.ts index f43a323b..f8da774a 100644 --- a/src/parser/classes/SubscribeButton.js +++ b/src/parser/classes/SubscribeButton.ts @@ -6,12 +6,23 @@ import { YTNode } from '../helpers'; class SubscribeButton extends YTNode { static type = 'SubscribeButton'; - constructor(data) { + title: Text; + subscribed: boolean; + enabled: boolean; + item_type: string; + channel_id: string; + show_preferences: boolean; + subscribed_text: Text; + unsubscribed_text: Text; + notification_preference_button; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.title = new Text(data.buttonText); this.subscribed = data.subscribed; this.enabled = data.enabled; - this.type = data.type; + this.item_type = data.type; this.channel_id = data.channelId; this.show_preferences = data.showPreferences; this.subscribed_text = new Text(data.subscribedButtonText); diff --git a/src/parser/classes/SubscriptionNotificationToggleButton.js b/src/parser/classes/SubscriptionNotificationToggleButton.js deleted file mode 100644 index f26d6c8b..00000000 --- a/src/parser/classes/SubscriptionNotificationToggleButton.js +++ /dev/null @@ -1,20 +0,0 @@ -import Parser from '../index'; -import { YTNode } from '../helpers'; - -class SubscriptionNotificationToggleButton extends YTNode { - static type = 'SubscriptionNotificationToggleButton'; - - constructor(data) { - super(); - this.states = data.states.map((state) => ({ - id: state.stateId, - next_id: state.nextStateId, - state: Parser.parse(state.state) - })); - - this.current_state_id = data.currentStateId; - this.target_id = data.targetId; - } -} - -export default SubscriptionNotificationToggleButton; \ No newline at end of file diff --git a/src/parser/classes/SubscriptionNotificationToggleButton.ts b/src/parser/classes/SubscriptionNotificationToggleButton.ts new file mode 100644 index 00000000..39e3c482 --- /dev/null +++ b/src/parser/classes/SubscriptionNotificationToggleButton.ts @@ -0,0 +1,29 @@ +import Parser from '../index'; +import { YTNode } from '../helpers'; + +class SubscriptionNotificationToggleButton extends YTNode { + static type = 'SubscriptionNotificationToggleButton'; + + states: { + id: string; + next_id: string; + state: any; + }; + + current_state_id: string; + target_id: string; + + constructor(data: any) { + super(); + this.states = data.states.map((data: any) => ({ + id: data.stateId, + next_id: data.nextStateId, + state: Parser.parse(data.state) + })); + + this.current_state_id = data.currentStateId; + this.target_id = data.targetId; + } +} + +export default SubscriptionNotificationToggleButton; \ No newline at end of file diff --git a/src/parser/classes/Tabbed.js b/src/parser/classes/Tabbed.ts similarity index 65% rename from src/parser/classes/Tabbed.js rename to src/parser/classes/Tabbed.ts index 28fb1dc7..d5281db8 100644 --- a/src/parser/classes/Tabbed.js +++ b/src/parser/classes/Tabbed.ts @@ -4,8 +4,11 @@ import { YTNode } from '../helpers'; class Tabbed extends YTNode { static type = 'Tabbed'; - constructor(data) { + contents; + + constructor(data: any) { super(); + // TODO: use parseArray instead this.contents = Parser.parse(data); } } diff --git a/src/parser/classes/TextHeader.js b/src/parser/classes/TextHeader.ts similarity index 72% rename from src/parser/classes/TextHeader.js rename to src/parser/classes/TextHeader.ts index ad200640..cbe3da41 100644 --- a/src/parser/classes/TextHeader.js +++ b/src/parser/classes/TextHeader.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class TextHeader extends YTNode { static type = 'TextHeader'; - constructor(data) { + title: Text; + style: string; + + constructor(data: any) { super(); this.title = new Text(data.title); this.style = data.style; diff --git a/src/parser/classes/ThumbnailOverlayBottomPanel.js b/src/parser/classes/ThumbnailOverlayBottomPanel.ts similarity index 54% rename from src/parser/classes/ThumbnailOverlayBottomPanel.js rename to src/parser/classes/ThumbnailOverlayBottomPanel.ts index e010bf59..649ae6ca 100644 --- a/src/parser/classes/ThumbnailOverlayBottomPanel.js +++ b/src/parser/classes/ThumbnailOverlayBottomPanel.ts @@ -3,9 +3,11 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayBottomPanel extends YTNode { static type = 'ThumbnailOverlayBottomPanel'; - constructor(data) { + icon_type: string; + + constructor(data: any) { super(); - this.type = data.icon.iconType; + this.icon_type = data.icon.iconType; } } diff --git a/src/parser/classes/ThumbnailOverlayEndorsement.js b/src/parser/classes/ThumbnailOverlayEndorsement.ts similarity index 73% rename from src/parser/classes/ThumbnailOverlayEndorsement.js rename to src/parser/classes/ThumbnailOverlayEndorsement.ts index 0effcea9..fb3a39ad 100644 --- a/src/parser/classes/ThumbnailOverlayEndorsement.js +++ b/src/parser/classes/ThumbnailOverlayEndorsement.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayEndorsement extends YTNode { static type = 'ThumbnailOverlayEndorsement'; - constructor(data) { + text: string; + + constructor(data: any) { super(); this.text = new Text(data.text).toString(); } diff --git a/src/parser/classes/ThumbnailOverlayHoverText.js b/src/parser/classes/ThumbnailOverlayHoverText.ts similarity index 60% rename from src/parser/classes/ThumbnailOverlayHoverText.js rename to src/parser/classes/ThumbnailOverlayHoverText.ts index 4733f7c3..0e2746d8 100644 --- a/src/parser/classes/ThumbnailOverlayHoverText.js +++ b/src/parser/classes/ThumbnailOverlayHoverText.ts @@ -4,10 +4,13 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayHoverText extends YTNode { static type = 'ThumbnailOverlayHoverText'; - constructor(data) { + text: Text; + icon_type: string; + + constructor(data: any) { super(); this.text = new Text(data.text); - this.type = data.icon.iconType; + this.icon_type = data.icon.iconType; } } diff --git a/src/parser/classes/ThumbnailOverlayInlineUnplayable.js b/src/parser/classes/ThumbnailOverlayInlineUnplayable.ts similarity index 71% rename from src/parser/classes/ThumbnailOverlayInlineUnplayable.js rename to src/parser/classes/ThumbnailOverlayInlineUnplayable.ts index 94d35ccf..389b50f5 100644 --- a/src/parser/classes/ThumbnailOverlayInlineUnplayable.js +++ b/src/parser/classes/ThumbnailOverlayInlineUnplayable.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayInlineUnplayable extends YTNode { static type = 'ThumbnailOverlayInlineUnplayable'; - constructor(data) { + text: string; + icon_type: string; + + constructor(data: any) { super(); this.text = new Text(data.text).toString(); this.icon_type = data.icon.iconType; diff --git a/src/parser/classes/ThumbnailOverlayLoadingPreview.js b/src/parser/classes/ThumbnailOverlayLoadingPreview.ts similarity index 72% rename from src/parser/classes/ThumbnailOverlayLoadingPreview.js rename to src/parser/classes/ThumbnailOverlayLoadingPreview.ts index 882fd7ca..49c1806c 100644 --- a/src/parser/classes/ThumbnailOverlayLoadingPreview.js +++ b/src/parser/classes/ThumbnailOverlayLoadingPreview.ts @@ -4,7 +4,9 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayLoadingPreview extends YTNode { static type = 'ThumbnailOverlayLoadingPreview'; - constructor(data) { + text: Text; + + constructor(data: any) { super(); this.text = new Text(data.text); } diff --git a/src/parser/classes/ThumbnailOverlayNowPlaying.js b/src/parser/classes/ThumbnailOverlayNowPlaying.ts similarity index 58% rename from src/parser/classes/ThumbnailOverlayNowPlaying.js rename to src/parser/classes/ThumbnailOverlayNowPlaying.ts index a4c59802..434ae7b9 100644 --- a/src/parser/classes/ThumbnailOverlayNowPlaying.js +++ b/src/parser/classes/ThumbnailOverlayNowPlaying.ts @@ -4,9 +4,11 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayNowPlaying extends YTNode { static type = 'ThumbnailOverlayNowPlaying'; - constructor(data) { + text: string; + + constructor(data: any) { super(); - this.text = new Text(data.text).text; + this.text = new Text(data.text).toString(); } } diff --git a/src/parser/classes/ThumbnailOverlayPinking.js b/src/parser/classes/ThumbnailOverlayPinking.ts similarity index 67% rename from src/parser/classes/ThumbnailOverlayPinking.js rename to src/parser/classes/ThumbnailOverlayPinking.ts index 801b954d..d0675f97 100644 --- a/src/parser/classes/ThumbnailOverlayPinking.js +++ b/src/parser/classes/ThumbnailOverlayPinking.ts @@ -3,7 +3,9 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayPinking extends YTNode { static type = 'ThumbnailOverlayPinking'; - constructor(data) { + hack: boolean; + + constructor(data: any) { super(); this.hack = data.hack; } diff --git a/src/parser/classes/ThumbnailOverlayPlaybackStatus.js b/src/parser/classes/ThumbnailOverlayPlaybackStatus.ts similarity index 53% rename from src/parser/classes/ThumbnailOverlayPlaybackStatus.js rename to src/parser/classes/ThumbnailOverlayPlaybackStatus.ts index 4a82efa4..b80255bb 100644 --- a/src/parser/classes/ThumbnailOverlayPlaybackStatus.js +++ b/src/parser/classes/ThumbnailOverlayPlaybackStatus.ts @@ -4,9 +4,11 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayPlaybackStatus extends YTNode { static type = 'ThumbnailOverlayPlaybackStatus'; - constructor(data) { + text: string; + + constructor(data: any) { super(); - this.text = data.texts.map((text) => new Text(text))[0].toString(); + this.text = data.texts.map((text: any) => new Text(text))[0].toString(); } } diff --git a/src/parser/classes/ThumbnailOverlayResumePlayback.js b/src/parser/classes/ThumbnailOverlayResumePlayback.ts similarity index 62% rename from src/parser/classes/ThumbnailOverlayResumePlayback.js rename to src/parser/classes/ThumbnailOverlayResumePlayback.ts index b034ed7a..ad0c98fc 100644 --- a/src/parser/classes/ThumbnailOverlayResumePlayback.js +++ b/src/parser/classes/ThumbnailOverlayResumePlayback.ts @@ -3,7 +3,9 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayResumePlayback extends YTNode { static type = 'ThumbnailOverlayResumePlayback'; - constructor(data) { + percent_duration_watched: string; // TODO: is this a number? + + constructor(data: any) { super(); this.percent_duration_watched = data.percentDurationWatched; } diff --git a/src/parser/classes/ThumbnailOverlaySidePanel.js b/src/parser/classes/ThumbnailOverlaySidePanel.ts similarity index 60% rename from src/parser/classes/ThumbnailOverlaySidePanel.js rename to src/parser/classes/ThumbnailOverlaySidePanel.ts index 8679429c..9338aecf 100644 --- a/src/parser/classes/ThumbnailOverlaySidePanel.js +++ b/src/parser/classes/ThumbnailOverlaySidePanel.ts @@ -4,10 +4,13 @@ import { YTNode } from '../helpers'; class ThumbnailOverlaySidePanel extends YTNode { static type = 'ThumbnailOverlaySidePanel'; - constructor(data) { + text: Text; + icon_type: string; + + constructor(data: any) { super(); this.text = new Text(data.text); - this.type = data.icon.iconType; + this.icon_type = data.icon.iconType; } } diff --git a/src/parser/classes/ThumbnailOverlayTimeStatus.js b/src/parser/classes/ThumbnailOverlayTimeStatus.ts similarity index 58% rename from src/parser/classes/ThumbnailOverlayTimeStatus.js rename to src/parser/classes/ThumbnailOverlayTimeStatus.ts index 3df4c92e..887e076f 100644 --- a/src/parser/classes/ThumbnailOverlayTimeStatus.js +++ b/src/parser/classes/ThumbnailOverlayTimeStatus.ts @@ -4,9 +4,11 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayTimeStatus extends YTNode { static type = 'ThumbnailOverlayTimeStatus'; - constructor(data) { + text: string; + + constructor(data: any) { super(); - this.text = new Text(data.text).text; + this.text = new Text(data.text).toString(); } } diff --git a/src/parser/classes/ThumbnailOverlayToggleButton.js b/src/parser/classes/ThumbnailOverlayToggleButton.ts similarity index 67% rename from src/parser/classes/ThumbnailOverlayToggleButton.js rename to src/parser/classes/ThumbnailOverlayToggleButton.ts index ac2a962a..80a59aba 100644 --- a/src/parser/classes/ThumbnailOverlayToggleButton.js +++ b/src/parser/classes/ThumbnailOverlayToggleButton.ts @@ -4,7 +4,22 @@ import { YTNode } from '../helpers'; class ThumbnailOverlayToggleButton extends YTNode { static type = 'ThumbnailOverlayToggleButton'; - constructor(data) { + is_toggled: boolean | null; + + icon_type: { + toggled: string; + untoggled: string; + }; + + tooltip: { + toggled: string; + untoggled: string; + }; + + toggled_endpoint: NavigationEndpoint; + untoggled_endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.is_toggled = data.isToggled || null; diff --git a/src/parser/classes/ToggleButton.js b/src/parser/classes/ToggleButton.ts similarity index 70% rename from src/parser/classes/ToggleButton.js rename to src/parser/classes/ToggleButton.ts index 4dae2282..51c21a60 100644 --- a/src/parser/classes/ToggleButton.js +++ b/src/parser/classes/ToggleButton.ts @@ -5,7 +5,23 @@ import { YTNode } from '../helpers'; class ToggleButton extends YTNode { static type = 'ToggleButton'; - constructor(data) { + text: Text; + toggled_text: Text; + tooltip: string; + toggled_tooltip: string; + is_toggled: boolean; + is_disabled: boolean; + icon_type: string; + + like_count; + short_like_count; + + endpoint: NavigationEndpoint; + toggled_endpoint: NavigationEndpoint; + button_id: string | null; + target_id: string | null; + + constructor(data: any) { super(); this.text = new Text(data.defaultText); this.toggled_text = new Text(data.toggledText); @@ -16,8 +32,8 @@ class ToggleButton extends YTNode { this.icon_type = data.defaultIcon.iconType; const acc_label = - data?.defaultText?.accessibility?.accessibilityData.label || - data?.accessibilityData?.accessibilityData.label || + data?.defaultText?.accessibility?.accessibilityData?.label || + data?.accessibilityData?.accessibilityData?.label || data?.accessibility?.label; if (this.icon_type == 'LIKE') { @@ -35,4 +51,5 @@ class ToggleButton extends YTNode { this.target_id = data.targetId || null; } } -export default ToggleButton; + +export default ToggleButton; \ No newline at end of file diff --git a/src/parser/classes/ToggleMenuServiceItem.js b/src/parser/classes/ToggleMenuServiceItem.ts similarity index 73% rename from src/parser/classes/ToggleMenuServiceItem.js rename to src/parser/classes/ToggleMenuServiceItem.ts index 5b0d57c8..53a8994a 100644 --- a/src/parser/classes/ToggleMenuServiceItem.js +++ b/src/parser/classes/ToggleMenuServiceItem.ts @@ -5,7 +5,13 @@ import { YTNode } from '../helpers'; class ToggleMenuServiceItem extends YTNode { static type = 'ToggleMenuServiceItem'; - constructor(data) { + text: Text; + toggled_text: Text; + icon_type: string; + toggled_icon_type: string; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.text = new Text(data.defaultText); this.toggled_text = new Text(data.toggledText); diff --git a/src/parser/classes/Tooltip.js b/src/parser/classes/Tooltip.ts similarity index 64% rename from src/parser/classes/Tooltip.js rename to src/parser/classes/Tooltip.ts index e5f0869b..9c9ebca1 100644 --- a/src/parser/classes/Tooltip.js +++ b/src/parser/classes/Tooltip.ts @@ -5,13 +5,26 @@ import { YTNode } from '../helpers'; class Tooltip extends YTNode { static type = 'Tooltip'; - constructor(data) { + promo_config: { + promo_id: string; + impression_endpoints: NavigationEndpoint[]; + accept: NavigationEndpoint; + dismiss: NavigationEndpoint; + }; + + target_id: string; + details: Text; + suggested_position: string; + dismiss_stratedy: string; + dwell_time_ms: number; + + constructor(data: any) { super(); this.promo_config = { promo_id: data.promoConfig.promoId, impression_endpoints: data.promoConfig.impressionEndpoints - .map((endpoint) => new NavigationEndpoint(endpoint)), + .map((endpoint: any) => new NavigationEndpoint(endpoint)), accept: new NavigationEndpoint(data.promoConfig.acceptCommand), dismiss: new NavigationEndpoint(data.promoConfig.dismissCommand) }; diff --git a/src/parser/classes/TwoColumnBrowseResults.js b/src/parser/classes/TwoColumnBrowseResults.ts similarity index 74% rename from src/parser/classes/TwoColumnBrowseResults.js rename to src/parser/classes/TwoColumnBrowseResults.ts index bd0f8057..88ca9084 100644 --- a/src/parser/classes/TwoColumnBrowseResults.js +++ b/src/parser/classes/TwoColumnBrowseResults.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class TwoColumnBrowseResults extends YTNode { static type = 'TwoColumnBrowseResults'; - constructor(data) { + tabs; + secondary_contents; + + constructor(data: any) { super(); this.tabs = Parser.parse(data.tabs); this.secondary_contents = Parser.parse(data.secondaryContents); diff --git a/src/parser/classes/TwoColumnSearchResults.js b/src/parser/classes/TwoColumnSearchResults.ts similarity index 74% rename from src/parser/classes/TwoColumnSearchResults.js rename to src/parser/classes/TwoColumnSearchResults.ts index 8605aeb0..6d0ab4b5 100644 --- a/src/parser/classes/TwoColumnSearchResults.js +++ b/src/parser/classes/TwoColumnSearchResults.ts @@ -4,7 +4,10 @@ import { YTNode } from '../helpers'; class TwoColumnSearchResults extends YTNode { static type = 'TwoColumnSearchResults'; - constructor(data) { + primary_contents; + secondary_contents; + + constructor(data: any) { super(); this.primary_contents = Parser.parse(data.primaryContents); this.secondary_contents = Parser.parse(data.secondaryContents); diff --git a/src/parser/classes/TwoColumnWatchNextResults.js b/src/parser/classes/TwoColumnWatchNextResults.ts similarity index 77% rename from src/parser/classes/TwoColumnWatchNextResults.js rename to src/parser/classes/TwoColumnWatchNextResults.ts index cd0936c5..10a5c4bf 100644 --- a/src/parser/classes/TwoColumnWatchNextResults.js +++ b/src/parser/classes/TwoColumnWatchNextResults.ts @@ -4,7 +4,11 @@ import { YTNode } from '../helpers'; class TwoColumnWatchNextResults extends YTNode { static type = 'TwoColumnWatchNextResults'; - constructor(data) { + results; + secondary_results; + conversation_bar; + + constructor(data: any) { super(); this.results = Parser.parse(data.results?.results.contents, true); this.secondary_results = Parser.parse(data.secondaryResults?.secondaryResults.results, true); diff --git a/src/parser/classes/UniversalWatchCard.js b/src/parser/classes/UniversalWatchCard.ts similarity index 68% rename from src/parser/classes/UniversalWatchCard.js rename to src/parser/classes/UniversalWatchCard.ts index 74f5ef67..0a7e1842 100644 --- a/src/parser/classes/UniversalWatchCard.js +++ b/src/parser/classes/UniversalWatchCard.ts @@ -4,8 +4,13 @@ import { YTNode } from '../helpers'; class UniversalWatchCard extends YTNode { static type = 'UniversalWatchCard'; - constructor(data) { + header; + call_to_action; + sections; + + constructor(data: any) { super(); + // TODO: use parseItem / parseArray for these this.header = Parser.parse(data.header); this.call_to_action = Parser.parse(data.callToAction); this.sections = Parser.parse(data.sections); diff --git a/src/parser/classes/VerticalList.js b/src/parser/classes/VerticalList.ts similarity index 75% rename from src/parser/classes/VerticalList.js rename to src/parser/classes/VerticalList.ts index 40b0da4b..ed87c26d 100644 --- a/src/parser/classes/VerticalList.js +++ b/src/parser/classes/VerticalList.ts @@ -5,7 +5,11 @@ import { YTNode } from '../helpers'; class VerticalList extends YTNode { static type = 'VerticalList'; - constructor(data) { + items; + collapsed_item_count: string; // Number? + collapsed_state_button_text: Text; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); this.collapsed_item_count = data.collapsedItemCount; diff --git a/src/parser/classes/VerticalWatchCardList.js b/src/parser/classes/VerticalWatchCardList.ts similarity index 76% rename from src/parser/classes/VerticalWatchCardList.js rename to src/parser/classes/VerticalWatchCardList.ts index e6cfccf8..99028d23 100644 --- a/src/parser/classes/VerticalWatchCardList.js +++ b/src/parser/classes/VerticalWatchCardList.ts @@ -6,7 +6,12 @@ import { YTNode } from '../helpers'; class VerticalWatchCardList extends YTNode { static type = 'VerticalWatchCardList'; - constructor(data) { + items; + contents; + view_all_text: Text; + view_all_endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); this.contents = this.items; // XXX: alias for consistency diff --git a/src/parser/classes/Video.js b/src/parser/classes/Video.ts similarity index 69% rename from src/parser/classes/Video.js rename to src/parser/classes/Video.ts index 2486cd9d..3022573c 100644 --- a/src/parser/classes/Video.js +++ b/src/parser/classes/Video.ts @@ -9,18 +9,45 @@ import { YTNode } from '../helpers'; class Video extends YTNode { static type = 'Video'; - constructor(data) { + id: string; + title: Text; + description_snippet: Text | null; + snippets: { + text: Text; + hover_text: Text; + }[]; + + thumbnails: Thumbnail[]; + thumbnail_overlays; + rich_thumbnail; + author: Author; + endpoint: NavigationEndpoint; + published: Text; + view_count: Text; + short_view_count: Text; + upcoming; + + duration: { + text: string; + seconds: number; + }; + + show_action_menu: boolean; + is_watched: boolean; + menu; + + constructor(data: any) { super(); const overlay_time_status = data.thumbnailOverlays - .find((overlay) => overlay.thumbnailOverlayTimeStatusRenderer) + .find((overlay: any) => overlay.thumbnailOverlayTimeStatusRenderer) ?.thumbnailOverlayTimeStatusRenderer.text || 'N/A'; this.id = data.videoId; this.title = new Text(data.title); - this.description_snippet = data.descriptionSnippet ? new Text(data.descriptionSnippet, '') : null; + this.description_snippet = data.descriptionSnippet ? new Text(data.descriptionSnippet) : null; - this.snippets = data.detailedMetadataSnippets?.map((snippet) => ({ + this.snippets = data.detailedMetadataSnippets?.map((snippet: any) => ({ text: new Text(snippet.snippetText), hover_text: new Text(snippet.snippetHoverText) })) || []; @@ -31,8 +58,8 @@ class Video extends YTNode { this.author = new Author(data.ownerText, data.ownerBadges, data.channelThumbnailSupportedRenderers?.channelThumbnailWithLinkRenderer?.thumbnail); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.published = new Text(data.publishedTimeText); - this.view_count_text = new Text(data.viewCountText); - this.short_view_count_text = new Text(data.shortViewCountText); + this.view_count = new Text(data.viewCountText); + this.short_view_count = new Text(data.shortViewCountText); const upcoming = data.upcomingEventData && Number(`${data.upcomingEventData.startTime}000`); if (upcoming) { @@ -49,41 +76,29 @@ class Video extends YTNode { this.menu = Parser.parse(data.menu); } - /** - * @returns {string} - */ - get description() { + get description(): string { if (this.snippets.length > 0) { return this.snippets.map((snip) => snip.text.toString()).join(''); } return this.description_snippet?.toString() || ''; } - /** - * @type {boolean} - */ - get is_live() { + /* + Get is_live() { return this.badges.some((badge) => badge.style === 'BADGE_STYLE_TYPE_LIVE_NOW'); } + */ - /** - * @type {boolean} - */ - get is_upcoming() { + get is_upcoming(): boolean | undefined { return this.upcoming && this.upcoming > new Date(); } - /** - * @type {boolean} - */ - get has_captions() { + /* + Get has_captions() { return this.badges.some((badge) => badge.label === 'CC'); - } + }*/ - /** - * @type {Thumbnail | undefined} - */ - get best_thumbnail() { + get best_thumbnail(): Thumbnail | undefined{ return this.thumbnails[0]; } } diff --git a/src/parser/classes/VideoInfoCardContent.js b/src/parser/classes/VideoInfoCardContent.ts similarity index 74% rename from src/parser/classes/VideoInfoCardContent.js rename to src/parser/classes/VideoInfoCardContent.ts index 00d1ea83..e0b44228 100644 --- a/src/parser/classes/VideoInfoCardContent.js +++ b/src/parser/classes/VideoInfoCardContent.ts @@ -6,7 +6,14 @@ import { YTNode } from '../helpers'; class VideoInfoCardContent extends YTNode { static type = 'VideoInfoCardContent'; - constructor(data) { + title: Text; + channel_name: Text; + view_count: Text; + video_thumbnails: Thumbnail[]; + duration: Text; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.title = new Text(data.videoTitle); this.channel_name = new Text(data.channelName); diff --git a/src/parser/classes/VideoOwner.js b/src/parser/classes/VideoOwner.ts similarity index 75% rename from src/parser/classes/VideoOwner.js rename to src/parser/classes/VideoOwner.ts index 0d99d1c5..509dc6f4 100644 --- a/src/parser/classes/VideoOwner.js +++ b/src/parser/classes/VideoOwner.ts @@ -5,8 +5,13 @@ import { YTNode } from '../helpers'; class VideoOwner extends YTNode { static type = 'VideoOwner'; - constructor(data) { + subscription_button; + subscriber_count: Text; + author: Author; + + constructor(data: any) { super(); + // TODO: check this this.subscription_button = data.subscriptionButton || null; this.subscriber_count = new Text(data.subscriberCountText); diff --git a/src/parser/classes/VideoPrimaryInfo.ts b/src/parser/classes/VideoPrimaryInfo.ts index 83d50009..9498f132 100644 --- a/src/parser/classes/VideoPrimaryInfo.ts +++ b/src/parser/classes/VideoPrimaryInfo.ts @@ -6,11 +6,11 @@ import Menu from './menus/Menu'; class VideoPrimaryInfo extends YTNode { static type = 'VideoPrimaryInfo'; - title; - super_title_link; - view_count; - short_view_count; - published; + title: Text; + super_title_link: Text; + view_count: Text; + short_view_count: Text; + published: Text; menu; constructor(data: any) { diff --git a/src/parser/classes/VideoSecondaryInfo.js b/src/parser/classes/VideoSecondaryInfo.ts similarity index 61% rename from src/parser/classes/VideoSecondaryInfo.js rename to src/parser/classes/VideoSecondaryInfo.ts index 0d472830..953ad211 100644 --- a/src/parser/classes/VideoSecondaryInfo.js +++ b/src/parser/classes/VideoSecondaryInfo.ts @@ -7,12 +7,21 @@ import MetadataRowContainer from './MetadataRowContainer'; class VideoSecondaryInfo extends YTNode { static type = 'VideoSecondaryInfo'; - constructor(data) { + owner; // TODO: VideoOwner? + description: Text; + subscribe_button; + metadata: MetadataRowContainer | null; + show_more_text: string; + show_less_text: string; + default_expanded: string; + description_collapsed_lines: string; + + constructor(data: any) { super(); this.owner = Parser.parse(data.owner); this.description = new Text(data.description); this.subscribe_button = Parser.parse(data.subscribeButton); - this.metadata = Parser.parseItem(data.metadataRowContainer, MetadataRowContainer); + this.metadata = Parser.parseItem(data.metadataRowContainer, MetadataRowContainer); this.show_more_text = data.showMoreText; this.show_less_text = data.showLessText; this.default_expanded = data.defaultExpanded; diff --git a/src/parser/classes/WatchCardCompactVideo.js b/src/parser/classes/WatchCardCompactVideo.ts similarity index 73% rename from src/parser/classes/WatchCardCompactVideo.js rename to src/parser/classes/WatchCardCompactVideo.ts index 21aa42c6..275c1bab 100644 --- a/src/parser/classes/WatchCardCompactVideo.js +++ b/src/parser/classes/WatchCardCompactVideo.ts @@ -5,7 +5,17 @@ import { YTNode } from '../helpers'; class WatchCardCompactVideo extends YTNode { static type = 'WatchCardCompactVideo'; - constructor(data) { + title: Text; + subtitle: Text; + + duration: { + text: string; + seconds: number; + }; + + style: string; + + constructor(data: any) { super(); this.title = new Text(data.title); this.subtitle = new Text(data.subtitle); diff --git a/src/parser/classes/WatchCardHeroVideo.js b/src/parser/classes/WatchCardHeroVideo.ts similarity index 76% rename from src/parser/classes/WatchCardHeroVideo.js rename to src/parser/classes/WatchCardHeroVideo.ts index c4d9c2f1..024d173c 100644 --- a/src/parser/classes/WatchCardHeroVideo.js +++ b/src/parser/classes/WatchCardHeroVideo.ts @@ -5,7 +5,12 @@ import { YTNode } from '../helpers'; class WatchCardHeroVideo extends YTNode { static type = 'WatchCardHeroVideo'; - constructor(data) { + endpoint: NavigationEndpoint; + call_to_action_button; + hero_image; + label: string; + + constructor(data: any) { super(); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.call_to_action_button = Parser.parse(data.callToActionButton); diff --git a/src/parser/classes/WatchCardRichHeader.js b/src/parser/classes/WatchCardRichHeader.ts similarity index 71% rename from src/parser/classes/WatchCardRichHeader.js rename to src/parser/classes/WatchCardRichHeader.ts index 4d23a642..5c5b5455 100644 --- a/src/parser/classes/WatchCardRichHeader.js +++ b/src/parser/classes/WatchCardRichHeader.ts @@ -6,13 +6,19 @@ import { YTNode } from '../helpers'; class WatchCardRichHeader extends YTNode { static type = 'WatchCardRichHeader'; - constructor(data) { + title: Text; + title_endpoint: NavigationEndpoint; + subtitle: Text; + author: Author; + style: string; + + constructor(data: any) { super(); this.title = new Text(data.title); this.title_endpoint = new NavigationEndpoint(data.titleNavigationEndpoint); this.subtitle = new Text(data.subtitle); this.author = new Author(data, data.titleBadge ? [ data.titleBadge ] : null, data.avatar); - this.author.name = this.title; + this.author.name = this.title.toString(); this.style = data.style; } } diff --git a/src/parser/classes/WatchCardSectionSequence.js b/src/parser/classes/WatchCardSectionSequence.ts similarity index 74% rename from src/parser/classes/WatchCardSectionSequence.js rename to src/parser/classes/WatchCardSectionSequence.ts index 26d4de39..d604fc0f 100644 --- a/src/parser/classes/WatchCardSectionSequence.js +++ b/src/parser/classes/WatchCardSectionSequence.ts @@ -3,7 +3,10 @@ import { YTNode } from '../helpers'; class WatchCardSectionSequence extends YTNode { static type = 'WatchCardSectionSequence'; - constructor(data) { + + lists; + + constructor(data: any) { super(); this.lists = Parser.parse(data.lists); } diff --git a/src/parser/classes/WatchNextEndScreen.js b/src/parser/classes/WatchNextEndScreen.ts similarity index 76% rename from src/parser/classes/WatchNextEndScreen.js rename to src/parser/classes/WatchNextEndScreen.ts index 17673683..f89dc5e6 100644 --- a/src/parser/classes/WatchNextEndScreen.js +++ b/src/parser/classes/WatchNextEndScreen.ts @@ -5,7 +5,10 @@ import { YTNode } from '../helpers'; class WatchNextEndScreen extends YTNode { static type = 'WatchNextEndScreen'; - constructor(data) { + results; + title: string; + + constructor(data: any) { super(); this.results = Parser.parse(data.results); this.title = new Text(data.title).toString(); diff --git a/src/parser/classes/WatchNextTabbedResults.js b/src/parser/classes/WatchNextTabbedResults.ts similarity index 74% rename from src/parser/classes/WatchNextTabbedResults.js rename to src/parser/classes/WatchNextTabbedResults.ts index 8b5f5be1..21c74a02 100644 --- a/src/parser/classes/WatchNextTabbedResults.js +++ b/src/parser/classes/WatchNextTabbedResults.ts @@ -3,7 +3,7 @@ import TwoColumnBrowseResults from './TwoColumnBrowseResults'; class WatchNextTabbedResults extends TwoColumnBrowseResults { static type = 'WatchNextTabbedResults'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/actions/AppendContinuationItemsAction.js b/src/parser/classes/actions/AppendContinuationItemsAction.ts similarity index 73% rename from src/parser/classes/actions/AppendContinuationItemsAction.js rename to src/parser/classes/actions/AppendContinuationItemsAction.ts index 15947ea0..360ffe41 100644 --- a/src/parser/classes/actions/AppendContinuationItemsAction.js +++ b/src/parser/classes/actions/AppendContinuationItemsAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class AppendContinuationItemsAction extends YTNode { static type = 'AppendContinuationItemsAction'; - constructor(data) { + items; + target: string; + + constructor(data: any) { super(); this.items = Parser.parse(data.continuationItems); this.target = data.target; diff --git a/src/parser/classes/actions/OpenPopupAction.js b/src/parser/classes/actions/OpenPopupAction.ts similarity index 75% rename from src/parser/classes/actions/OpenPopupAction.js rename to src/parser/classes/actions/OpenPopupAction.ts index 9c66dfc4..e4a07077 100644 --- a/src/parser/classes/actions/OpenPopupAction.js +++ b/src/parser/classes/actions/OpenPopupAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class OpenPopupAction extends YTNode { static type = 'OpenPopupAction'; - constructor(data) { + popup; + popup_type; + + constructor(data: any) { super(); this.popup = Parser.parse(data.popup); this.popup_type = data.popupType; diff --git a/src/parser/classes/comments/AuthorCommentBadge.js b/src/parser/classes/comments/AuthorCommentBadge.ts similarity index 79% rename from src/parser/classes/comments/AuthorCommentBadge.js rename to src/parser/classes/comments/AuthorCommentBadge.ts index d1d615ca..770f136b 100644 --- a/src/parser/classes/comments/AuthorCommentBadge.js +++ b/src/parser/classes/comments/AuthorCommentBadge.ts @@ -5,7 +5,11 @@ class AuthorCommentBadge extends YTNode { #data; - constructor(data) { + icon_type: string | null; + tooltip: string; + style?: string; + + constructor(data: any) { super(); this.icon_type = data.icon?.iconType || null; diff --git a/src/parser/classes/comments/Comment.js b/src/parser/classes/comments/Comment.ts similarity index 55% rename from src/parser/classes/comments/Comment.js rename to src/parser/classes/comments/Comment.ts index 76bdb044..668a458f 100644 --- a/src/parser/classes/comments/Comment.js +++ b/src/parser/classes/comments/Comment.ts @@ -2,22 +2,50 @@ import Parser from '../../index'; import Text from '../misc/Text'; import Thumbnail from '../misc/Thumbnail'; import Author from '../misc/Author'; +import ToggleButton from '../ToggleButton'; +import CommentReplyDialog from './CommentReplyDialog'; +import CommentActionButtons from './CommentActionButtons'; +import AuthorCommentBadge from './AuthorCommentBadge'; + import Proto from '../../../proto/index'; +import Actions from '../../../core/Actions'; import { InnertubeError } from '../../../utils/Utils'; -import { YTNode } from '../../helpers'; + +import { YTNode, SuperParsedResult } from '../../helpers'; class Comment extends YTNode { static type = 'Comment'; - #actions; + #actions?: Actions; - constructor(data) { + content: Text; + published: Text; + author_is_channel_owner: boolean; + current_user_reply_thumbnail: Thumbnail[]; + author_badge; + author: Author; + action_menu; + action_buttons; + comment_id: string; + vote_status: string; + + vote_count: { + text: string; + short_text: string; + }; + + reply_count: number; + is_liked: boolean; + is_disliked: boolean; + is_pinned: boolean; + + constructor(data: any) { super(); this.content = new Text(data.contentText); this.published = new Text(data.publishedTimeText); this.author_is_channel_owner = data.authorIsChannelOwner; this.current_user_reply_thumbnail = Thumbnail.fromResponse(data.currentUserReplyThumbnail); - this.author_badge = Parser.parse(data.authorCommentBadge); + this.author_badge = Parser.parseItem(data.authorCommentBadge, AuthorCommentBadge); this.author = new Author({ ...data.authorText, @@ -37,22 +65,19 @@ class Comment extends YTNode { }; this.reply_count = data.replyCount || 0; - this.is_liked = this.action_buttons.item().like_button.item().is_toggled; - this.is_disliked = this.action_buttons.item().dislike_button.item().is_toggled; + this.is_liked = this.action_buttons.item().as(CommentActionButtons).like_button.item().as(ToggleButton).is_toggled; + this.is_disliked = this.action_buttons.item().as(CommentActionButtons).dislike_button.item().as(ToggleButton).is_toggled; this.is_pinned = !!data.pinnedCommentBadge; } - /** - * API response. - * @typedef {{ success: boolean, status_code: number, data: object }} Response - */ - /** * Likes the comment. - * @returns {Promise.} */ async like() { - const button = this.action_buttons.item().like_button.item(); + if (!this.#actions) + throw new InnertubeError('An active caller must be provide to perform this operation.'); + + const button = this.action_buttons.item().as(CommentActionButtons).like_button.item().as(ToggleButton); if (button.is_toggled) throw new InnertubeError('This comment is already liked', { comment_id: this.comment_id }); @@ -63,10 +88,12 @@ class Comment extends YTNode { } /** * Dislikes the comment. - * @returns {Promise.} */ async dislike() { - const button = this.action_buttons.item().dislike_button.item(); + if (!this.#actions) + throw new InnertubeError('An active caller must be provide to perform this operation.'); + + const button = this.action_buttons.item().as(CommentActionButtons).dislike_button.item().as(ToggleButton); if (button.is_toggled) throw new InnertubeError('This comment is already disliked', { comment_id: this.comment_id }); @@ -78,15 +105,21 @@ class Comment extends YTNode { /** * Creates a reply to the comment. - * @param {string} text - * @returns {Promise.} */ - async reply(text) { - if (!this.action_buttons.item().reply_button) + async reply(text: string) { + if (!this.#actions) + throw new InnertubeError('An active caller must be provide to perform this operation.'); + + if (!this.action_buttons.item().as(CommentActionButtons).reply_button) throw new InnertubeError('Cannot reply to another reply. Try mentioning the user instead.', { comment_id: this.comment_id }); - const button = this.action_buttons.item().reply_button.item(); - const dialog_button = button.endpoint.dialog.item().reply_button.item(); + const button = this.action_buttons.item().as(CommentActionButtons).reply_button.item().as(ToggleButton); + + if (!button.endpoint.dialog) + throw new InnertubeError('Reply button endpoint did not have a dialog.'); + + const dialog = button.endpoint.dialog as SuperParsedResult; + const dialog_button = dialog.item().as(CommentReplyDialog).reply_button.item().as(ToggleButton); const payload = { params: { @@ -101,9 +134,12 @@ class Comment extends YTNode { /** * Translates the comment to the given language. - * @param {string} target_language + * @param target_language - Ex; en, ja */ - async translate(target_language) { + async translate(target_language: string) { + if (!this.#actions) + throw new InnertubeError('An active caller must be provide to perform this operation.'); + // Emojis must be removed otherwise InnerTube throws a 400 status code at us. const text = this.content.toString().replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu, ''); @@ -123,10 +159,7 @@ class Comment extends YTNode { return { ...response, content }; } - /** - * @param {import('../../../../core/Actions').default} actions - */ - setActions(actions) { + setActions(actions: Actions | undefined) { this.#actions = actions; } } diff --git a/src/parser/classes/comments/CommentActionButtons.js b/src/parser/classes/comments/CommentActionButtons.ts similarity index 75% rename from src/parser/classes/comments/CommentActionButtons.js rename to src/parser/classes/comments/CommentActionButtons.ts index 5752b8fa..43173fe4 100644 --- a/src/parser/classes/comments/CommentActionButtons.js +++ b/src/parser/classes/comments/CommentActionButtons.ts @@ -4,7 +4,11 @@ import { YTNode } from '../../helpers'; class CommentActionButtons extends YTNode { static type = 'CommentActionButtons'; - constructor(data) { + like_button; + dislike_button; + reply_button; + + constructor(data: any) { super(); this.like_button = Parser.parse(data.likeButton); this.dislike_button = Parser.parse(data.dislikeButton); diff --git a/src/parser/classes/comments/CommentReplies.js b/src/parser/classes/comments/CommentReplies.ts similarity index 76% rename from src/parser/classes/comments/CommentReplies.js rename to src/parser/classes/comments/CommentReplies.ts index 06a5db97..671a99c7 100644 --- a/src/parser/classes/comments/CommentReplies.js +++ b/src/parser/classes/comments/CommentReplies.ts @@ -4,7 +4,11 @@ import { YTNode } from '../../helpers'; class CommentReplies extends YTNode { static type = 'CommentReplies'; - constructor(data) { + contents; + view_replies; + hide_replies; + + constructor(data: any) { super(); this.contents = Parser.parse(data.contents); this.view_replies = Parser.parse(data.viewReplies); diff --git a/src/parser/classes/comments/CommentReplyDialog.js b/src/parser/classes/comments/CommentReplyDialog.ts similarity index 78% rename from src/parser/classes/comments/CommentReplyDialog.js rename to src/parser/classes/comments/CommentReplyDialog.ts index d1a86587..2c23e50e 100644 --- a/src/parser/classes/comments/CommentReplyDialog.js +++ b/src/parser/classes/comments/CommentReplyDialog.ts @@ -6,7 +6,13 @@ import { YTNode } from '../../helpers'; class CommentReplyDialog extends YTNode { static type = 'CommentReplyDialog'; - constructor(data) { + reply_button; + cancel_button; + author_thumbnail; + placeholder; + error_message; + + constructor(data: any) { super(); this.reply_button = Parser.parse(data.replyButton); this.cancel_button = Parser.parse(data.cancelButton); diff --git a/src/parser/classes/comments/CommentSimplebox.js b/src/parser/classes/comments/CommentSimplebox.ts similarity index 76% rename from src/parser/classes/comments/CommentSimplebox.js rename to src/parser/classes/comments/CommentSimplebox.ts index 2e0e7d9a..794ae646 100644 --- a/src/parser/classes/comments/CommentSimplebox.js +++ b/src/parser/classes/comments/CommentSimplebox.ts @@ -6,7 +6,13 @@ import { YTNode } from '../../helpers'; class CommentSimplebox extends YTNode { static type = 'CommentSimplebox'; - constructor(data) { + submit_button; + cancel_button; + author_thumbnails: Thumbnail[]; + placeholder: Text; + avatar_size; + + constructor(data: any) { super(); this.submit_button = Parser.parse(data.submitButton); this.cancel_button = Parser.parse(data.cancelButton); diff --git a/src/parser/classes/comments/CommentsEntryPointHeader.js b/src/parser/classes/comments/CommentsEntryPointHeader.ts similarity index 77% rename from src/parser/classes/comments/CommentsEntryPointHeader.js rename to src/parser/classes/comments/CommentsEntryPointHeader.ts index d0eb7804..ca874093 100644 --- a/src/parser/classes/comments/CommentsEntryPointHeader.js +++ b/src/parser/classes/comments/CommentsEntryPointHeader.ts @@ -5,7 +5,13 @@ import { YTNode } from '../../helpers'; class CommentsEntryPointHeader extends YTNode { static type = 'CommentsEntryPointHeader'; - constructor(data) { + header; + comment_count; + teaser_avatar; + teaser_content; + simplebox_placeholder; + + constructor(data: any) { super(); this.header = new Text(data.headerText); this.comment_count = new Text(data.commentCount); diff --git a/src/parser/classes/comments/CommentsHeader.js b/src/parser/classes/comments/CommentsHeader.ts similarity index 65% rename from src/parser/classes/comments/CommentsHeader.js rename to src/parser/classes/comments/CommentsHeader.ts index 3c557b85..f1180427 100644 --- a/src/parser/classes/comments/CommentsHeader.js +++ b/src/parser/classes/comments/CommentsHeader.ts @@ -6,7 +6,21 @@ import { YTNode } from '../../helpers'; class CommentsHeader extends YTNode { static type = 'CommentsHeader'; - constructor(data) { + title: Text; + count: Text; + comments_count: Text; + create_renderer; + sort_menu; + + custom_emojis: { + emoji_id: string; + shortcuts: string[]; + search_terms: string[]; + image: Thumbnail[]; + is_custom_emoji: boolean; + }[] | null; + + constructor(data: any) { super(); this.title = new Text(data.titleText); this.count = new Text(data.countText); @@ -14,7 +28,7 @@ class CommentsHeader extends YTNode { this.create_renderer = Parser.parseItem(data.createRenderer); this.sort_menu = Parser.parse(data.sortMenu); - this.custom_emojis = data.customEmojis?.map((emoji) => ({ + this.custom_emojis = data.customEmojis?.map((emoji: any) => ({ emoji_id: emoji.emojiId, shortcuts: emoji.shortcuts, search_terms: emoji.searchTerms, diff --git a/src/parser/classes/livechat/AddBannerToLiveChatCommand.js b/src/parser/classes/livechat/AddBannerToLiveChatCommand.ts similarity index 59% rename from src/parser/classes/livechat/AddBannerToLiveChatCommand.js rename to src/parser/classes/livechat/AddBannerToLiveChatCommand.ts index d2455945..ce8c9142 100644 --- a/src/parser/classes/livechat/AddBannerToLiveChatCommand.js +++ b/src/parser/classes/livechat/AddBannerToLiveChatCommand.ts @@ -4,9 +4,11 @@ import { YTNode } from '../../helpers'; class AddBannerToLiveChatCommand extends YTNode { static type = 'AddBannerToLiveChatCommand'; - constructor(data) { + banner; + + constructor(data: any) { super(); - return Parser.parse(data.bannerRenderer); + this.banner = Parser.parse(data.bannerRenderer); } } diff --git a/src/parser/classes/livechat/AddChatItemAction.js b/src/parser/classes/livechat/AddChatItemAction.ts similarity index 73% rename from src/parser/classes/livechat/AddChatItemAction.js rename to src/parser/classes/livechat/AddChatItemAction.ts index b1e09d75..957d8d3f 100644 --- a/src/parser/classes/livechat/AddChatItemAction.js +++ b/src/parser/classes/livechat/AddChatItemAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class AddChatItemAction extends YTNode { static type = 'AddChatItemAction'; - constructor(data) { + item; + client_id: string | null; + + constructor(data: any) { super(); this.item = Parser.parseItem(data.item); this.client_id = data.clientId || null; diff --git a/src/parser/classes/livechat/AddLiveChatTickerItemAction.js b/src/parser/classes/livechat/AddLiveChatTickerItemAction.ts similarity index 74% rename from src/parser/classes/livechat/AddLiveChatTickerItemAction.js rename to src/parser/classes/livechat/AddLiveChatTickerItemAction.ts index 70264d76..76765d56 100644 --- a/src/parser/classes/livechat/AddLiveChatTickerItemAction.js +++ b/src/parser/classes/livechat/AddLiveChatTickerItemAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class AddLiveChatTickerItemAction extends YTNode { static type = 'AddLiveChatTickerItemAction'; - constructor(data) { + item; + duration_sec; + + constructor(data: any) { super(); this.item = Parser.parseItem(data.item); this.duration_sec = data.durationSec; diff --git a/src/parser/classes/livechat/LiveChatActionPanel.js b/src/parser/classes/livechat/LiveChatActionPanel.ts similarity index 72% rename from src/parser/classes/livechat/LiveChatActionPanel.js rename to src/parser/classes/livechat/LiveChatActionPanel.ts index 686fbea3..3cd28082 100644 --- a/src/parser/classes/livechat/LiveChatActionPanel.js +++ b/src/parser/classes/livechat/LiveChatActionPanel.ts @@ -4,7 +4,11 @@ import { YTNode } from '../../helpers'; class LiveChatActionPanel extends YTNode { static type = 'LiveChatActionPanel'; - constructor(data) { + id: string; + contents; + target_id: string; + + constructor(data: any) { super(); this.id = data.id; this.contents = Parser.parse(data.contents); diff --git a/src/parser/classes/livechat/MarkChatItemAsDeletedAction.js b/src/parser/classes/livechat/MarkChatItemAsDeletedAction.ts similarity index 70% rename from src/parser/classes/livechat/MarkChatItemAsDeletedAction.js rename to src/parser/classes/livechat/MarkChatItemAsDeletedAction.ts index 8ff0a59d..3548d15b 100644 --- a/src/parser/classes/livechat/MarkChatItemAsDeletedAction.js +++ b/src/parser/classes/livechat/MarkChatItemAsDeletedAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class MarkChatItemAsDeletedAction extends YTNode { static type = 'MarkChatItemAsDeletedAction'; - constructor(data) { + deleted_state_message: Text; + target_item_id: string; + + constructor(data: any) { super(); this.deleted_state_message = new Text(data.deletedStateMessage); this.target_item_id = data.targetItemId; diff --git a/src/parser/classes/livechat/MarkChatItemsByAuthorAsDeletedAction.js b/src/parser/classes/livechat/MarkChatItemsByAuthorAsDeletedAction.ts similarity index 71% rename from src/parser/classes/livechat/MarkChatItemsByAuthorAsDeletedAction.js rename to src/parser/classes/livechat/MarkChatItemsByAuthorAsDeletedAction.ts index 197ed5db..d2021e3e 100644 --- a/src/parser/classes/livechat/MarkChatItemsByAuthorAsDeletedAction.js +++ b/src/parser/classes/livechat/MarkChatItemsByAuthorAsDeletedAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class MarkChatItemsByAuthorAsDeletedAction extends YTNode { static type = 'MarkChatItemsByAuthorAsDeletedAction'; - constructor(data) { + deleted_state_message: Text; + channel_id: string; + + constructor(data: any) { super(); this.deleted_state_message = new Text(data.deletedStateMessage); this.channel_id = data.externalChannelId; diff --git a/src/parser/classes/livechat/RemoveBannerForLiveChatCommand.js b/src/parser/classes/livechat/RemoveBannerForLiveChatCommand.ts similarity index 67% rename from src/parser/classes/livechat/RemoveBannerForLiveChatCommand.js rename to src/parser/classes/livechat/RemoveBannerForLiveChatCommand.ts index 13529cd7..e2c00205 100644 --- a/src/parser/classes/livechat/RemoveBannerForLiveChatCommand.js +++ b/src/parser/classes/livechat/RemoveBannerForLiveChatCommand.ts @@ -3,7 +3,9 @@ import { YTNode } from '../../helpers'; class RemoveBannerForLiveChatCommand extends YTNode { static type = 'RemoveBannerForLiveChatCommand'; - constructor(data) { + target_action_id: string; + + constructor(data: any) { super(); this.target_action_id = data.targetActionId; } diff --git a/src/parser/classes/livechat/ReplaceChatItemAction.js b/src/parser/classes/livechat/ReplaceChatItemAction.ts similarity index 72% rename from src/parser/classes/livechat/ReplaceChatItemAction.js rename to src/parser/classes/livechat/ReplaceChatItemAction.ts index 6400e7fd..e72e5bf3 100644 --- a/src/parser/classes/livechat/ReplaceChatItemAction.js +++ b/src/parser/classes/livechat/ReplaceChatItemAction.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class ReplaceChatItemAction extends YTNode { static type = 'ReplaceChatItemAction'; - constructor(data) { + target_item_id: string; + replacement_item; + + constructor(data: any) { super(); this.target_item_id = data.targetItemId; this.replacement_item = Parser.parse(data.replacementItem); diff --git a/src/parser/classes/livechat/ReplayChatItemAction.js b/src/parser/classes/livechat/ReplayChatItemAction.ts similarity index 62% rename from src/parser/classes/livechat/ReplayChatItemAction.js rename to src/parser/classes/livechat/ReplayChatItemAction.ts index a167dcfa..6320542c 100644 --- a/src/parser/classes/livechat/ReplayChatItemAction.js +++ b/src/parser/classes/livechat/ReplayChatItemAction.ts @@ -4,9 +4,12 @@ import { YTNode } from '../../helpers'; class ReplayChatItemAction extends YTNode { static type = 'ReplayChatItemAction'; - constructor(data) { + actions; + video_offset_time_msec: string; // Or number? + + constructor(data: any) { super(); - this.actions = Parser.parse(data.actions?.map((action) => { + this.actions = Parser.parse(data.actions?.map((action: any) => { delete action.clickTrackingParams; return action; })) || []; diff --git a/src/parser/classes/livechat/ShowLiveChatActionPanelAction.js b/src/parser/classes/livechat/ShowLiveChatActionPanelAction.ts similarity index 73% rename from src/parser/classes/livechat/ShowLiveChatActionPanelAction.js rename to src/parser/classes/livechat/ShowLiveChatActionPanelAction.ts index 4c0a0f3c..00261cc2 100644 --- a/src/parser/classes/livechat/ShowLiveChatActionPanelAction.js +++ b/src/parser/classes/livechat/ShowLiveChatActionPanelAction.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class ShowLiveChatActionPanelAction extends YTNode { static type = 'ShowLiveChatActionPanelAction'; - constructor(data) { + panel_to_show; + + constructor(data: any) { super(); this.panel_to_show = Parser.parse(data.panelToShow); } diff --git a/src/parser/classes/livechat/ShowLiveChatTooltipCommand.js b/src/parser/classes/livechat/ShowLiveChatTooltipCommand.ts similarity index 74% rename from src/parser/classes/livechat/ShowLiveChatTooltipCommand.js rename to src/parser/classes/livechat/ShowLiveChatTooltipCommand.ts index e350e813..7ed83934 100644 --- a/src/parser/classes/livechat/ShowLiveChatTooltipCommand.js +++ b/src/parser/classes/livechat/ShowLiveChatTooltipCommand.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class ShowLiveChatTooltipCommand extends YTNode { static type = 'ShowLiveChatTooltipCommand'; - constructor(data) { + tooltip; + + constructor(data: any) { super(); this.tooltip = Parser.parse(data.tooltip); } diff --git a/src/parser/classes/livechat/UpdateDateTextAction.js b/src/parser/classes/livechat/UpdateDateTextAction.ts similarity index 73% rename from src/parser/classes/livechat/UpdateDateTextAction.js rename to src/parser/classes/livechat/UpdateDateTextAction.ts index be4b0965..5230a95c 100644 --- a/src/parser/classes/livechat/UpdateDateTextAction.js +++ b/src/parser/classes/livechat/UpdateDateTextAction.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class UpdateDateTextAction extends YTNode { static type = 'UpdateDateTextAction'; - constructor(data) { + date_text: string; + + constructor(data: any) { super(); this.date_text = new Text(data.dateText).toString(); } diff --git a/src/parser/classes/livechat/UpdateDescriptionAction.js b/src/parser/classes/livechat/UpdateDescriptionAction.ts similarity index 72% rename from src/parser/classes/livechat/UpdateDescriptionAction.js rename to src/parser/classes/livechat/UpdateDescriptionAction.ts index 85fd6255..a686fdb9 100644 --- a/src/parser/classes/livechat/UpdateDescriptionAction.js +++ b/src/parser/classes/livechat/UpdateDescriptionAction.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class UpdateDescriptionAction extends YTNode { static type = 'UpdateDescriptionAction'; - constructor(data) { + description: Text; + + constructor(data: any) { super(); this.description = new Text(data.description); } diff --git a/src/parser/classes/livechat/UpdateLiveChatPollAction.js b/src/parser/classes/livechat/UpdateLiveChatPollAction.ts similarity index 74% rename from src/parser/classes/livechat/UpdateLiveChatPollAction.js rename to src/parser/classes/livechat/UpdateLiveChatPollAction.ts index b2b9bbb0..bae55e2d 100644 --- a/src/parser/classes/livechat/UpdateLiveChatPollAction.js +++ b/src/parser/classes/livechat/UpdateLiveChatPollAction.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class UpdateLiveChatPollAction extends YTNode { static type = 'UpdateLiveChatPollAction'; - constructor(data) { + poll_to_update; + + constructor(data: any) { super(); this.poll_to_update = Parser.parse(data.pollToUpdate); } diff --git a/src/parser/classes/livechat/UpdateTitleAction.js b/src/parser/classes/livechat/UpdateTitleAction.ts similarity index 73% rename from src/parser/classes/livechat/UpdateTitleAction.js rename to src/parser/classes/livechat/UpdateTitleAction.ts index 5d6c30b3..8242a3af 100644 --- a/src/parser/classes/livechat/UpdateTitleAction.js +++ b/src/parser/classes/livechat/UpdateTitleAction.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class UpdateTitleAction extends YTNode { static type = 'UpdateTitleAction'; - constructor(data) { + title: Text; + + constructor(data: any) { super(); this.title = new Text(data.title); } diff --git a/src/parser/classes/livechat/UpdateToggleButtonTextAction.js b/src/parser/classes/livechat/UpdateToggleButtonTextAction.ts similarity index 71% rename from src/parser/classes/livechat/UpdateToggleButtonTextAction.js rename to src/parser/classes/livechat/UpdateToggleButtonTextAction.ts index e7f1f06c..4ba0f854 100644 --- a/src/parser/classes/livechat/UpdateToggleButtonTextAction.js +++ b/src/parser/classes/livechat/UpdateToggleButtonTextAction.ts @@ -4,7 +4,11 @@ import { YTNode } from '../../helpers'; class UpdateToggleButtonTextAction extends YTNode { static type = 'UpdateToggleButtonTextAction'; - constructor(data) { + default_text: string; + toggled_text: string; + button_id: string; + + constructor(data: any) { super(); this.default_text = new Text(data.defaultText).toString(); this.toggled_text = new Text(data.toggledText).toString(); diff --git a/src/parser/classes/livechat/UpdateViewershipAction.js b/src/parser/classes/livechat/UpdateViewershipAction.ts similarity index 76% rename from src/parser/classes/livechat/UpdateViewershipAction.js rename to src/parser/classes/livechat/UpdateViewershipAction.ts index 858bcdc6..d0e9311d 100644 --- a/src/parser/classes/livechat/UpdateViewershipAction.js +++ b/src/parser/classes/livechat/UpdateViewershipAction.ts @@ -4,7 +4,11 @@ import { YTNode } from '../../helpers'; class UpdateViewershipAction extends YTNode { static type = 'UpdateViewershipAction'; - constructor(data) { + view_count: Text; + extra_short_view_count: Text; + is_live: boolean; + + constructor(data: any) { super(); const view_count_renderer = data.viewCount.videoViewCountRenderer; this.view_count = new Text(view_count_renderer.viewCount); diff --git a/src/parser/classes/livechat/items/LiveChatBannerHeader.js b/src/parser/classes/livechat/items/LiveChatBannerHeader.ts similarity index 75% rename from src/parser/classes/livechat/items/LiveChatBannerHeader.js rename to src/parser/classes/livechat/items/LiveChatBannerHeader.ts index 59eb76e5..f5026ea4 100644 --- a/src/parser/classes/livechat/items/LiveChatBannerHeader.js +++ b/src/parser/classes/livechat/items/LiveChatBannerHeader.ts @@ -5,7 +5,11 @@ import { YTNode } from '../../../helpers'; class LiveChatBannerHeader extends YTNode { static type = 'LiveChatBannerHeader'; - constructor(data) { + text: string; + icon_type: string; + context_menu_button; + + constructor(data: any) { super(); this.text = new Text(data.text).toString(); this.icon_type = data.icon.iconType; diff --git a/src/parser/classes/livechat/items/LiveChatBannerPoll.js b/src/parser/classes/livechat/items/LiveChatBannerPoll.ts similarity index 67% rename from src/parser/classes/livechat/items/LiveChatBannerPoll.js rename to src/parser/classes/livechat/items/LiveChatBannerPoll.ts index bf9f59d8..3f934fd6 100644 --- a/src/parser/classes/livechat/items/LiveChatBannerPoll.js +++ b/src/parser/classes/livechat/items/LiveChatBannerPoll.ts @@ -6,12 +6,23 @@ import { YTNode } from '../../../helpers'; class LiveChatBannerPoll extends YTNode { static type = 'LiveChatBannerPoll'; - constructor(data) { + poll_question: Text; + author_photo: Thumbnail[]; + choices: { + option_id: string; + text: string; + }[]; + + collapsed_state_entity_key: string; + live_chat_poll_state_entity_key: string; + context_menu_button; + + constructor(data: any) { super(); this.poll_question = new Text(data.pollQuestion); this.author_photo = Thumbnail.fromResponse(data.authorPhoto); - this.choices = data.pollChoices.map((choice) => ({ + this.choices = data.pollChoices.map((choice: any) => ({ option_id: choice.pollOptionId, text: new Text(choice.text).toString() })); diff --git a/src/parser/classes/livechat/items/LiveChatMembershipItem.js b/src/parser/classes/livechat/items/LiveChatMembershipItem.ts similarity index 74% rename from src/parser/classes/livechat/items/LiveChatMembershipItem.js rename to src/parser/classes/livechat/items/LiveChatMembershipItem.ts index 2db92227..15715684 100644 --- a/src/parser/classes/livechat/items/LiveChatMembershipItem.js +++ b/src/parser/classes/livechat/items/LiveChatMembershipItem.ts @@ -7,7 +7,20 @@ import { YTNode } from '../../../helpers'; class LiveChatMembershipItem extends YTNode { static type = 'LiveChatMembershipItem'; - constructor(data) { + id: string; + timestamp: number; + header_subtext: Text; + + author: { + id: string; + name: Text; + thumbnails: Thumbnail[]; + badges: any; + }; + + menu_endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.id = data.id; this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000); diff --git a/src/parser/classes/livechat/items/LiveChatPaidMessage.js b/src/parser/classes/livechat/items/LiveChatPaidMessage.js deleted file mode 100644 index 8c77c51e..00000000 --- a/src/parser/classes/livechat/items/LiveChatPaidMessage.js +++ /dev/null @@ -1,35 +0,0 @@ -import Text from '../../misc/Text'; -import Thumbnail from '../../misc/Thumbnail'; -import NavigationEndpoint from '../../NavigationEndpoint'; -import Parser from '../../../index'; -import { YTNode } from '../../../helpers'; - -class LiveChatPaidMessage extends YTNode { - static type = 'LiveChatPaidMessage'; - - constructor(data) { - super(); - this.message = new Text(data.message); - - this.author = { - id: data.authorExternalChannelId, - name: new Text(data.authorName), - thumbnails: Thumbnail.fromResponse(data.authorPhoto), - badges: Parser.parse(data.authorBadges) - }; - - const badges = Parser.parse(data.authorBadges); - - this.author.badges = badges; - this.author.is_moderator = badges?.some((badge) => badge.icon_type == 'MODERATOR') || null; - this.author.is_verified = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null; - this.author.is_verified_artist = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null; - this.purchase_amount = new Text(data.purchaseAmountText).toString(); - this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint); - this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000); - this.timestamp_text = new Text(data.timestampText).toString(); - this.id = data.id; - } -} - -export default LiveChatPaidMessage; \ No newline at end of file diff --git a/src/parser/classes/livechat/items/LiveChatPaidMessage.ts b/src/parser/classes/livechat/items/LiveChatPaidMessage.ts new file mode 100644 index 00000000..0511dd0c --- /dev/null +++ b/src/parser/classes/livechat/items/LiveChatPaidMessage.ts @@ -0,0 +1,58 @@ +import Text from '../../misc/Text'; +import Thumbnail from '../../misc/Thumbnail'; +import NavigationEndpoint from '../../NavigationEndpoint'; +import MetadataBadge from '../../MetadataBadge'; +import Parser from '../../../index'; +import { YTNode } from '../../../helpers'; + +class LiveChatPaidMessage extends YTNode { + static type = 'LiveChatPaidMessage'; + + message: Text; + + author: { + id: string; + name: Text; + thumbnails: Thumbnail[]; + badges: MetadataBadge[]; + is_moderator: boolean | null; + is_verified: boolean | null; + is_verified_artist: boolean | null; + }; + + purchase_amount: string; + menu_endpoint: NavigationEndpoint; + timestamp: number; + timestamp_text: string; + id: string; + + constructor(data: any) { + super(); + this.message = new Text(data.message); + + this.author = { + id: data.authorExternalChannelId, + name: new Text(data.authorName), + thumbnails: Thumbnail.fromResponse(data.authorPhoto), + badges: Parser.parseArray(data.authorBadges, MetadataBadge), + is_moderator: null, + is_verified: null, + is_verified_artist: null + }; + + const badges = Parser.parseArray(data.authorBadges, MetadataBadge); + + this.author.badges = badges; + this.author.is_moderator = badges?.some((badge: any) => badge.icon_type == 'MODERATOR') || null; + this.author.is_verified = badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null; + this.author.is_verified_artist = badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null; + + this.purchase_amount = new Text(data.purchaseAmountText).toString(); + this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint); + this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000); + this.timestamp_text = new Text(data.timestampText).toString(); + this.id = data.id; + } +} + +export default LiveChatPaidMessage; \ No newline at end of file diff --git a/src/parser/classes/livechat/items/LiveChatPaidSticker.js b/src/parser/classes/livechat/items/LiveChatPaidSticker.ts similarity index 74% rename from src/parser/classes/livechat/items/LiveChatPaidSticker.js rename to src/parser/classes/livechat/items/LiveChatPaidSticker.ts index ed99da9e..5097f855 100644 --- a/src/parser/classes/livechat/items/LiveChatPaidSticker.js +++ b/src/parser/classes/livechat/items/LiveChatPaidSticker.ts @@ -7,7 +7,21 @@ import { YTNode } from '../../../helpers'; class LiveChatPaidSticker extends YTNode { static type = 'LiveChatPaidSticker'; - constructor(data) { + id: string; + + author: { + id: string; + name: Text; + thumbnails: Thumbnail[]; + badges: any; + }; + + sticker: Thumbnail[]; + purchase_amount: string; + context_menu: NavigationEndpoint; + timestamp: number; + + constructor(data: any) { super(); this.id = data.id; diff --git a/src/parser/classes/livechat/items/LiveChatPlaceholderItem.js b/src/parser/classes/livechat/items/LiveChatPlaceholderItem.ts similarity index 70% rename from src/parser/classes/livechat/items/LiveChatPlaceholderItem.js rename to src/parser/classes/livechat/items/LiveChatPlaceholderItem.ts index 49993edc..9257a54b 100644 --- a/src/parser/classes/livechat/items/LiveChatPlaceholderItem.js +++ b/src/parser/classes/livechat/items/LiveChatPlaceholderItem.ts @@ -3,7 +3,10 @@ import { YTNode } from '../../../helpers'; class LiveChatPlaceholderItem extends YTNode { static type = 'LiveChatPlaceholderItem'; - constructor(data) { + id: string; + timestamp: number; + + constructor(data: any) { super(); this.id = data.id; this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000); diff --git a/src/parser/classes/livechat/items/LiveChatTextMessage.js b/src/parser/classes/livechat/items/LiveChatTextMessage.ts similarity index 59% rename from src/parser/classes/livechat/items/LiveChatTextMessage.js rename to src/parser/classes/livechat/items/LiveChatTextMessage.ts index cf4c41e9..9524e90f 100644 --- a/src/parser/classes/livechat/items/LiveChatTextMessage.js +++ b/src/parser/classes/livechat/items/LiveChatTextMessage.ts @@ -1,23 +1,44 @@ import Text from '../../misc/Text'; import Thumbnail from '../../misc/Thumbnail'; import NavigationEndpoint from '../../NavigationEndpoint'; +import MetadataBadge from '../../MetadataBadge'; import Parser from '../../../index'; + import { YTNode } from '../../../helpers'; class LiveChatTextMessage extends YTNode { static type = 'LiveChatTextMessage'; - constructor(data) { + message: Text; + author?: { + id: string; + name: Text; + thumbnails: Thumbnail[]; + badges: MetadataBadge[]; + is_moderator: boolean | null; + is_verified: boolean | null; + is_verified_artist: boolean | null; + }; + + menu_endpoint?: NavigationEndpoint; + timestamp: number; + id: string; + + constructor(data: any) { super(); this.message = new Text(data.message); this.author = { id: data.authorExternalChannelId, name: new Text(data.authorName), - thumbnails: Thumbnail.fromResponse(data.authorPhoto) + thumbnails: Thumbnail.fromResponse(data.authorPhoto), + badges: [] as MetadataBadge[], + is_moderator: null, + is_verified: null, + is_verified_artist: null }; - const badges = Parser.parse(data.authorBadges); + const badges = Parser.parseArray(data.authorBadges, MetadataBadge); this.author.badges = badges; this.author.is_moderator = badges ? badges.some((badge) => badge.icon_type == 'MODERATOR') : null; diff --git a/src/parser/classes/livechat/items/LiveChatTickerPaidMessageItem.js b/src/parser/classes/livechat/items/LiveChatTickerPaidMessageItem.ts similarity index 60% rename from src/parser/classes/livechat/items/LiveChatTickerPaidMessageItem.js rename to src/parser/classes/livechat/items/LiveChatTickerPaidMessageItem.ts index 047b6f85..54cdd349 100644 --- a/src/parser/classes/livechat/items/LiveChatTickerPaidMessageItem.js +++ b/src/parser/classes/livechat/items/LiveChatTickerPaidMessageItem.ts @@ -1,22 +1,43 @@ import Text from '../../misc/Text'; import Thumbnail from '../../misc/Thumbnail'; import NavigationEndpoint from '../../NavigationEndpoint'; +import MetadataBadge from '../../MetadataBadge'; import Parser from '../../../index'; + import { YTNode } from '../../../helpers'; class LiveChatTickerPaidMessageItem extends YTNode { static type = 'LiveChatTickerPaidMessageItem'; - constructor(data) { + author: { + id: string; + thumbnails: Thumbnail[]; + badges: MetadataBadge[]; + is_moderator: boolean | null; + is_verified: boolean | null; + is_verified_artist: boolean | null; + }; + + amount: Text; + duration_sec: string; // Or number? + full_duration_sec: string; + show_item; + show_item_endpoint: NavigationEndpoint; + id: string; + + constructor(data: any) { super(); this.author = { id: data.authorExternalChannelId, thumbnails: Thumbnail.fromResponse(data.authorPhoto), - badges: Parser.parse(data.authorBadges) + badges: Parser.parseArray(data.authorBadges, MetadataBadge), + is_moderator: null, + is_verified: null, + is_verified_artist: null }; - const badges = Parser.parse(data.authorBadges); + const badges = Parser.parseArray(data.authorBadges, MetadataBadge); this.author.badges = badges; this.author.is_moderator = badges?.some((badge) => badge.icon_type == 'MODERATOR') || null; @@ -25,7 +46,7 @@ class LiveChatTickerPaidMessageItem extends YTNode { this.amount = new Text(data.amount); this.duration_sec = data.durationSec; this.full_duration_sec = data.fullDurationSec; - this.show_item = Parser.parse(data.showItemEndpoint.showLiveChatItemEndpoint.renderer, 'livechat/items'); + this.show_item = Parser.parse(data.showItemEndpoint.showLiveChatItemEndpoint.renderer); this.show_item_endpoint = new NavigationEndpoint(data.showItemEndpoint); this.id = data.id; } diff --git a/src/parser/classes/livechat/items/LiveChatTickerSponsorItem.js b/src/parser/classes/livechat/items/LiveChatTickerSponsorItem.ts similarity index 72% rename from src/parser/classes/livechat/items/LiveChatTickerSponsorItem.js rename to src/parser/classes/livechat/items/LiveChatTickerSponsorItem.ts index fec41e7c..d4300ebb 100644 --- a/src/parser/classes/livechat/items/LiveChatTickerSponsorItem.js +++ b/src/parser/classes/livechat/items/LiveChatTickerSponsorItem.ts @@ -5,7 +5,17 @@ import { YTNode } from '../../../helpers'; class LiveChatTickerSponsorItem extends YTNode { static type = 'LiveChatTickerSponsorItem'; - constructor(data) { + id: string; + detail_text: string; + author: { + id: string; + name: Text; + thumbnails: Thumbnail[]; + }; + + duration_sec: string; + + constructor(data: any) { super(); this.id = data.id; this.detail_text = new Text(data.detailText).toString(); diff --git a/src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.js b/src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.ts similarity index 77% rename from src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.js rename to src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.ts index dbf680de..003b417c 100644 --- a/src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.js +++ b/src/parser/classes/livechat/items/LiveChatViewerEngagementMessage.ts @@ -4,7 +4,10 @@ import Parser from '../../../index'; class LiveChatViewerEngagementMessage extends LiveChatTextMessage { static type = 'LiveChatViewerEngagementMessage'; - constructor(data) { + icon_type: string; + action_button; + + constructor(data: any) { super(data); delete this.author; delete this.menu_endpoint; diff --git a/src/parser/classes/livechat/items/PollHeader.js b/src/parser/classes/livechat/items/PollHeader.ts similarity index 75% rename from src/parser/classes/livechat/items/PollHeader.js rename to src/parser/classes/livechat/items/PollHeader.ts index 001c19f0..bbc61fe0 100644 --- a/src/parser/classes/livechat/items/PollHeader.js +++ b/src/parser/classes/livechat/items/PollHeader.ts @@ -6,7 +6,13 @@ import { YTNode } from '../../../helpers'; class PollHeader extends YTNode { static type = 'PollHeader'; - constructor(data) { + poll_question: Text; + thumbnails: Thumbnail[]; + metadata: Text; + live_chat_poll_type: string; + context_menu_button; + + constructor(data: any) { super(); this.poll_question = new Text(data.pollQuestion); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); diff --git a/src/parser/classes/menus/MenuNavigationItem.js b/src/parser/classes/menus/MenuNavigationItem.ts similarity index 69% rename from src/parser/classes/menus/MenuNavigationItem.js rename to src/parser/classes/menus/MenuNavigationItem.ts index 21a89393..31fc8de4 100644 --- a/src/parser/classes/menus/MenuNavigationItem.js +++ b/src/parser/classes/menus/MenuNavigationItem.ts @@ -3,7 +3,7 @@ import Button from '../Button'; class MenuNavigationItem extends Button { static type = 'MenuNavigationItem'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/menus/MenuServiceItem.js b/src/parser/classes/menus/MenuServiceItem.ts similarity index 69% rename from src/parser/classes/menus/MenuServiceItem.js rename to src/parser/classes/menus/MenuServiceItem.ts index 6eb252c5..deb58ceb 100644 --- a/src/parser/classes/menus/MenuServiceItem.js +++ b/src/parser/classes/menus/MenuServiceItem.ts @@ -3,7 +3,7 @@ import Button from '../Button'; class MenuServiceItem extends Button { static type = 'MenuServiceItem'; - constructor(data) { + constructor(data: any) { super(data); } } diff --git a/src/parser/classes/menus/MenuServiceItemDownload.js b/src/parser/classes/menus/MenuServiceItemDownload.ts similarity index 73% rename from src/parser/classes/menus/MenuServiceItemDownload.js rename to src/parser/classes/menus/MenuServiceItemDownload.ts index 6c93c722..9767640f 100644 --- a/src/parser/classes/menus/MenuServiceItemDownload.js +++ b/src/parser/classes/menus/MenuServiceItemDownload.ts @@ -4,7 +4,10 @@ import { YTNode } from '../../helpers'; class MenuServiceItemDownload extends YTNode { static type = 'MenuServiceItemDownload'; - constructor(data) { + has_separator: boolean; + endpoint: NavigationEndpoint; + + constructor(data: any) { super(); this.has_separator = data.hasSeparator; this.endpoint = new NavigationEndpoint(data.navigationEndpoint || data.serviceEndpoint); diff --git a/src/parser/classes/menus/MultiPageMenu.js b/src/parser/classes/menus/MultiPageMenu.ts similarity index 75% rename from src/parser/classes/menus/MultiPageMenu.js rename to src/parser/classes/menus/MultiPageMenu.ts index 1ba51b06..aedaa8c7 100644 --- a/src/parser/classes/menus/MultiPageMenu.js +++ b/src/parser/classes/menus/MultiPageMenu.ts @@ -4,7 +4,11 @@ import { YTNode } from '../../helpers'; class MultiPageMenu extends YTNode { static type = 'MultiPageMenu'; - constructor(data) { + header; + sections; + style: string; + + constructor(data: any) { super(); this.header = Parser.parse(data.header); this.sections = Parser.parse(data.sections); diff --git a/src/parser/classes/menus/MultiPageMenuNotificationSection.js b/src/parser/classes/menus/MultiPageMenuNotificationSection.ts similarity index 77% rename from src/parser/classes/menus/MultiPageMenuNotificationSection.js rename to src/parser/classes/menus/MultiPageMenuNotificationSection.ts index 43f4900f..695f2118 100644 --- a/src/parser/classes/menus/MultiPageMenuNotificationSection.js +++ b/src/parser/classes/menus/MultiPageMenuNotificationSection.ts @@ -4,7 +4,9 @@ import { YTNode } from '../../helpers'; class MultiPageMenuNotificationSection extends YTNode { static type = 'MultiPageMenuNotificationSection'; - constructor(data) { + items; + + constructor(data: any) { super(); this.items = Parser.parse(data.items); } diff --git a/src/parser/classes/menus/SimpleMenuHeader.js b/src/parser/classes/menus/SimpleMenuHeader.ts similarity index 77% rename from src/parser/classes/menus/SimpleMenuHeader.js rename to src/parser/classes/menus/SimpleMenuHeader.ts index 5eddedfb..3f9f5dcf 100644 --- a/src/parser/classes/menus/SimpleMenuHeader.js +++ b/src/parser/classes/menus/SimpleMenuHeader.ts @@ -5,7 +5,10 @@ import { YTNode } from '../../helpers'; class SimpleMenuHeader extends YTNode { static type = 'SimpleMenuHeader'; - constructor(data) { + title: Text; + buttons; + + constructor(data: any) { super(); this.title = new Text(data.title); this.buttons = Parser.parse(data.buttons); diff --git a/src/parser/classes/misc/Author.js b/src/parser/classes/misc/Author.js deleted file mode 100644 index 99674d5a..00000000 --- a/src/parser/classes/misc/Author.js +++ /dev/null @@ -1,38 +0,0 @@ -import Parser from '../../index'; -import NavigatableText from './NavigatableText'; -import Thumbnail from './Thumbnail'; -import Constants from '../../../utils/Constants'; - -class Author { - #nav_text; - - constructor(item, badges, thumbs) { - this.#nav_text = new NavigatableText(item); - - this.id = - this.#nav_text.runs?.[0].endpoint?.browse?.id || - this.#nav_text.endpoint?.browse?.id || 'N/A'; - - this.name = this.#nav_text.text || 'N/A'; - this.thumbnails = thumbs ? Thumbnail.fromResponse(thumbs) : []; - this.endpoint = this.#nav_text.runs?.[0].endpoint || this.#nav_text.endpoint; - this.badges = Array.isArray(badges) ? Parser.parseArray(badges) : []; - this.is_verified = this.badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null; - this.is_verified_artist = this.badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null; - - this.url = - this.#nav_text.runs?.[0].endpoint?.browse && - `${Constants.URLS.YT_BASE}${this.#nav_text.runs[0].endpoint?.browse?.base_url || `/u/${this.#nav_text.runs[0].endpoint?.browse?.id}`}` || - `${Constants.URLS.YT_BASE}${this.#nav_text.endpoint?.browse?.base_url || `/u/${this.#nav_text.endpoint?.browse?.id}`}` || - null; - } - - /** - * @type {Thumbnail | undefined} - */ - get best_thumbnail() { - return this.thumbnails[0]; - } -} - -export default Author; \ No newline at end of file diff --git a/src/parser/classes/misc/Author.ts b/src/parser/classes/misc/Author.ts new file mode 100644 index 00000000..2b792c23 --- /dev/null +++ b/src/parser/classes/misc/Author.ts @@ -0,0 +1,46 @@ +import Parser from '../../index'; +import NavigatableText from './NavigatableText'; +import NavigationEndpoint from '../NavigationEndpoint'; +import TextRun from './TextRun'; +import Thumbnail from './Thumbnail'; +import Constants from '../../../utils/Constants'; + +class Author { + #nav_text; + + id: string; + name: string; + thumbnails: Thumbnail[]; + endpoint: NavigationEndpoint | null; + badges?: any; + is_verified?: boolean | null; + is_verified_artist?: boolean | null; + url: string | null; + + constructor(item: any, badges?: any, thumbs?: any) { + this.#nav_text = new NavigatableText(item); + + this.id = + (this.#nav_text.runs?.[0] as TextRun)?.endpoint?.browse?.id || + this.#nav_text?.endpoint?.browse?.id || 'N/A'; + + this.name = this.#nav_text.text || 'N/A'; + this.thumbnails = thumbs ? Thumbnail.fromResponse(thumbs) : []; + this.endpoint = ((this.#nav_text.runs?.[0] as TextRun) as TextRun)?.endpoint || this.#nav_text.endpoint; + this.badges = Array.isArray(badges) ? Parser.parseArray(badges) : []; + this.is_verified = this.badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null; + this.is_verified_artist = this.badges?.some((badge: any) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null; + + this.url = + (this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.browse && + `${Constants.URLS.YT_BASE}${(this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.browse?.base_url || `/u/${(this.#nav_text?.runs?.[0] as TextRun)?.endpoint?.browse?.id}`}` || + `${Constants.URLS.YT_BASE}${this.#nav_text?.endpoint?.browse?.base_url || `/u/${this.#nav_text?.endpoint?.browse?.id}`}` || + null; + } + + get best_thumbnail(): Thumbnail | undefined { + return this.thumbnails[0]; + } +} + +export default Author; \ No newline at end of file diff --git a/src/parser/classes/misc/Format.js b/src/parser/classes/misc/Format.js deleted file mode 100644 index a529b645..00000000 --- a/src/parser/classes/misc/Format.js +++ /dev/null @@ -1,47 +0,0 @@ -class Format { - constructor(data) { - this.itag = data.itag; - this.mime_type = data.mimeType; - this.bitrate = data.bitrate; - this.average_bitrate = data.averageBitrate; - this.width = data.width || null; - this.height = data.height || null; - - this.init_range = data.initRange ? { - start: parseInt(data.initRange.start), - end: parseInt(data.initRange.end) - } : undefined; - - this.index_range = data.indexRange ? { - start: parseInt(data.indexRange.start), - end: parseInt(data.indexRange.end) - } : undefined; - - this.last_modified = new Date(Math.floor(parseInt(data.lastModified) / 1000)); - this.content_length = parseInt(data.contentLength); - this.quality = data.quality; - this.quality_label = data.qualityLabel || null; - this.fps = data.fps || null; - this.url = data.url || null; - this.cipher = data.cipher || null; - this.signature_cipher = data.signatureCipher || null; - this.audio_quality = data.audioQuality; - this.approx_duration_ms = parseInt(data.approxDurationMs); - this.audio_sample_rate = parseInt(data.audioSampleRate); - this.audio_channels = data.audioChannels; - this.loudness_db = data.loudnessDb; - this.has_audio = !!data.audioBitrate || !!data.audioQuality; - this.has_video = !!data.qualityLabel; - } - - /** - * Decipher the streaming url of the format. - * @returns {string} Deciphered URL for downloading - */ - decipher() { - return this.url; - // Return player.decipher(this.url, this.signature_cipher, this.cipher); - } -} - -export default Format; \ No newline at end of file diff --git a/src/parser/classes/misc/Format.ts b/src/parser/classes/misc/Format.ts new file mode 100644 index 00000000..4512e168 --- /dev/null +++ b/src/parser/classes/misc/Format.ts @@ -0,0 +1,79 @@ +class Format { + itag: string; + mime_type: string; + bitrate; + average_bitrate; + width; + height; + + init_range: { + start: number; + end: number; + } | undefined; + + index_range: { + start: number; + end: number; + } | undefined; + + last_modified: Date; + content_length: number; + quality: string; + quality_label: string | undefined; + fps: string | undefined; + url: string; + cipher: string | undefined; + signature_cipher: string | undefined; + audio_quality: string | undefined; + approx_duration_ms: number; + audio_sample_rate: number; + audio_channels: string; + loudness_db: string; + has_audio: boolean; + has_video: boolean; + + constructor(data: any) { + this.itag = data.itag; + this.mime_type = data.mimeType; + this.bitrate = data.bitrate; + this.average_bitrate = data.averageBitrate; + this.width = data.width || undefined; + this.height = data.height || undefined; + + this.init_range = data.initRange ? { + start: parseInt(data.initRange.start), + end: parseInt(data.initRange.end) + } : undefined; + + this.index_range = data.indexRange ? { + start: parseInt(data.indexRange.start), + end: parseInt(data.indexRange.end) + } : undefined; + + this.last_modified = new Date(Math.floor(parseInt(data.lastModified) / 1000)); + this.content_length = parseInt(data.contentLength); + this.quality = data.quality; + this.quality_label = data.qualityLabel || undefined; + this.fps = data.fps || undefined; + this.url = data.url || undefined; + this.cipher = data.cipher || undefined; + this.signature_cipher = data.signatureCipher || undefined; + this.audio_quality = data.audioQuality || undefined; + this.approx_duration_ms = parseInt(data.approxDurationMs); + this.audio_sample_rate = parseInt(data.audioSampleRate); + this.audio_channels = data.audioChannels; + this.loudness_db = data.loudnessDb; + this.has_audio = !!data.audioBitrate || !!data.audioQuality; + this.has_video = !!data.qualityLabel; + } + + /** + * Decipher the streaming url of the format. + * @returns Deciphered URL. + */ + decipher(): string { + return this.url; + } +} + +export default Format; \ No newline at end of file diff --git a/src/parser/classes/misc/NavigatableText.js b/src/parser/classes/misc/NavigatableText.ts similarity index 82% rename from src/parser/classes/misc/NavigatableText.js rename to src/parser/classes/misc/NavigatableText.ts index 450cf44a..199bb2fe 100644 --- a/src/parser/classes/misc/NavigatableText.js +++ b/src/parser/classes/misc/NavigatableText.ts @@ -4,9 +4,9 @@ import NavigationEndpoint from '../NavigationEndpoint'; class NavigatableText extends Text { static type = 'NavigatableText'; - endpoint; + endpoint: NavigationEndpoint | null; - constructor(node) { + constructor(node: any) { super(node); // TODO: is this needed? Text now supports this itself this.endpoint = @@ -18,7 +18,7 @@ class NavigatableText extends Text { new NavigationEndpoint(node.titleNavigationEndpoint) : null; } - toJSON() { + toJSON(): NavigatableText { return this; } } diff --git a/src/parser/classes/misc/PlaylistAuthor.js b/src/parser/classes/misc/PlaylistAuthor.ts similarity index 70% rename from src/parser/classes/misc/PlaylistAuthor.js rename to src/parser/classes/misc/PlaylistAuthor.ts index 518f8523..789ed7f4 100644 --- a/src/parser/classes/misc/PlaylistAuthor.js +++ b/src/parser/classes/misc/PlaylistAuthor.ts @@ -1,7 +1,7 @@ import Author from './Author'; class PlaylistAuthor extends Author { - constructor(item, badges, thumbs) { + constructor(item: any, badges?: any, thumbs?: any) { super(item, badges, thumbs); delete this.badges; delete this.is_verified; diff --git a/src/parser/classes/misc/Thumbnail.js b/src/parser/classes/misc/Thumbnail.js deleted file mode 100644 index 707dbdc7..00000000 --- a/src/parser/classes/misc/Thumbnail.js +++ /dev/null @@ -1,34 +0,0 @@ -class Thumbnail { - /** - * @type {string} - */ - url; - /** - * @type {number} - */ - width; - /** - * @type {number} - */ - height; - - constructor({ url, width, height }) { - this.url = url; - this.width = width; - this.height = height; - } - - /** - * Get thumbnails from response object - * - * @param {object} data - response object - * @returns {Thumbnail[]} sorted array of thumbnails - */ - static fromResponse(data) { - if (!data || !data.thumbnails) - return; - return data.thumbnails.map((x) => new Thumbnail(x)).sort((a, b) => b.width - a.width); - } -} - -export default Thumbnail; \ No newline at end of file diff --git a/src/parser/classes/misc/Thumbnail.ts b/src/parser/classes/misc/Thumbnail.ts new file mode 100644 index 00000000..1b173d3f --- /dev/null +++ b/src/parser/classes/misc/Thumbnail.ts @@ -0,0 +1,21 @@ +class Thumbnail { + url: string; + width: number; + height: number; + + constructor(data: any) { + this.url = data.url; + this.width = data.width; + this.height = data.height; + } + + /** + * Get thumbnails from response object. + */ + static fromResponse(data: any): Thumbnail[] { + if (!data || !data.thumbnails) return []; + return data.thumbnails.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width); + } +} + +export default Thumbnail; \ No newline at end of file diff --git a/src/parser/classes/misc/VideoDetails.js b/src/parser/classes/misc/VideoDetails.ts similarity index 64% rename from src/parser/classes/misc/VideoDetails.js rename to src/parser/classes/misc/VideoDetails.ts index 290c4d88..4b6ad88d 100644 --- a/src/parser/classes/misc/VideoDetails.js +++ b/src/parser/classes/misc/VideoDetails.ts @@ -1,32 +1,22 @@ import Thumbnail from './Thumbnail'; class VideoDetails { - /** - * @type {string} - */ - id; - /** - * @type {string} - */ - channel_id; - /** - * @type {string} - */ - title; - /** - * @type {string[]} - */ - keywords; - /** - * @type {string} - */ - short_description; - /** - * @type {string} - */ - author; + id: string; + channel_id: string; + title: string; + duration: number; + keywords: string[]; + is_owner_viewing: boolean; + short_description: string; + thumbnail: Thumbnail[]; + allow_ratings: boolean; + view_count: number; + author: string; + is_private: boolean; + is_live_content: boolean; + is_crawlable: boolean; - constructor(data) { + constructor(data: any) { this.id = data.videoId; this.channel_id = data.channelId; this.title = data.title; diff --git a/src/parser/youtube/LiveChat.ts b/src/parser/youtube/LiveChat.ts index 66fd38f4..5756973f 100644 --- a/src/parser/youtube/LiveChat.ts +++ b/src/parser/youtube/LiveChat.ts @@ -21,7 +21,7 @@ import RemoveBannerForLiveChatCommand from '../classes/livechat/RemoveBannerForL import ShowLiveChatTooltipCommand from '../classes/livechat/ShowLiveChatTooltipCommand'; import { InnertubeError } from '../../utils/Utils'; -import { ObservedArray } from '../helpers'; +import { ObservedArray, YTNode } from '../helpers'; export type ChatAction = AddChatItemAction | AddBannerToLiveChatCommand | AddLiveChatTickerItemAction | @@ -106,7 +106,7 @@ class LiveChat extends EventEmitter { * Ensures actions are emitted at the right speed. * This was adapted from YouTube's compiled code (Android). */ - async #emitSmoothedActions(actions: ObservedArray) { + async #emitSmoothedActions(actions: ObservedArray) { const base = 1E4; let delay = actions.length < base / 80 ? 1 : 0;