Variables
Const parsePlaylist
parsePlaylist: (...input: T) => R = utils.parser((response: any, playlistId: string) => {const header = response.header.musicDetailHeaderRenderer? response.header.musicDetailHeaderRenderer: response.header.musicEditablePlaylistDetailHeaderRenderer.header.musicDetailHeaderRendererconst playlist: Playlist = {title: header.title.runs[0],thumbnail:header.thumbnail.croppedSquareThumbnailRenderer.thumbnail.thumbnails,playlistId,content: [],subtitle: header.subtitle.runs,secondSubtitle: header.secondSubtitle.runs}return playlist})
Const parsePlaylistContents
parsePlaylistContents: (...input: T) => R = utils.parser((contents: any, playlistId: string, limit: number | undefined) => {const content: Song[] = []for (let i = 0; i < contents.length; ++i) {const e = contents[i].musicResponsiveListItemRendererif (limit && i > limit - 1) breakconst song = parseSong(e, playlistId)if (song) {content.push(song)}}return content})
Const parseSong
parseSong: (...input: T) => R = utils.parser((e: any, playlistId: string) => {const primaryTextRun =e.flexColumns[0].musicResponsiveListItemFlexColumnRenderer.text.runs[0]const id = primaryTextRun?.navigationEndpoint?.watchEndpoint?.videoIdif (!id) {// NOTE: It is apparently possible to have items that don't have an ID!// The Web UI renders them as disabled, and the only available action is to// remove them from the playlist. For now, we will wimply omit them from// results, since having an optional ID would be quite a breaking changereturn}return {id,duration:e.fixedColumns[0].musicResponsiveListItemFixedColumnRenderer.text.runs[0].text,thumbnail: e.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails,title: primaryTextRun,author:e.flexColumns[1].musicResponsiveListItemFlexColumnRenderer.text.runs,album:e.flexColumns[2].musicResponsiveListItemFlexColumnRenderer.text.runs?.[0],url: `https://music.youtube.com/watch?v=${id}&list=${playlistId}`} as Song})
Add song(s) to playlist
const api = new YTMUSIC(cookie) const data = await api.addToPlaylist(['-mLpe7KUg9U', '5hFevwJ4JXI'], 'RDAMVM5hFevwJ4JXI')