Library

YTMusic.get_library_playlists(limit: int | None = 25) list[dict]

Retrieves the playlists in the user’s library.

Parameters:

limit – Number of playlists to retrieve. None retrieves them all.

Returns:

List of owned playlists.

Each item is in the following format:

{
    'playlistId': 'PLQwVIlKxHM6rz0fDJVv_0UlXGEWf-bFys',
    'title': 'Playlist title',
    'thumbnails: [...],
    'count': 5
}
YTMusic.get_library_songs(limit: int = 25, validate_responses: bool = False, order: Literal['a_to_z', 'z_to_a', 'recently_added'] | None = None) list[dict]

Gets the songs in the user’s library (liked videos are not included). To get liked songs and videos, use get_liked_songs()

Parameters:
  • limit – Number of songs to retrieve

  • validate_responses – Flag indicating if responses from YTM should be validated and retried in case when some songs are missing. Default: False

  • order – Order of songs to return. Allowed values: a_to_z, z_to_a, recently_added. Default: Default order.

Returns:

List of songs. Same format as get_playlist()

YTMusic.get_library_albums(limit: int = 25, order: Literal['a_to_z', 'z_to_a', 'recently_added'] | None = None) list[dict]

Gets the albums in the user’s library.

Parameters:
  • limit – Number of albums to return

  • order – Order of albums to return. Allowed values: a_to_z, z_to_a, recently_added. Default: Default order.

Returns:

List of albums.

Each item is in the following format:

{
  "browseId": "MPREb_G8AiyN7RvFg",
  "playlistId": "OLAK5uy_lKgoGvlrWhX0EIPavQUXxyPed8Cj38AWc",
  "title": "Beautiful",
  "type": "Album",
  "thumbnails": [...],
  "artists": [{
    "name": "Project 46",
    "id": "UCXFv36m62USAN5rnVct9B4g"
  }],
  "year": "2015"
}
YTMusic.get_library_artists(limit: int = 25, order: Literal['a_to_z', 'z_to_a', 'recently_added'] | None = None) list[dict]

Gets the artists of the songs in the user’s library.

Parameters:
  • limit – Number of artists to return

  • order – Order of artists to return. Allowed values: a_to_z, z_to_a, recently_added. Default: Default order.

Returns:

List of artists.

Each item is in the following format:

{
  "browseId": "UCxEqaQWosMHaTih-tgzDqug",
  "artist": "WildVibes",
  "subscribers": "2.91K",
  "thumbnails": [...]
}
YTMusic.get_library_subscriptions(limit: int = 25, order: Literal['a_to_z', 'z_to_a', 'recently_added'] | None = None) list[dict]

Gets the artists the user has subscribed to.

Parameters:
  • limit – Number of artists to return

  • order – Order of artists to return. Allowed values: a_to_z, z_to_a, recently_added. Default: Default order.

Returns:

List of artists. Same format as get_library_artists()

YTMusic.get_library_podcasts(limit: int = 25, order: Literal['a_to_z', 'z_to_a', 'recently_added'] | None = None) list[dict]

Get podcasts the user has added to the library

Parameters:
  • limit – Number of podcasts to return

  • order – Order of podcasts to return. Allowed values: a_to_z, z_to_a, recently_added. Default: Default order.

Returns:

List of podcasts. New Episodes playlist is the first podcast returned, but only if subscribed to relevant podcasts.

Example:

[
    {
        "title": "New Episodes",
        "channel":
        {
            "id": null,
            "name": "Auto playlist"
        },
        "browseId": "VLRDPN",
        "podcastId": "RDPN",
        "thumbnails": [...]
    },
    {
        "title": "5 Minuten Harry Podcast",
        "channel":
        {
            "id": "UCDIDXF4WM1qQzerrxeEfSdA",
            "name": "coldmirror"
        },
        "browseId": "MPSPPLDvBqWb1UAGeEt9n6vFH_zdGw65Obf3sH",
        "podcastId": "PLDvBqWb1UAGeEt9n6vFH_zdGw65Obf3sH",
        "thumbnails": [...]
    }
]
YTMusic.get_library_channels(limit: int = 25, order: Literal['a_to_z', 'z_to_a', 'recently_added'] | None = None) list[dict]

Get channels the user has added to the library

Parameters:
  • limit – Number of channels to return

  • order – Order of channels to return. Allowed values: a_to_z, z_to_a, recently_added. Default: Default order.

Returns:

List of channels.

Example:

[
    {
        "browseId": "UCRFF8xw5dg9mL4r5ryFOtKw",
        "artist": "Jumpers Jump",
        "subscribers": "1.54M",
        "thumbnails": [...]
    },
    {
        "browseId": "UCQ3f2_sO3NJyDkuCxCNSOVA",
        "artist": "BROWN BAG",
        "subscribers": "74.2K",
        "thumbnails": [...]
    }
]
YTMusic.get_liked_songs(limit: int = 100) dict

Gets playlist items for the ‘Liked Songs’ playlist

Parameters:

limit – How many items to return. Default: 100

Returns:

List of playlistItem dictionaries. See get_playlist()

YTMusic.get_saved_episodes(limit: int = 100) dict

Gets playlist items for the ‘Liked Songs’ playlist

Parameters:

limit – How many items to return. Default: 100

Returns:

List of playlistItem dictionaries. See get_playlist()

YTMusic.get_history() list[dict]

Gets your play history in reverse chronological order

Returns:

List of playlistItems, see get_playlist() The additional property played indicates when the playlistItem was played The additional property feedbackToken can be used to remove items with remove_history_items()

YTMusic.add_history_item(song)

Add an item to the account’s history using the playbackTracking URI obtained from get_song(). A 204 return code indicates success.

Usage:

song = yt_auth.get_song(videoId)
response = yt_auth.add_history_item(song)

Note

You need to use the same YTMusic instance as you used for get_song().

Parameters:

song – Dictionary as returned by get_song()

Returns:

Full response. response.status_code is 204 if successful

YTMusic.remove_history_items(feedbackTokens: list[str]) dict

Remove an item from the account’s history. This method does currently not work with brand accounts

Parameters:

feedbackTokens – Token to identify the item to remove, obtained from get_history()

Returns:

Full response

YTMusic.rate_song(videoId: str, rating: str = 'INDIFFERENT') dict | None

Rates a song (“thumbs up”/”thumbs down” interactions on YouTube Music)

Parameters:
  • videoId – Video id

  • rating

    One of LIKE, DISLIKE, INDIFFERENT

    INDIFFERENT removes the previous rating and assigns no rating

Returns:

Full response

YTMusic.edit_song_library_status(feedbackTokens: list[str] | None = None) dict

Adds or removes a song from your library depending on the token provided.

Parameters:

feedbackTokens – List of feedbackTokens obtained from authenticated requests to endpoints that return songs (i.e. get_album())

Returns:

Full response

YTMusic.rate_playlist(playlistId: str, rating: str = 'INDIFFERENT') dict

Rates a playlist/album (“Add to library”/”Remove from library” interactions on YouTube Music) You can also dislike a playlist/album, which has an effect on your recommendations

Parameters:
  • playlistId – Playlist id

  • rating

    One of LIKE, DISLIKE, INDIFFERENT

    INDIFFERENT removes the playlist/album from the library

Returns:

Full response

YTMusic.subscribe_artists(channelIds: list[str]) dict

Subscribe to artists. Adds the artists to your library

Parameters:

channelIds – Artist channel ids

Returns:

Full response

YTMusic.unsubscribe_artists(channelIds: list[str]) dict

Unsubscribe from artists. Removes the artists from your library

Parameters:

channelIds – Artist channel ids

Returns:

Full response

YTMusic.get_account_info() dict

Gets information about the currently authenticated user’s account.

Returns:

Dictionary with user’s account name, channel handle, and URL of their account photo.

Example:

{
    "accountName": "Sample User",
    "channelHandle": "@SampleUser
    "accountPhotoUrl": "https://yt3.ggpht.com/sample-user-photo"
}