diff --git a/src/core/mixins/Feed.ts b/src/core/mixins/Feed.ts index 2e71f2d1..ddf95e4e 100644 --- a/src/core/mixins/Feed.ts +++ b/src/core/mixins/Feed.ts @@ -160,7 +160,7 @@ export default class Feed { * Finds shelf by title. */ getShelf(title: string) { - return this.shelves.get({ title }); + return this.shelves.find((shelf) => shelf.title.toString() === title); } /** diff --git a/src/core/mixins/MediaInfo.ts b/src/core/mixins/MediaInfo.ts index 0630cebb..2fe6dd0d 100644 --- a/src/core/mixins/MediaInfo.ts +++ b/src/core/mixins/MediaInfo.ts @@ -188,8 +188,8 @@ export default class MediaInfo { if (!next_response.engagement_panels) throw new InnertubeError('Engagement panels not found. Video likely has no transcript.'); - const transcript_panel = next_response.engagement_panels.get({ - panel_identifier: 'engagement-panel-searchable-transcript' + const transcript_panel = next_response.engagement_panels.find((panel) => { + return panel.panel_identifier === 'engagement-panel-searchable-transcript'; }); if (!transcript_panel) diff --git a/src/parser/youtube/Channel.ts b/src/parser/youtube/Channel.ts index 600086a4..c19b1bfd 100644 --- a/src/parser/youtube/Channel.ts +++ b/src/parser/youtube/Channel.ts @@ -62,7 +62,7 @@ export default class Channel extends TabbedFeed { this.subscribe_button = this.page.header_memo?.getType(SubscribeButton)[0]; if (this.page.contents) - this.current_tab = this.page.contents.item().as(TwoColumnBrowseResults).tabs.get({ selected: true }); + this.current_tab = this.page.contents.item().as(TwoColumnBrowseResults).tabs.find((tab) => tab.selected); } /** @@ -75,7 +75,7 @@ export default class Channel extends TabbedFeed { const filter_chipbar = this.memo.getType(FeedFilterChipBar)[0]; if (typeof filter === 'string') { - target_filter = filter_chipbar?.contents.get({ text: filter }); + target_filter = filter_chipbar?.contents.find((chip) => chip.text === filter); if (!target_filter) throw new InnertubeError(`Filter ${filter} not found`, { available_filters: this.filters }); } else { @@ -330,7 +330,7 @@ export class FilteredChannelList extends FilterableFeed { constructor(actions: Actions, data: ApiResponse | IBrowseResponse, already_parsed = false) { super(actions, data, already_parsed); - this.applied_filter = this.memo.getType(ChipCloudChip).get({ is_selected: true }); + this.applied_filter = this.memo.getType(ChipCloudChip).find((chip) => chip.is_selected); // Removes the filter chipbar from the actions list if ( diff --git a/src/parser/youtube/Search.ts b/src/parser/youtube/Search.ts index 2d1f4c6e..e6dd4daf 100644 --- a/src/parser/youtube/Search.ts +++ b/src/parser/youtube/Search.ts @@ -59,7 +59,9 @@ export default class Search extends Feed { if (typeof card === 'string') { if (!this.refinement_cards) throw new InnertubeError('No refinement cards found.'); - target_card = this.refinement_cards?.cards.get({ query: card })?.as(SearchRefinementCard); + target_card = this.refinement_cards?.cards.find((refinement_card): refinement_card is SearchRefinementCard => { + return refinement_card.is(SearchRefinementCard) && refinement_card.query === card; + }); if (!target_card) throw new InnertubeError(`Refinement card "${card}" not found`, { available_cards: this.refinement_card_queries }); } else if (card.type === 'SearchRefinementCard') { diff --git a/src/parser/youtube/Settings.ts b/src/parser/youtube/Settings.ts index bd728438..208df956 100644 --- a/src/parser/youtube/Settings.ts +++ b/src/parser/youtube/Settings.ts @@ -33,7 +33,7 @@ export default class Settings { if (!this.#page.contents) throw new InnertubeError('Page contents not found'); - const tab = this.#page.contents.item().as(TwoColumnBrowseResults).tabs.get({ selected: true }); + const tab = this.#page.contents.item().as(TwoColumnBrowseResults).tabs.find((tab) => tab.selected); if (!tab) throw new InnertubeError('Target tab not found'); @@ -58,7 +58,7 @@ export default class Settings { let item: CompactLink | undefined; if (typeof target_item === 'string') { - item = this.sidebar.items.get({ title: target_item }); + item = this.sidebar.items.find((link) => link.title === target_item); if (!item) throw new InnertubeError(`Item "${target_item}" not found`, { available_items: this.sidebar_items }); } else if (target_item?.is(CompactLink)) { diff --git a/src/parser/youtube/VideoInfo.ts b/src/parser/youtube/VideoInfo.ts index f2dc5c4b..ad81cb1b 100644 --- a/src/parser/youtube/VideoInfo.ts +++ b/src/parser/youtube/VideoInfo.ts @@ -131,7 +131,9 @@ export default class VideoInfo extends MediaInfo { } } - const comments_entry_point = results.get({ target_id: 'comments-entry-point' })?.as(ItemSection); + const comments_entry_point = results.find((node): node is ItemSection => { + return node.is(ItemSection) && node.target_id === 'comments-entry-point'; + }); this.comments_entry_point_header = comments_entry_point?.contents?.firstOfType(CommentsEntryPointHeader); this.livechat = next?.contents_memo?.getType(LiveChat)[0]; @@ -163,7 +165,7 @@ export default class VideoInfo extends MediaInfo { let cloud_chip: ChipCloudChip; if (typeof target_filter === 'string') { - const filter = this.related_chip_cloud?.chips?.get({ text: target_filter }); + const filter = this.related_chip_cloud?.chips?.find((chip) => chip.text === target_filter); if (!filter) throw new InnertubeError('Invalid filter', { available_filters: this.filters }); @@ -178,9 +180,11 @@ export default class VideoInfo extends MediaInfo { if (cloud_chip.is_selected) return this; const response = await cloud_chip.endpoint?.call(this.actions, { parse: true }); - const data = response?.on_response_received_endpoints?.get({ target_id: 'watch-next-feed' }); + const data = response?.on_response_received_endpoints?.find((endpoint): endpoint is ReloadContinuationItemsCommand => { + return endpoint.is(ReloadContinuationItemsCommand) && endpoint.target_id === 'watch-next-feed'; + }); - this.watch_next_feed = data?.as(AppendContinuationItemsAction, ReloadContinuationItemsCommand).contents; + this.watch_next_feed = data?.contents; return this; } @@ -207,12 +211,12 @@ export default class VideoInfo extends MediaInfo { throw new InnertubeError('Watch next feed continuation not found'); const response = await this.#watch_next_continuation?.endpoint.call(this.actions, { parse: true }); - const data = response?.on_response_received_endpoints?.get({ type: 'AppendContinuationItemsAction' }); + const data = response?.on_response_received_endpoints?.firstOfType(AppendContinuationItemsAction); if (!data) throw new InnertubeError('AppendContinuationItemsAction not found'); - this.watch_next_feed = data?.as(AppendContinuationItemsAction, ReloadContinuationItemsCommand).contents; + this.watch_next_feed = data?.contents; if (this.watch_next_feed?.at(-1)?.is(ContinuationItem)) { this.#watch_next_continuation = this.watch_next_feed.pop()?.as(ContinuationItem); } else { diff --git a/src/parser/ytmusic/Explore.ts b/src/parser/ytmusic/Explore.ts index 9b1963b4..6ad3b2a2 100644 --- a/src/parser/ytmusic/Explore.ts +++ b/src/parser/ytmusic/Explore.ts @@ -20,7 +20,7 @@ export default class Explore { constructor(response: ApiResponse) { this.#page = Parser.parseResponse(response.data); - const tab = this.#page.contents?.item().as(SingleColumnBrowseResults).tabs.get({ selected: true }); + const tab = this.#page.contents?.item().as(SingleColumnBrowseResults).tabs.find((tab) => tab.selected); if (!tab) throw new InnertubeError('Could not find target tab.'); diff --git a/src/parser/ytmusic/HomeFeed.ts b/src/parser/ytmusic/HomeFeed.ts index b7353bb3..d5eae625 100644 --- a/src/parser/ytmusic/HomeFeed.ts +++ b/src/parser/ytmusic/HomeFeed.ts @@ -23,7 +23,7 @@ export default class HomeFeed { this.#actions = actions; this.#page = Parser.parseResponse(response.data); - const tab = this.#page.contents?.item().as(SingleColumnBrowseResults).tabs.get({ selected: true }); + const tab = this.#page.contents?.item().as(SingleColumnBrowseResults).tabs.find((tab) => tab.selected); if (!tab) throw new InnertubeError('Could not find Home tab.'); @@ -62,7 +62,7 @@ export default class HomeFeed { let cloud_chip: ChipCloudChip | undefined; if (typeof target_filter === 'string') { - cloud_chip = this.header?.chips?.as(ChipCloudChip).get({ text: target_filter }); + cloud_chip = this.header?.chips?.as(ChipCloudChip).find((chip) => chip.text === target_filter); if (!cloud_chip) throw new InnertubeError('Could not find filter with given name.', { available_filters: this.filters }); } else if (target_filter?.is(ChipCloudChip)) { diff --git a/src/parser/ytmusic/Library.ts b/src/parser/ytmusic/Library.ts index 1168d5ed..8255c363 100644 --- a/src/parser/ytmusic/Library.ts +++ b/src/parser/ytmusic/Library.ts @@ -97,7 +97,7 @@ export default class Library { const chip_cloud = this.#page.contents_memo?.getType(ChipCloud)[0]; if (typeof filter === 'string') { - target_chip = chip_cloud?.chips.get({ text: filter }); + target_chip = chip_cloud?.chips.find((chip) => chip.text === filter); if (!target_chip) throw new InnertubeError(`Filter "${filter}" not found`, { available_filters: this.filters }); diff --git a/src/parser/ytmusic/Search.ts b/src/parser/ytmusic/Search.ts index d73033c3..7e7803e8 100644 --- a/src/parser/ytmusic/Search.ts +++ b/src/parser/ytmusic/Search.ts @@ -32,7 +32,7 @@ export default class Search { if (!this.#page.contents || !this.#page.contents_memo) throw new InnertubeError('Response did not contain any contents.'); - const tab = this.#page.contents.item().as(TabbedSearchResults).tabs.get({ selected: true }); + const tab = this.#page.contents.item().as(TabbedSearchResults).tabs.find((tab) => tab.selected); if (!tab) throw new InnertubeError('Could not find target tab.'); @@ -87,7 +87,7 @@ export default class Search { let cloud_chip: ChipCloudChip | undefined; if (typeof target_filter === 'string') { - cloud_chip = this.header?.chips?.as(ChipCloudChip).get({ text: target_filter }); + cloud_chip = this.header?.chips?.as(ChipCloudChip).find((chip) => chip.text === target_filter); if (!cloud_chip) throw new InnertubeError('Could not find filter with given name.', { available_filters: this.filters }); } else if (target_filter?.is(ChipCloudChip)) { diff --git a/src/parser/ytmusic/TrackInfo.ts b/src/parser/ytmusic/TrackInfo.ts index 69ca3920..e1c008e6 100644 --- a/src/parser/ytmusic/TrackInfo.ts +++ b/src/parser/ytmusic/TrackInfo.ts @@ -48,7 +48,7 @@ class TrackInfo extends MediaInfo { throw new InnertubeError('Could not find any tab'); const target_tab = - this.tabs.get({ title: title_or_page_type }) || + this.tabs.find((tab) => tab.title === title_or_page_type) || this.tabs.find((tab) => tab.endpoint.payload.browseEndpointContextSupportedConfigs?.browseEndpointContextMusicConfig?.pageType === title_or_page_type) || this.tabs?.[0];