Playlists

Warning

The playlists API was broken at 2018-05-24 by a server-side change made by Spotify. The functionality was never restored.

Please use the Spotify Web API to work with playlists.

class spotify.Playlist(session, uri=None, sp_playlist=None, add_ref=True)[source]

A Spotify playlist.

You can get playlists from the playlist_container, inbox, get_starred(), search(), etc., or you can create a playlist yourself from a Spotify URI:

>>> session = spotify.Session()
# ...
>>> playlist = session.get_playlist(
...     'spotify:user:fiat500c:playlist:54k50VZdvtnIPt4d8RBCmZ')
>>> playlist.load().name
u'500C feelgood playlist'
class spotify.PlaylistEvent[source]

Playlist events.

Using Playlist objects, you can register listener functions to be called when various events occurs in the playlist. This class enumerates the available events and the arguments your listener functions will be called with.

Example usage:

import spotify

def tracks_added(playlist, tracks, index):
    print('Tracks added to playlist')

session = spotify.Session()
# Login, etc...

playlist = session.playlist_container[0]
playlist.on(spotify.PlaylistEvent.TRACKS_ADDED, tracks_added)

All events will cause debug log statements to be emitted, even if no listeners are registered. Thus, there is no need to register listener functions just to log that they’re called.

class spotify.PlaylistContainer(session, sp_playlistcontainer, add_ref=True)[source]

A Spotify playlist container.

The playlist container can be accessed as a regular Python collection to work with the playlists:

>>> import spotify
>>> session = spotify.Session()
# Login, etc.
>>> container = session.playlist_container
>>> container.is_loaded
False
>>> container.load()
[Playlist(u'spotify:user:jodal:playlist:6xkJysqhkj9uwufFbUb8sP'),
 Playlist(u'spotify:user:jodal:playlist:0agJjPcOhHnstLIQunJHxo'),
 PlaylistFolder(id=8027491506140518932L, name=u'Shared playlists',
    type=<PlaylistType.START_FOLDER: 1>),
 Playlist(u'spotify:user:p3.no:playlist:7DkMndS2KNVQuf2fOpMt10'),
 PlaylistFolder(id=8027491506140518932L, name=u'',
    type=<PlaylistType.END_FOLDER: 2>)]
>>> container[0]
Playlist(u'spotify:user:jodal:playlist:6xkJysqhkj9uwufFbUb8sP')

As you can see, a playlist container can contain a mix of Playlist and PlaylistFolder objects.

The container supports operations that changes the container as well.

To add a playlist you can use append() or insert() with either the name of a new playlist or an existing playlist object. For example:

>>> playlist = session.get_playlist(
...     'spotify:user:fiat500c:playlist:54k50VZdvtnIPt4d8RBCmZ')
>>> container.insert(3, playlist)
>>> container.append('New empty playlist')

To remove a playlist or folder you can use remove_playlist(), or:

>>> del container[0]

To replace an existing playlist or folder with a new empty playlist with the given name you can use remove_playlist() and add_new_playlist(), or:

>>> container[0] = 'My other new empty playlist'

To replace an existing playlist or folder with an existing playlist you can :use remove_playlist() and add_playlist(), or:

>>> container[0] = playlist
class spotify.PlaylistContainerEvent[source]

Playlist container events.

Using PlaylistContainer objects, you can register listener functions to be called when various events occurs in the playlist container. This class enumerates the available events and the arguments your listener functions will be called with.

Example usage:

import spotify

def container_loaded(playlist_container):
    print('Playlist container loaded')

session = spotify.Session()
# Login, etc...

session.playlist_container.on(
    spotify.PlaylistContainerEvent.CONTAINER_LOADED, container_loaded)

All events will cause debug log statements to be emitted, even if no listeners are registered. Thus, there is no need to register listener functions just to log that they’re called.

class spotify.PlaylistFolder(id, name, type)[source]

An object marking the start or end of a playlist folder.

id

An opaque ID that matches the ID of the PlaylistFolder object at the other end of the folder.

name

Name of the playlist folder. This is an empty string for the END_FOLDER.

type

The PlaylistType of the folder. Either START_FOLDER or END_FOLDER.

class spotify.PlaylistOfflineStatus(value)[source]
class spotify.PlaylistPlaceholder[source]

An object marking an unknown entry in the playlist container.

class spotify.PlaylistTrack(session, sp_playlist, index)[source]

A playlist track with metadata specific to the playlist.

Use tracks_with_metadata to get a list of PlaylistTrack.

class spotify.PlaylistType(value)[source]
class spotify.PlaylistUnseenTracks(session, sp_playlistcontainer, sp_playlist)[source]

A list of unseen tracks in a playlist.

The list may contain items that are None.

Returned by PlaylistContainer.get_unseen_tracks().