From 7315fca1b448fd3adb94ca5149dfb49663733d87 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 29 Apr 2024 07:09:35 -0400 Subject: [PATCH] Add getPlaylists function (#650) --- src/Innertube.ts | 12 ++++++++++++ src/core/Actions.ts | 1 + src/parser/classes/ChipBarView.ts | 14 ++++++++++++++ src/parser/classes/ChipView.ts | 20 ++++++++++++++++++++ src/parser/nodes.ts | 2 ++ 5 files changed, 49 insertions(+) create mode 100644 src/parser/classes/ChipBarView.ts create mode 100644 src/parser/classes/ChipView.ts diff --git a/src/Innertube.ts b/src/Innertube.ts index 4ee845b3a..07c0c7679 100644 --- a/src/Innertube.ts +++ b/src/Innertube.ts @@ -325,6 +325,18 @@ export default class Innertube { return response.data?.unseenCount || response.data?.actions?.[0].updateNotificationsUnseenCountAction?.unseenCount || 0; } + /** + * Retrieves playlists. + */ + async getPlaylists() { + const response = await this.actions.execute( + BrowseEndpoint.PATH, { ...BrowseEndpoint.build({ browse_id: 'FEplaylist_aggregation' }), parse: true } + ); + + const feed = new Feed(this.actions, response); + return feed.playlists; + } + /** * Retrieves playlist contents. * @param id - Playlist id diff --git a/src/core/Actions.ts b/src/core/Actions.ts index fda837a7d..6a0086594 100644 --- a/src/core/Actions.ts +++ b/src/core/Actions.ts @@ -168,6 +168,7 @@ export default class Actions { 'FEhistory', 'FEsubscriptions', 'FEchannels', + 'FEplaylist_aggregation', 'FEmusic_listening_review', 'FEmusic_library_landing', 'SPaccount_overview', diff --git a/src/parser/classes/ChipBarView.ts b/src/parser/classes/ChipBarView.ts new file mode 100644 index 000000000..59a8942a0 --- /dev/null +++ b/src/parser/classes/ChipBarView.ts @@ -0,0 +1,14 @@ +import { YTNode, type ObservedArray } from '../helpers.js'; +import { Parser, type RawNode } from '../index.js'; +import ChipView from './ChipView.js'; + +export default class ChipBarView extends YTNode { + static type = 'ChipBarView'; + + chips: ObservedArray | null; + + constructor(data: RawNode) { + super(); + this.chips = Parser.parseArray(data.chips, ChipView); + } +} \ No newline at end of file diff --git a/src/parser/classes/ChipView.ts b/src/parser/classes/ChipView.ts new file mode 100644 index 000000000..decced593 --- /dev/null +++ b/src/parser/classes/ChipView.ts @@ -0,0 +1,20 @@ +import { YTNode } from '../helpers.js'; +import { type RawNode } from '../index.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; + +export default class ChipView extends YTNode { + static type = 'ChipView'; + + text: string; + display_type: string; + endpoint: NavigationEndpoint; + chip_entity_key: string; + + constructor(data: RawNode) { + super(); + this.text = data.text; + this.display_type = data.displayType; + this.endpoint = new NavigationEndpoint(data.tapCommand); + this.chip_entity_key = data.chipEntityKey; + } +} \ No newline at end of file diff --git a/src/parser/nodes.ts b/src/parser/nodes.ts index 27b97f950..728073bb9 100644 --- a/src/parser/nodes.ts +++ b/src/parser/nodes.ts @@ -55,8 +55,10 @@ export { default as ChannelThumbnailWithLink } from './classes/ChannelThumbnailW export { default as ChannelVideoPlayer } from './classes/ChannelVideoPlayer.js'; export { default as Chapter } from './classes/Chapter.js'; export { default as ChildVideo } from './classes/ChildVideo.js'; +export { default as ChipBarView } from './classes/ChipBarView.js'; export { default as ChipCloud } from './classes/ChipCloud.js'; export { default as ChipCloudChip } from './classes/ChipCloudChip.js'; +export { default as ChipView } from './classes/ChipView.js'; export { default as ClipAdState } from './classes/ClipAdState.js'; export { default as ClipCreation } from './classes/ClipCreation.js'; export { default as ClipCreationScrubber } from './classes/ClipCreationScrubber.js';