From b175e02f6dc7d283b383ae592a623212bd06e5e9 Mon Sep 17 00:00:00 2001 From: "luan.lrt4@gmail.com" Date: Fri, 22 Apr 2022 00:27:03 -0300 Subject: [PATCH] chore: oops --- lib/Innertube.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/lib/Innertube.js b/lib/Innertube.js index c9519dad..154df216 100644 --- a/lib/Innertube.js +++ b/lib/Innertube.js @@ -237,7 +237,7 @@ class Innertube { * Deletes a given playlist. * * @param {string} playlist_id - * @returns {Promise<{ success: boolean; status_code: string; }>} + * @returns {Promise.<{ success: boolean; status_code: string; }>} */ delete: (playlist_id) => Actions.engage(this, 'playlist/delete', { playlist_id }), @@ -553,6 +553,47 @@ class Innertube { return response.data.unseenCount; } + /** + * Retrieves lyrics for a given song if available. + * + * @param {string} video_id + * @returns {Promise.} Song lyrics + */ + async getLyrics(video_id) { + const continuation = await Actions.next(this, { video_id: video_id, ytmusic: true }); + if (!continuation.success) throw new Utils.InnertubeError('Could not retrieve lyrics', continuation); + + const lyrics_tab = Utils.findNode(continuation, 'contents', 'Lyrics', 8, false); + + const response = await Actions.browse(this, 'lyrics', { ytmusic: true, browse_id: lyrics_tab.endpoint?.browseEndpoint.browseId }); + if (!response.success || !response.data?.contents?.sectionListRenderer) throw new Utils.UnavailableContentError('Lyrics not available', { video_id }); + + const lyrics = Utils.findNode(response.data, 'contents', 'runs', 6, false); + return lyrics.runs[0].text; + } + + /** + * Parses a given playlist. + * + * @param {string} playlist_id - The id of the playlist. + * @param {object} options - { client: YOUTUBE | YTMUSIC } + * @param {string} options.client - Client used to parse the playlist, can be: `YTMUSIC` | `YOUTUBE` + * @returns {Promise.< + * { title: string; description: string; total_items: string; last_updated: string; views: string; items: [] } | + * { title: string; description: string; total_items: number; duration: string; year: string; items: [] }>} + */ + async getPlaylist(playlist_id, options = { client: 'YOUTUBE' }) { + const response = await Actions.browse(this, options.client == 'YTMUSIC' ? 'music_playlist' : 'playlist', { ytmusic: options.client == 'YTMUSIC', browse_id: `VL${playlist_id}` }); + if (!response.success) throw new Utils.InnertubeError('Could not get playlist', response); + + const playlist = new Parser(this, response.data, { + client: options.client, + data_type: 'PLAYLIST' + }).parse(); + + return playlist; + } + /** * Internal method to process and filter formats. * @@ -795,4 +836,4 @@ class Innertube { } } -module.exports = Innertube; +module.exports = Innertube; \ No newline at end of file