diff --git a/README.md b/README.md index 000ec116..a3c77b05 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,7 @@ const yt = await Innertube.create({ * [.getSearchSuggestions(query)](#getsearchsuggestions) * [.getComments(video_id, sort_by?)](#getcomments) * [.getHomeFeed()](#gethomefeed) + * [.getGuide()](#getguide) * [.getLibrary()](#getlibrary) * [.getHistory()](#gethistory) * [.getTrending()](#gettrending) @@ -426,6 +427,12 @@ Retrieves YouTube's home feed.

+ +### getGuide() +Retrieves YouTube's content guide. + +**Returns**: `Promise` + ### getLibrary() Retrieves the account's library. diff --git a/deno/package.json b/deno/package.json index d9ef31f2..9d626129 100644 --- a/deno/package.json +++ b/deno/package.json @@ -1,6 +1,6 @@ { "name": "youtubei.js", - "version": "3.1.1", + "version": "3.2.0", "description": "A wrapper around YouTube's private API. Supports YouTube, YouTube Music, YouTube Kids and YouTube Studio (WIP).", "type": "module", "types": "./dist/src/platform/lib.d.ts", diff --git a/deno/src/Innertube.ts b/deno/src/Innertube.ts index 11c9ba61..2e1c07c3 100644 --- a/deno/src/Innertube.ts +++ b/deno/src/Innertube.ts @@ -21,6 +21,7 @@ import PlaylistManager from './core/PlaylistManager.ts'; import YTStudio from './core/Studio.ts'; import TabbedFeed from './core/TabbedFeed.ts'; import HomeFeed from './parser/youtube/HomeFeed.ts'; +import Guide from './parser/youtube/Guide.ts'; import Proto from './proto/index.ts'; import Constants from './utils/Constants.ts'; @@ -170,6 +171,14 @@ class Innertube { return new HomeFeed(this.actions, response); } + /** + * Retrieves YouTube's content guide. + */ + async getGuide(): Promise { + const response = await this.actions.execute('/guide'); + return new Guide(response.data); + } + /** * Returns the account's library. */ diff --git a/deno/src/core/Feed.ts b/deno/src/core/Feed.ts index c072b68b..5e3c3856 100644 --- a/deno/src/core/Feed.ts +++ b/deno/src/core/Feed.ts @@ -4,6 +4,7 @@ import { concatMemos, InnertubeError } from '../utils/Utils.ts'; import type Actions from './Actions.ts'; import BackstagePost from '../parser/classes/BackstagePost.ts'; +import SharedPost from '../parser/classes/SharedPost.ts'; import Channel from '../parser/classes/Channel.ts'; import CompactVideo from '../parser/classes/CompactVideo.ts'; import GridChannel from '../parser/classes/GridChannel.ts'; @@ -100,7 +101,7 @@ class Feed { * Get all the community posts in the feed */ get posts() { - return this.#memo.getType([ BackstagePost, Post ]); + return this.#memo.getType([ BackstagePost, Post, SharedPost ]); } /** diff --git a/deno/src/core/Music.ts b/deno/src/core/Music.ts index 034bb350..bdc5b122 100644 --- a/deno/src/core/Music.ts +++ b/deno/src/core/Music.ts @@ -28,6 +28,10 @@ import type { ObservedArray, YTNode } from '../parser/helpers.ts'; import type Actions from './Actions.ts'; import type Session from './Session.ts'; +export type SearchFilters = { + type?: 'all' | 'song' | 'video' | 'album' | 'playlist' | 'artist'; +}; + class Music { #session: Session; #actions: Actions; @@ -108,9 +112,7 @@ class Music { * @param query - Search query. * @param filters - Search filters. */ - async search(query: string, filters: { - type?: 'all' | 'song' | 'video' | 'album' | 'playlist' | 'artist'; - } = {}): Promise { + async search(query: string, filters: SearchFilters = {}): Promise { throwIfMissing({ query }); const payload: { diff --git a/deno/src/parser/classes/AccountChannel.ts b/deno/src/parser/classes/AccountChannel.ts index 973f9994..6815976e 100644 --- a/deno/src/parser/classes/AccountChannel.ts +++ b/deno/src/parser/classes/AccountChannel.ts @@ -1,6 +1,7 @@ import Text from './misc/Text.ts'; import NavigationEndpoint from './NavigationEndpoint.ts'; import { YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; class AccountChannel extends YTNode { static type = 'AccountChannel'; @@ -8,7 +9,7 @@ class AccountChannel extends YTNode { title: Text; endpoint: NavigationEndpoint; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); this.endpoint = new NavigationEndpoint(data.navigationEndpoint); diff --git a/deno/src/parser/classes/AccountItemSection.ts b/deno/src/parser/classes/AccountItemSection.ts index 01d0d9da..9bffdbe0 100644 --- a/deno/src/parser/classes/AccountItemSection.ts +++ b/deno/src/parser/classes/AccountItemSection.ts @@ -6,6 +6,7 @@ import NavigationEndpoint from './NavigationEndpoint.ts'; import AccountItemSectionHeader from './AccountItemSectionHeader.ts'; import { YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; class AccountItem { static type = 'AccountItem'; @@ -18,7 +19,7 @@ class AccountItem { endpoint: NavigationEndpoint; account_byline: Text; - constructor(data: any) { + constructor(data: RawNode) { this.account_name = new Text(data.accountName); this.account_photo = Thumbnail.fromResponse(data.accountPhoto); this.is_selected = data.isSelected; @@ -35,7 +36,7 @@ class AccountItemSection extends YTNode { contents; header; - constructor(data: any) { + constructor(data: RawNode) { super(); this.contents = data.contents.map((ac: any) => new AccountItem(ac.accountItem)); this.header = Parser.parseItem(data.header, AccountItemSectionHeader); diff --git a/deno/src/parser/classes/AccountItemSectionHeader.ts b/deno/src/parser/classes/AccountItemSectionHeader.ts index 566cbf64..1355c5ab 100644 --- a/deno/src/parser/classes/AccountItemSectionHeader.ts +++ b/deno/src/parser/classes/AccountItemSectionHeader.ts @@ -1,12 +1,12 @@ import Text from './misc/Text.ts'; import { YTNode } from '../helpers.ts'; - +import type { RawNode } from '../index.ts'; class AccountItemSectionHeader extends YTNode { static type = 'AccountItemSectionHeader'; title: Text; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); } diff --git a/deno/src/parser/classes/AccountSectionList.ts b/deno/src/parser/classes/AccountSectionList.ts index feaae69b..f6d220dd 100644 --- a/deno/src/parser/classes/AccountSectionList.ts +++ b/deno/src/parser/classes/AccountSectionList.ts @@ -3,14 +3,14 @@ import AccountChannel from './AccountChannel.ts'; import AccountItemSection from './AccountItemSection.ts'; import { YTNode } from '../helpers.ts'; - +import type { RawNode } from '../index.ts'; class AccountSectionList extends YTNode { static type = 'AccountSectionList'; contents; footers; - constructor(data: any) { + constructor(data: RawNode) { super(); this.contents = Parser.parseItem(data.contents[0], AccountItemSection); this.footers = Parser.parseItem(data.footers[0], AccountChannel); diff --git a/deno/src/parser/classes/Alert.ts b/deno/src/parser/classes/Alert.ts index 6bb1bb90..2c8aac67 100644 --- a/deno/src/parser/classes/Alert.ts +++ b/deno/src/parser/classes/Alert.ts @@ -1,13 +1,13 @@ import Text from './misc/Text.ts'; import { YTNode } from '../helpers.ts'; - +import type { RawNode } from '../index.ts'; class Alert extends YTNode { static type = 'Alert'; text: Text; alert_type: string; - constructor(data: any) { + constructor(data: RawNode) { super(); this.text = new Text(data.text); this.alert_type = data.type; diff --git a/deno/src/parser/classes/AudioOnlyPlayability.ts b/deno/src/parser/classes/AudioOnlyPlayability.ts index 64fcde67..7b6071f5 100644 --- a/deno/src/parser/classes/AudioOnlyPlayability.ts +++ b/deno/src/parser/classes/AudioOnlyPlayability.ts @@ -1,11 +1,11 @@ import { YTNode } from '../helpers.ts'; - +import type { RawNode } from '../index.ts'; class AudioOnlyPlayability extends YTNode { static type = 'AudioOnlyPlayability'; audio_only_availability: string; - constructor (data: any) { + constructor (data: RawNode) { super(); this.audio_only_availability = data.audioOnlyAvailability; } diff --git a/deno/src/parser/classes/AutomixPreviewVideo.ts b/deno/src/parser/classes/AutomixPreviewVideo.ts index ce704f1f..b3eda2b3 100644 --- a/deno/src/parser/classes/AutomixPreviewVideo.ts +++ b/deno/src/parser/classes/AutomixPreviewVideo.ts @@ -1,12 +1,12 @@ import { YTNode } from '../helpers.ts'; import NavigationEndpoint from './NavigationEndpoint.ts'; - +import type { RawNode } from '../index.ts'; class AutomixPreviewVideo extends YTNode { static type = 'AutomixPreviewVideo'; playlist_video?: { endpoint: NavigationEndpoint }; - constructor(data: any) { + constructor(data: RawNode) { super(); if (data?.content?.automixPlaylistVideoRenderer?.navigationEndpoint) { this.playlist_video = { diff --git a/deno/src/parser/classes/GuideCollapsibleEntry.ts b/deno/src/parser/classes/GuideCollapsibleEntry.ts new file mode 100644 index 00000000..28cd98ac --- /dev/null +++ b/deno/src/parser/classes/GuideCollapsibleEntry.ts @@ -0,0 +1,35 @@ +import Text from './misc/Text.ts'; +import { YTNode } from '../helpers.ts'; +import Parser from '../parser.ts'; + +class GuideCollapsibleEntry extends YTNode { + static type = 'GuideCollapsibleEntry'; + + expander_item: { + title: string, + icon_type: string + }; + collapser_item: { + title: string, + icon_type: string + }; + expandable_items; + + constructor(data: any) { + super(); + + this.expander_item = { + title: new Text(data.expanderItem.guideEntryRenderer.formattedTitle).toString(), + icon_type: data.expanderItem.guideEntryRenderer.icon.iconType + }; + + this.collapser_item = { + title: new Text(data.collapserItem.guideEntryRenderer.formattedTitle).toString(), + icon_type: data.collapserItem.guideEntryRenderer.icon.iconType + }; + + this.expandable_items = Parser.parseArray(data.expandableItems); + } +} + +export default GuideCollapsibleEntry; \ No newline at end of file diff --git a/deno/src/parser/classes/GuideCollapsibleSectionEntry.ts b/deno/src/parser/classes/GuideCollapsibleSectionEntry.ts new file mode 100644 index 00000000..75eb0d73 --- /dev/null +++ b/deno/src/parser/classes/GuideCollapsibleSectionEntry.ts @@ -0,0 +1,23 @@ +import { YTNode } from '../helpers.ts'; +import Parser from '../parser.ts'; + +class GuideCollapsibleSectionEntry extends YTNode { + static type = 'GuideCollapsibleSectionEntry'; + + header_entry; + expander_icon: string; + collapser_icon: string; + section_items; + + constructor(data: any) { + super(); + + this.header_entry = Parser.parseItem(data.headerEntry); + this.expander_icon = data.expanderIcon.iconType; + this.collapser_icon = data.collapserIcon.iconType; + this.section_items = Parser.parseArray(data.sectionItems); + + } +} + +export default GuideCollapsibleSectionEntry; \ No newline at end of file diff --git a/deno/src/parser/classes/GuideDownloadsEntry.ts b/deno/src/parser/classes/GuideDownloadsEntry.ts new file mode 100644 index 00000000..2c27f921 --- /dev/null +++ b/deno/src/parser/classes/GuideDownloadsEntry.ts @@ -0,0 +1,14 @@ +import GuideEntry from './GuideEntry.ts'; + +class GuideDownloadsEntry extends GuideEntry { + static type = 'GuideDownloadsEntry'; + + always_show: boolean; + + constructor(data: any) { + super(data.entryRenderer.guideEntryRenderer); + this.always_show = !!data.alwaysShow; + } +} + +export default GuideDownloadsEntry; \ No newline at end of file diff --git a/deno/src/parser/classes/GuideEntry.ts b/deno/src/parser/classes/GuideEntry.ts new file mode 100644 index 00000000..76a232fc --- /dev/null +++ b/deno/src/parser/classes/GuideEntry.ts @@ -0,0 +1,33 @@ +import Text from './misc/Text.ts'; +import NavigationEndpoint from './NavigationEndpoint.ts'; +import { YTNode } from '../helpers.ts'; +import Thumbnail from './misc/Thumbnail.ts'; + +class GuideEntry extends YTNode { + static type = 'GuideEntry'; + + title: Text; + endpoint: NavigationEndpoint; + icon_type?: string; + thumbnails?: Thumbnail[]; + badges?: any; + is_primary: boolean; + + constructor(data: any) { + super(); + this.title = new Text(data.formattedTitle); + this.endpoint = new NavigationEndpoint(data.navigationEndpoint || data.serviceEndpoint); + if (data.icon?.iconType) { + this.icon_type = data.icon.iconType; + } + if (data.thumbnail) { + this.thumbnails = Thumbnail.fromResponse(data.thumbnail); + } + if (data.badges) { + this.badges = data.badges; + } + this.is_primary = !!data.isPrimary; + } +} + +export default GuideEntry; \ No newline at end of file diff --git a/deno/src/parser/classes/GuideSection.ts b/deno/src/parser/classes/GuideSection.ts new file mode 100644 index 00000000..0361b5fd --- /dev/null +++ b/deno/src/parser/classes/GuideSection.ts @@ -0,0 +1,20 @@ +import Text from './misc/Text.ts'; +import { YTNode } from '../helpers.ts'; +import Parser from '../parser.ts'; + +class GuideSection extends YTNode { + static type = 'GuideSection'; + + title?: Text; + items; + + constructor(data: any) { + super(); + if (data.formattedTitle) { + this.title = new Text(data.formattedTitle); + } + this.items = Parser.parseArray(data.items); + } +} + +export default GuideSection; \ No newline at end of file diff --git a/deno/src/parser/classes/GuideSubscriptionsSection.ts b/deno/src/parser/classes/GuideSubscriptionsSection.ts new file mode 100644 index 00000000..e6a2864f --- /dev/null +++ b/deno/src/parser/classes/GuideSubscriptionsSection.ts @@ -0,0 +1,7 @@ +import GuideSection from './GuideSection.ts'; + +class GuideSubscriptionsSection extends GuideSection { + static type = 'GuideSubscriptionsSection'; +} + +export default GuideSubscriptionsSection; \ No newline at end of file diff --git a/deno/src/parser/classes/HeroPlaylistThumbnail.ts b/deno/src/parser/classes/HeroPlaylistThumbnail.ts new file mode 100644 index 00000000..fb59b1be --- /dev/null +++ b/deno/src/parser/classes/HeroPlaylistThumbnail.ts @@ -0,0 +1,19 @@ +import { YTNode } from '../helpers.ts'; +import NavigationEndpoint from './NavigationEndpoint.ts'; +import Thumbnail from './misc/Thumbnail.ts'; + +class HeroPlaylistThumbnail extends YTNode { + static type = 'HeroPlaylistThumbnail'; + + thumbnails: Thumbnail[]; + on_tap_endpoint: NavigationEndpoint; + + constructor(data: any) { + super(); + + this.thumbnails = Thumbnail.fromResponse(data.thumbnail); + this.on_tap_endpoint = new NavigationEndpoint(data.onTap); + } +} + +export default HeroPlaylistThumbnail; \ No newline at end of file diff --git a/deno/src/parser/classes/PlayerLegacyDesktopYpcOffer.ts b/deno/src/parser/classes/PlayerLegacyDesktopYpcOffer.ts new file mode 100644 index 00000000..9c07a68e --- /dev/null +++ b/deno/src/parser/classes/PlayerLegacyDesktopYpcOffer.ts @@ -0,0 +1,21 @@ +import { YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; + +class PlayerLegacyDesktopYpcOffer extends YTNode { + static type = 'PlayerLegacyDesktopYpcOffer'; + + title: string; + thumbnail: string; + offer_description: string; + offer_id: string; + + constructor(data: RawNode) { + super(); + this.title = data.itemTitle; + this.thumbnail = data.itemThumbnail; + this.offer_description = data.offerDescription; + this.offer_id = data.offerId; + } +} + +export default PlayerLegacyDesktopYpcOffer; \ No newline at end of file diff --git a/deno/src/parser/classes/PlaylistHeader.ts b/deno/src/parser/classes/PlaylistHeader.ts index 79ef0fda..09074421 100644 --- a/deno/src/parser/classes/PlaylistHeader.ts +++ b/deno/src/parser/classes/PlaylistHeader.ts @@ -21,6 +21,7 @@ class PlaylistHeader extends YTNode { save_button; shuffle_play_button; menu; + banner; constructor(data: any) { super(); @@ -39,6 +40,7 @@ class PlaylistHeader extends YTNode { this.save_button = Parser.parse(data.saveButton); this.shuffle_play_button = Parser.parse(data.shufflePlayButton); this.menu = Parser.parse(data.moreActionsMenu); + this.banner = Parser.parseItem(data.playlistHeaderBanner); } } diff --git a/deno/src/parser/classes/RichMetadata.ts b/deno/src/parser/classes/RichMetadata.ts new file mode 100644 index 00000000..2f14d8ac --- /dev/null +++ b/deno/src/parser/classes/RichMetadata.ts @@ -0,0 +1,32 @@ +import Text from './misc/Text.ts'; +import Thumbnail from './misc/Thumbnail.ts'; +import NavigationEndpoint from './NavigationEndpoint.ts'; +import { YTNode } from '../helpers.ts'; + +class RichMetadata extends YTNode { + static type = 'RichMetadata'; + + thumbnail: Thumbnail[]; + title: Text; + subtitle?: Text; + call_to_action: Text; + icon_type?: string; + endpoint: NavigationEndpoint; + + constructor(data: any) { + super(); + + this.thumbnail = Thumbnail.fromResponse(data.thumbnail); + this.title = new Text(data.title); + this.subtitle = new Text(data.subtitle); + this.call_to_action = new Text(data.callToAction); + + if (data.callToActionIcon?.iconType) { + this.icon_type = data.callToActionIcon?.iconType; + } + + this.endpoint = new NavigationEndpoint(data.endpoint); + } +} + +export default RichMetadata; \ No newline at end of file diff --git a/deno/src/parser/classes/RichMetadataRow.ts b/deno/src/parser/classes/RichMetadataRow.ts new file mode 100644 index 00000000..bcb5dae3 --- /dev/null +++ b/deno/src/parser/classes/RichMetadataRow.ts @@ -0,0 +1,15 @@ +import Parser from '../index.ts'; +import { YTNode } from '../helpers.ts'; + +class RichMetadataRow extends YTNode { + static type = 'RichMetadataRow'; + + contents; + + constructor(data: any) { + super(); + this.contents = Parser.parseArray(data.contents); + } +} + +export default RichMetadataRow; \ No newline at end of file diff --git a/deno/src/parser/classes/SearchFilter.ts b/deno/src/parser/classes/SearchFilter.ts new file mode 100644 index 00000000..b7cf992d --- /dev/null +++ b/deno/src/parser/classes/SearchFilter.ts @@ -0,0 +1,22 @@ +import { YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; +import Text from './misc/Text.ts'; +import NavigationEndpoint from './NavigationEndpoint.ts'; + +class SearchFilter extends YTNode { + static type = 'SearchFilter'; + + label: Text; + endpoint: NavigationEndpoint; + tooltip: string; + + constructor(data: RawNode) { + super(); + + this.label = new Text(data.label); + this.endpoint = new NavigationEndpoint(data.endpoint); + this.tooltip = data.tooltip; + } +} + +export default SearchFilter; \ No newline at end of file diff --git a/deno/src/parser/classes/SearchFilterGroup.ts b/deno/src/parser/classes/SearchFilterGroup.ts new file mode 100644 index 00000000..b0347969 --- /dev/null +++ b/deno/src/parser/classes/SearchFilterGroup.ts @@ -0,0 +1,21 @@ +import { ObservedArray, YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; +import { Parser } from '../index.ts'; +import Text from './misc/Text.ts'; +import SearchFilter from './SearchFilter.ts'; + +class SearchFilterGroup extends YTNode { + static type = 'SearchFilterGroup'; + + title: Text; + filters: ObservedArray | null; + + constructor(data: RawNode) { + super(); + + this.title = new Text(data.title); + this.filters = Parser.parseArray(data.filters, SearchFilter); + } +} + +export default SearchFilterGroup; \ No newline at end of file diff --git a/deno/src/parser/classes/SearchSubMenu.ts b/deno/src/parser/classes/SearchSubMenu.ts new file mode 100644 index 00000000..9b0bf1e6 --- /dev/null +++ b/deno/src/parser/classes/SearchSubMenu.ts @@ -0,0 +1,23 @@ +import { ObservedArray, YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; +import Parser from '../index.ts'; +import Text from './misc/Text.ts'; +import SearchFilterGroup from './SearchFilterGroup.ts'; +import ToggleButton from './ToggleButton.ts'; + +class SearchSubMenu extends YTNode { + static type = 'SearchSubMenu'; + + title: Text; + groups: ObservedArray | null; + button: ToggleButton | null; + + constructor(data: RawNode) { + super(); + this.title = new Text(data.title); + this.groups = Parser.parseArray(data.groups, SearchFilterGroup); + this.button = Parser.parseItem(data.button, ToggleButton); + } +} + +export default SearchSubMenu; \ No newline at end of file diff --git a/deno/src/parser/classes/SegmentedLikeDislikeButton.ts b/deno/src/parser/classes/SegmentedLikeDislikeButton.ts index a785cd07..cbdeecfe 100644 --- a/deno/src/parser/classes/SegmentedLikeDislikeButton.ts +++ b/deno/src/parser/classes/SegmentedLikeDislikeButton.ts @@ -1,17 +1,19 @@ -import Parser from '../index.ts'; -import ToggleButton from './ToggleButton.ts'; import { YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; +import Parser from '../index.ts'; +import Button from './Button.ts'; +import ToggleButton from './ToggleButton.ts'; class SegmentedLikeDislikeButton extends YTNode { static type = 'SegmentedLikeDislikeButton'; - like_button: ToggleButton | null; - dislike_button: ToggleButton | null; + like_button: ToggleButton | Button | null; + dislike_button: ToggleButton | Button | null; - constructor (data: any) { + constructor (data: RawNode) { super(); - this.like_button = Parser.parseItem(data.likeButton, ToggleButton); - this.dislike_button = Parser.parseItem(data.dislikeButton, ToggleButton); + this.like_button = Parser.parseItem(data.likeButton, [ ToggleButton, Button ]); + this.dislike_button = Parser.parseItem(data.dislikeButton, [ ToggleButton, Button ]); } } diff --git a/deno/src/parser/classes/SharedPost.ts b/deno/src/parser/classes/SharedPost.ts new file mode 100644 index 00000000..a66f7130 --- /dev/null +++ b/deno/src/parser/classes/SharedPost.ts @@ -0,0 +1,38 @@ +import { YTNode } from '../helpers.ts'; +import { Menu } from '../map.ts'; +import Parser from '../parser.ts'; +import BackstagePost from './BackstagePost.ts'; +import Button from './Button.ts'; +import Author from './misc/Author.ts'; +import Text from './misc/Text.ts'; +import Thumbnail from './misc/Thumbnail.ts'; +import NavigationEndpoint from './NavigationEndpoint.ts'; + +class SharedPost extends YTNode { + static type = 'SharedPost'; + + thumbnail: Thumbnail[]; + content: Text; + published: Text; + menu: Menu | null; + original_post: BackstagePost | null; + id: string; + endpoint: NavigationEndpoint; + expand_button: Button | null; + author: Author; + + constructor(data: any) { + super(); + this.thumbnail = Thumbnail.fromResponse(data.thumbnail); + this.content = new Text(data.content); + this.published = new Text(data.publishedTimeText); + this.menu = Parser.parseItem(data.actionMenu, Menu); + this.original_post = Parser.parseItem(data.originalPost, BackstagePost); + this.id = data.postId; + this.endpoint = new NavigationEndpoint(data.navigationEndpoint); + this.expand_button = Parser.parseItem(data.expandButton, Button); + this.author = new Author(data.displayName, undefined); + } +} + +export default SharedPost; \ No newline at end of file diff --git a/deno/src/parser/classes/VideoPrimaryInfo.ts b/deno/src/parser/classes/VideoPrimaryInfo.ts index 899979a0..2dfc4548 100644 --- a/deno/src/parser/classes/VideoPrimaryInfo.ts +++ b/deno/src/parser/classes/VideoPrimaryInfo.ts @@ -1,6 +1,9 @@ +import { YTNode } from '../helpers.ts'; +import type { RawNode } from '../index.ts'; +import type { ObservedArray } from '../helpers.ts'; import Parser from '../index.ts'; import Text from './misc/Text.ts'; -import { YTNode } from '../helpers.ts'; +import MetadataBadge from './MetadataBadge.ts'; import Menu from './menus/Menu.ts'; class VideoPrimaryInfo extends YTNode { @@ -10,16 +13,20 @@ class VideoPrimaryInfo extends YTNode { super_title_link: Text; view_count: Text; short_view_count: Text; + badges: ObservedArray; published: Text; - menu; + relative_date: Text; + menu: Menu | null; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); this.super_title_link = new Text(data.superTitleLink); - this.view_count = new Text(data.viewCount.videoViewCountRenderer.viewCount); - this.short_view_count = new Text(data.viewCount.videoViewCountRenderer.shortViewCount); + this.view_count = new Text(data.viewCount?.videoViewCountRenderer?.viewCount); + this.short_view_count = new Text(data.viewCount?.videoViewCountRenderer?.shortViewCount); + this.badges = Parser.parseArray(data.badges, MetadataBadge); this.published = new Text(data.dateText); + this.relative_date = new Text(data.relativeDateText); this.menu = Parser.parseItem(data.videoActions, Menu); } } diff --git a/deno/src/parser/classes/actions/AppendContinuationItemsAction.ts b/deno/src/parser/classes/actions/AppendContinuationItemsAction.ts index 96a50938..8a7766d5 100644 --- a/deno/src/parser/classes/actions/AppendContinuationItemsAction.ts +++ b/deno/src/parser/classes/actions/AppendContinuationItemsAction.ts @@ -1,5 +1,6 @@ import Parser from '../../index.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class AppendContinuationItemsAction extends YTNode { static type = 'AppendContinuationItemsAction'; @@ -7,7 +8,7 @@ class AppendContinuationItemsAction extends YTNode { items; target: string; - constructor(data: any) { + constructor(data: RawNode) { super(); this.items = Parser.parse(data.continuationItems); this.target = data.target; diff --git a/deno/src/parser/classes/actions/OpenPopupAction.ts b/deno/src/parser/classes/actions/OpenPopupAction.ts index 05b78f58..71716eb9 100644 --- a/deno/src/parser/classes/actions/OpenPopupAction.ts +++ b/deno/src/parser/classes/actions/OpenPopupAction.ts @@ -1,5 +1,6 @@ import Parser from '../../index.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class OpenPopupAction extends YTNode { static type = 'OpenPopupAction'; @@ -7,7 +8,7 @@ class OpenPopupAction extends YTNode { popup; popup_type; - constructor(data: any) { + constructor(data: RawNode) { super(); this.popup = Parser.parse(data.popup); this.popup_type = data.popupType; diff --git a/deno/src/parser/classes/analytics/AnalyticsMainAppKeyMetrics.ts b/deno/src/parser/classes/analytics/AnalyticsMainAppKeyMetrics.ts index 0e7460bc..29053c4d 100644 --- a/deno/src/parser/classes/analytics/AnalyticsMainAppKeyMetrics.ts +++ b/deno/src/parser/classes/analytics/AnalyticsMainAppKeyMetrics.ts @@ -1,5 +1,6 @@ import DataModelSection from './DataModelSection.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class AnalyticsMainAppKeyMetrics extends YTNode { static type = 'AnalyticsMainAppKeyMetrics'; @@ -7,7 +8,7 @@ class AnalyticsMainAppKeyMetrics extends YTNode { period: string; sections: DataModelSection[]; - constructor(data: any) { + constructor(data: RawNode) { super(); this.period = data.cardData.periodLabel; const metrics_data = data.cardData.sections[0].analyticsKeyMetricsData; diff --git a/deno/src/parser/classes/analytics/AnalyticsRoot.ts b/deno/src/parser/classes/analytics/AnalyticsRoot.ts index 85d87e4f..c1c53a75 100644 --- a/deno/src/parser/classes/analytics/AnalyticsRoot.ts +++ b/deno/src/parser/classes/analytics/AnalyticsRoot.ts @@ -1,4 +1,5 @@ import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class AnalyticsRoot extends YTNode { static type = 'AnalyticsRoot'; @@ -19,7 +20,7 @@ class AnalyticsRoot extends YTNode { }[]; }[]; - constructor(data: any) { + constructor(data: RawNode) { super(); const cards = data.analyticsTableCarouselData.data.tableCards; diff --git a/deno/src/parser/classes/analytics/AnalyticsShortsCarouselCard.ts b/deno/src/parser/classes/analytics/AnalyticsShortsCarouselCard.ts index 3d78fd15..36cd49f7 100644 --- a/deno/src/parser/classes/analytics/AnalyticsShortsCarouselCard.ts +++ b/deno/src/parser/classes/analytics/AnalyticsShortsCarouselCard.ts @@ -1,4 +1,5 @@ import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; import NavigationEndpoint from '../NavigationEndpoint.ts'; class AnalyticsShortsCarouselCard extends YTNode { @@ -11,7 +12,7 @@ class AnalyticsShortsCarouselCard extends YTNode { endpoint: NavigationEndpoint; }[]; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = data.title; this.shorts = data.shortsCarouselData.shorts.map((short: any) => ({ diff --git a/deno/src/parser/classes/analytics/AnalyticsVideo.ts b/deno/src/parser/classes/analytics/AnalyticsVideo.ts index d2e6bd59..38e26cb7 100644 --- a/deno/src/parser/classes/analytics/AnalyticsVideo.ts +++ b/deno/src/parser/classes/analytics/AnalyticsVideo.ts @@ -1,5 +1,6 @@ import Thumbnail from '../misc/Thumbnail.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class AnalyticsVideo extends YTNode { static type = 'AnalyticsVideo'; @@ -13,7 +14,7 @@ class AnalyticsVideo extends YTNode { is_short: boolean; }; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = data.videoTitle; diff --git a/deno/src/parser/classes/analytics/AnalyticsVodCarouselCard.ts b/deno/src/parser/classes/analytics/AnalyticsVodCarouselCard.ts index dce16d85..94f54075 100644 --- a/deno/src/parser/classes/analytics/AnalyticsVodCarouselCard.ts +++ b/deno/src/parser/classes/analytics/AnalyticsVodCarouselCard.ts @@ -1,5 +1,6 @@ import Video from './AnalyticsVideo.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class AnalyticsVodCarouselCard extends YTNode { static type = 'AnalyticsVodCarouselCard'; @@ -8,7 +9,7 @@ class AnalyticsVodCarouselCard extends YTNode { videos: Video[] | null; no_data_message?: string; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = data.title; diff --git a/deno/src/parser/classes/analytics/CtaGoToCreatorStudio.ts b/deno/src/parser/classes/analytics/CtaGoToCreatorStudio.ts index c77aade7..8cdadd05 100644 --- a/deno/src/parser/classes/analytics/CtaGoToCreatorStudio.ts +++ b/deno/src/parser/classes/analytics/CtaGoToCreatorStudio.ts @@ -1,4 +1,5 @@ import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class CtaGoToCreatorStudio extends YTNode { static type = 'CtaGoToCreatorStudio'; @@ -6,7 +7,7 @@ class CtaGoToCreatorStudio extends YTNode { title: string; use_new_specs: boolean; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = data.buttonLabel; this.use_new_specs = data.useNewSpecs; diff --git a/deno/src/parser/classes/analytics/DataModelSection.ts b/deno/src/parser/classes/analytics/DataModelSection.ts index 4a284562..c6cf82aa 100644 --- a/deno/src/parser/classes/analytics/DataModelSection.ts +++ b/deno/src/parser/classes/analytics/DataModelSection.ts @@ -1,4 +1,5 @@ import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class DataModelSection extends YTNode { static type = 'DataModelSection'; @@ -36,7 +37,7 @@ class DataModelSection extends YTNode { } }; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = data.title; diff --git a/deno/src/parser/classes/analytics/StatRow.ts b/deno/src/parser/classes/analytics/StatRow.ts index 9756628b..55bc300d 100644 --- a/deno/src/parser/classes/analytics/StatRow.ts +++ b/deno/src/parser/classes/analytics/StatRow.ts @@ -1,6 +1,7 @@ import Text from '../misc/Text.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class StatRow extends YTNode { static type = 'StatRow'; @@ -8,7 +9,7 @@ class StatRow extends YTNode { title: Text; contents: Text; - constructor(data: any) { + constructor(data: RawNode) { super(); this.title = new Text(data.title); this.contents = new Text(data.contents); diff --git a/deno/src/parser/classes/comments/AuthorCommentBadge.ts b/deno/src/parser/classes/comments/AuthorCommentBadge.ts index 0cf16f5e..73ad8182 100644 --- a/deno/src/parser/classes/comments/AuthorCommentBadge.ts +++ b/deno/src/parser/classes/comments/AuthorCommentBadge.ts @@ -1,4 +1,5 @@ import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class AuthorCommentBadge extends YTNode { static type = 'AuthorCommentBadge'; @@ -9,7 +10,7 @@ class AuthorCommentBadge extends YTNode { tooltip: string; style?: string; - constructor(data: any) { + constructor(data: RawNode) { super(); this.icon_type = data.icon?.iconType || null; diff --git a/deno/src/parser/classes/comments/Comment.ts b/deno/src/parser/classes/comments/Comment.ts index eb662284..6f513a1c 100644 --- a/deno/src/parser/classes/comments/Comment.ts +++ b/deno/src/parser/classes/comments/Comment.ts @@ -16,6 +16,7 @@ import type Actions from '../../../core/Actions.ts'; import Proto from '../../../proto/index.ts'; import { InnertubeError } from '../../../utils/Utils.ts'; import { YTNode, SuperParsedResult } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class Comment extends YTNode { static type = 'Comment'; @@ -44,7 +45,7 @@ class Comment extends YTNode { is_pinned: boolean; is_member: boolean; - constructor(data: any) { + constructor(data: RawNode) { super(); this.content = new Text(data.contentText); this.published = new Text(data.publishedTimeText); diff --git a/deno/src/parser/classes/comments/CommentActionButtons.ts b/deno/src/parser/classes/comments/CommentActionButtons.ts index 7d18a056..2780fc18 100644 --- a/deno/src/parser/classes/comments/CommentActionButtons.ts +++ b/deno/src/parser/classes/comments/CommentActionButtons.ts @@ -3,6 +3,7 @@ import type Button from '../Button.ts'; import type ToggleButton from '../ToggleButton.ts'; import type CreatorHeart from './CreatorHeart.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class CommentActionButtons extends YTNode { static type = 'CommentActionButtons'; @@ -12,7 +13,7 @@ class CommentActionButtons extends YTNode { reply_button; creator_heart; - constructor(data: any) { + constructor(data: RawNode) { super(); this.like_button = Parser.parseItem(data.likeButton); this.dislike_button = Parser.parseItem(data.dislikeButton); diff --git a/deno/src/parser/classes/comments/CommentDialog.ts b/deno/src/parser/classes/comments/CommentDialog.ts index d0c8b520..57017dcd 100644 --- a/deno/src/parser/classes/comments/CommentDialog.ts +++ b/deno/src/parser/classes/comments/CommentDialog.ts @@ -4,6 +4,7 @@ import Thumbnail from '../misc/Thumbnail.ts'; import type Button from '../Button.ts'; import type EmojiPicker from './EmojiPicker.ts'; import { YTNode } from '../../helpers.ts'; +import type { RawNode } from '../../index.ts'; class CommentDialog extends YTNode { static type = 'CommentDialog'; @@ -16,7 +17,7 @@ class CommentDialog extends YTNode { emoji_button: Button | null; emoji_picker: any | null; - constructor(data: any) { + constructor(data: RawNode) { super(); this.editable_text = new Text(data.editableText); this.author_thumbnail = Thumbnail.fromResponse(data.authorThumbnail); diff --git a/deno/src/parser/classes/comments/CommentReplies.ts b/deno/src/parser/classes/comments/CommentReplies.ts index 58643f05..924f6595 100644 --- a/deno/src/parser/classes/comments/CommentReplies.ts +++ b/deno/src/parser/classes/comments/CommentReplies.ts @@ -2,7 +2,7 @@ import Parser from '../../index.ts'; import Thumbnail from '../misc/Thumbnail.ts'; import type Button from '../Button.ts'; import { YTNode } from '../../helpers.ts'; - +import type { RawNode } from '../../index.ts'; class CommentReplies extends YTNode { static type = 'CommentReplies'; @@ -12,7 +12,7 @@ class CommentReplies extends YTNode { view_replies_creator_thumbnail: Thumbnail[]; has_channel_owner_replied: boolean; - constructor(data: any) { + constructor(data: RawNode) { super(); this.contents = Parser.parseArray(data.contents); this.view_replies = Parser.parseItem