youtube-music-ts-api • Docs
youtube-music-ts-api • Docs
Defines the main YouTube Music API object. Using this object, you can either choose to make calls as a guest or an authenticated user. Not all APIs are available as a guest, so it is preferred to authenticate the user if possible.
authenticate(
cookiesStr
,authUser
):Promise
<IYouTubeMusicAuthenticated
>
Authenticates the user with the YouTube Music API. This function overload requies the cookie string of a valid logged in user.
• cookiesStr: string
The cookie string of a valid logged in user. To obtain this cookie value, log into https://music.youtube.com as a user and use your browser's developer tools to obtain the "cookie" value sent as a request header. Extra values in the cookie will be ignored.
• authUser: number
X-Goog-AuthUser header value
Promise
<IYouTubeMusicAuthenticated
>
A promise that will yield authenticated access to the YouTube Music API.
guest():
Promise
<IYouTubeMusicGuest
>
Provides guest access to the YouTube Music API. Only non-restrictive APIs (such as public playlists) are available to guests.
Promise
<IYouTubeMusicGuest
>
A promise that will yield guest access to the YouTube Music API.
youtube-music-ts-api • Docs
Defines the YouTube Music APIs available to an authenticated user. An authenticated user also naturally includes the APIs available to a guest.
addTracksToPlaylist(
playlistId
, ...tracks
):Promise
<boolean
>
Adds the tracks to the specified playlist.
• playlistId: string
The ID of the playlist to add the tracks to.
• ...tracks: ITrackDetail
[]
The array of tracks to add to the playlist.
Promise
<boolean
>
A promise that will yield whether or not the operation was successful.
createPlaylist(
name
,description
?,privacy
?,sourcePlaylistId
?):Promise
<IPlaylistSummary
>
Creates a playlist in the user's library.
• name: string
The name of the playlist to create.
• description?: string
An optional description for the playlist.
• privacy?: string
An optional privacy level for the playlist (either PUBLIC, PRIVATE, or UNLISTED).
• sourcePlaylistId?: string
An optional playlist ID to copy the initial set of tracks from.
Promise
<IPlaylistSummary
>
A promise that will yield the playlist with its ID.
deletePlaylist(
playlistId
):Promise
<boolean
>
Deletes a playlist from the user's library.
• playlistId: string
The ID of the playlist to delete.
Promise
<boolean
>
A promise that will yield whether or not the operation was successful.
getAlbum(
id
):Promise
<IAlbumDetail
>
Gets detailed information for a specific album.
• id: string
The ID of the album to get the detailed information for.
Promise
<IAlbumDetail
>
A promise that will yield the detailed information for a specific album.
getLibraryAlbums():
Promise
<IAlbumSummary
[]>
Gets all the albums in the user's library.
Promise
<IAlbumSummary
[]>
A promise that will yield an array of all the albums in the user's library.
getLibraryArtists():
Promise
<IArtistSummary
[]>
Gets all the artists in the user's library.
Promise
<IArtistSummary
[]>
A promise that will yield an array of all the artists in the user's library.
getLibraryHistory():
Promise
<IPlaylistDetail
>
Gets recently played tracks, in reverse chronological order, from the user's library
Promise
<IPlaylistDetail
>
A promise that will yield a playlist with detailed information on a recently played tracks.
getLibraryPlaylists():
Promise
<IPlaylistSummary
[]>
Gets all the playlists in the user's library.
Promise
<IPlaylistSummary
[]>
A promise that will yield an array of all the playlists in the user's library.
getLibraryTracks():
Promise
<ITrackDetail
[]>
Gets all the tracks in the user's library.
Promise
<ITrackDetail
[]>
A promise that will yield an array of all the tracks in the user's library.
getPlaylist(
id
,maxRetries
?):Promise
<IPlaylistDetail
>
Gets detailed information for a specific playlist.
• id: string
The ID of the playlist to get the detailed information for.
• maxRetries?: number
An optional maximum number of retries to obtain the tracks. YouTube Music is incredibly buggy in that not all tracks will be returned in a single request. If the request is retried, you may get a different set of tracks in the response. If you retry enough times, you will eventually get all the tracks (a union operation is done internally between all the tracks returned from each individual request).
Promise
<IPlaylistDetail
>
A promise that will yield the detailed information for a specific playlist.
IYouTubeMusicGuest
.getPlaylist
moveTrackWithinPlaylist(
playlistId
,trackToMove
,trackToMoveBefore
?):Promise
<boolean
>
Moves the specified track within the playlist.
• playlistId: string
The ID of the playlist to move the track within.
• trackToMove: ITrackDetail
The track that should be moved.
• trackToMoveBefore?: ITrackDetail
An optional track to move the track before. If unspecified, the track will be moved to the end of the playlist.
Promise
<boolean
>
A promise that will yield whether or not the operation was successful.
rateTrack(
trackId
,rating
):Promise
<boolean
>
Rates a track ("thumbs up"/"thumbs down" interaction).
• trackId: string
The ID of the track to rate.
• rating: "LIKE"
| "DISLIKE"
| "INDIFFERENT"
One of 'LIKE', 'DISLIKE', or 'INDIFFERENT'. 'INDIFFERENT' removes the previous rating and assigns no rating.
Promise
<boolean
>
A promise that will yield whether or not the operation was successful.
removeTracksFromPlaylist(
playlistId
, ...tracks
):Promise
<boolean
>
Removes the tracks from the specified playlist.
• playlistId: string
The ID of the playlist to remove the tracks from.
• ...tracks: ITrackDetail
[]
The array of tracks to remove from the playlist.
Promise
<boolean
>
A promise that will yield whether or not the operation was successful.
youtube-music-ts-api • Docs
Defines the YouTube Music APIs available to a guest.
getAlbum(
id
):Promise
<IAlbumDetail
>
Gets detailed information for a specific album.
• id: string
The ID of the album to get the detailed information for.
Promise
<IAlbumDetail
>
A promise that will yield the detailed information for a specific album.
getPlaylist(
id
,maxRetries
?):Promise
<IPlaylistDetail
>
Gets detailed information for a specific playlist.
• id: string
The ID of the playlist to get the detailed information for.
• maxRetries?: number
An optional maximum number of retries to obtain the tracks. YouTube Music is incredibly buggy in that not all tracks will be returned in a single request. If the request is retried, you may get a different set of tracks in the response. If you retry enough times, you will eventually get all the tracks (a union operation is done internally between all the tracks returned from each individual request).
Promise
<IPlaylistDetail
>
A promise that will yield the detailed information for a specific playlist.
youtube-music-ts-api • Docs
youtube-music-ts-api • Docs
Defines the details for an album.
optional
artists:IArtistSummary
[]
The artist(s) that composed the album.
interfaces-supplementary.ts:33
optional
count:number
The count of tracks within the album.
interfaces-supplementary.ts:23
optional
description:string
The description of the album.
interfaces-supplementary.ts:18
optional
durationMillis:number
The duration of the album in milliseconds.
interfaces-supplementary.ts:28
optional
id:string
The ID of the album.
optional
name:string
The name of the album.
interfaces-supplementary.ts:13
optional
releaseDay:number
The day the album was released.
interfaces-supplementary.ts:38
optional
releaseMonth:number
The month the album was released.
interfaces-supplementary.ts:43
optional
releaseYear:number
The year the album was released.
interfaces-supplementary.ts:48
tracks:
ITrackDetail
[]
The array of tracks within the album.
interfaces-supplementary.ts:53
youtube-music-ts-api • Docs
Defines an album summary.
optional
artist:IArtistSummary
The artist that composed the album.
interfaces-supplementary.ts:73
optional
id:string
The ID of the album.
interfaces-supplementary.ts:63
optional
name:string
The name of the album.
interfaces-supplementary.ts:68
optional
year:string
The year the album was released.
interfaces-supplementary.ts:78
youtube-music-ts-api • Docs
Defines an artist summary.
optional
id:string
The ID of the artist.
interfaces-supplementary.ts:88
optional
name:string
The name of the artist.
interfaces-supplementary.ts:93
youtube-music-ts-api • Docs
Defines the details for a playlist.
optional
count:number
The count of tracks within the playlist.
interfaces-supplementary.ts:118
optional
description:string
The description of the playlist.
interfaces-supplementary.ts:113
optional
id:string
The ID of the playlist.
interfaces-supplementary.ts:103
optional
name:string
The name of the playlist.
interfaces-supplementary.ts:108
optional
privacy:string
The privacy level of the playlist. This value will be PUBLIC, PRIVATE, or UNLISTED.
interfaces-supplementary.ts:123
optional
tracks:ITrackDetail
[]
The array of tracks within the playlist.
interfaces-supplementary.ts:128
youtube-music-ts-api • Docs
Defines a playlist summary.
optional
count:number
The count of tracks within the playlist.
interfaces-supplementary.ts:148
optional
id:string
The ID of the playlist.
interfaces-supplementary.ts:138
optional
name:string
The name of the playlist.
interfaces-supplementary.ts:143
optional
thumbnails:IThumbnail
[]
The thumbnails for the playlist (ordered from smallest to largest).
interfaces-supplementary.ts:153
youtube-music-ts-api • Docs
Defines the details for a thumbnail.
optional
height:number
The height of the thumbnail.
interfaces-supplementary.ts:229
optional
url:string
The URL for the thumbnail.
interfaces-supplementary.ts:219
optional
width:number
The width of the thumbnail.
interfaces-supplementary.ts:224
youtube-music-ts-api • Docs
Defines the details for a track.
optional
album:IAlbumSummary
The album the track is from.
interfaces-supplementary.ts:184
optional
alternateId:string
An alternate ID of the track. YouTube internally refers to this value as the setVideoId. This ID is used in combination with the standard ID in order to remove tracks from playlists.
interfaces-supplementary.ts:169
optional
artists:IArtistSummary
[]
The artist(s) that compose the track.
interfaces-supplementary.ts:179
optional
duration:string
The duration of the track as a readable string.
interfaces-supplementary.ts:189
optional
durationMillis:number
The duration of the track in milliseconds.
interfaces-supplementary.ts:194
optional
id:string
The ID of the track.
interfaces-supplementary.ts:163
optional
likeStatus:"LIKE"
|"DISLIKE"
|"INDIFFERENT"
The rating for the track (LIKE, DISLIKE, or INDIFFERENT).
interfaces-supplementary.ts:209
optional
thumbnails:IThumbnail
[]
The thumbnails for the track (ordered from smallest to largest).
interfaces-supplementary.ts:204
optional
title:string
The title of the track.
interfaces-supplementary.ts:174
optional
trackNumber:number
The track number within an album.