diff --git a/src/core/Music.ts b/src/core/Music.ts index 025fb2c1..635748c9 100644 --- a/src/core/Music.ts +++ b/src/core/Music.ts @@ -23,9 +23,8 @@ import SingleColumnMusicWatchNextResults from '../parser/classes/SingleColumnMus import TabbedSearchResults from '../parser/classes/TabbedSearchResults'; import WatchNextTabbedResults from '../parser/classes/WatchNextTabbedResults'; import TwoColumnBrowseResults from '../parser/classes/TwoColumnBrowseResults'; -import SectionList from '../parser/classes/SectionList'; - import NavigationEndpoint from '../parser/classes/NavigationEndpoint'; +import SectionList from '../parser/classes/SectionList'; import { InnertubeError, throwIfMissing } from '../utils/Utils'; @@ -108,29 +107,29 @@ class Music { const response = await this.#actions.next({ video_id, client: 'YTMUSIC' }); const data = Parser.parseResponse(response.data); - + const tabs = data.contents.item() .as(SingleColumnMusicWatchNextResults).contents.item() .as(Tabbed).contents.item() .as(WatchNextTabbedResults) .tabs.array().as(Tab); - + const tab = tabs.get({ title: 'Lyrics' })?.as(Tab); - + if (!tab) throw new InnertubeError('Could not find target tab.'); - + const page = await tab.endpoint.call(this.#actions, 'YTMUSIC', true); - + if (!page) throw new InnertubeError('Could not retrieve tab contents, the given id may be invalid or is not a song.'); - + if (page.contents.item().key('type').string() === 'Message') throw new InnertubeError(page.contents.item().as(Message).text, video_id); - + const section_list = page.contents.item().as(SectionList).contents.array(); const description_shelf = section_list.firstOfType(MusicDescriptionShelf); - + return { text: description_shelf?.description.toString(), footer: description_shelf?.footer @@ -146,25 +145,25 @@ class Music { const response = await this.#actions.next({ video_id, client: 'YTMUSIC' }); const data = Parser.parseResponse(response.data); - + const tabs = data.contents.item() .as(SingleColumnMusicWatchNextResults).contents.item() .as(Tabbed).contents.item() .as(WatchNextTabbedResults) .tabs.array().as(Tab); - + const tab = tabs.get({ title: 'Up next' })?.as(Tab); - + if (!tab) throw new InnertubeError('Could not find target tab.'); - + const music_queue = tab.content.item().as(MusicQueue); - + if (!music_queue.content) throw new InnertubeError('Music queue was empty, the given id is probably invalid.', music_queue); - + const playlist_panel = music_queue.content.item().as(PlaylistPanel); - + return playlist_panel; }