Tracks

class spotify.Track(session, uri=None, sp_track=None, add_ref=True)[source]

A Spotify track.

You can get tracks from playlists or albums, or you can create a Track yourself from a Spotify URI:

>>> session = spotify.Session()
# ...
>>> track = session.get_track('spotify:track:2Foc5Q5nqNiosCNqttzHof')
>>> track.load().name
u'Get Lucky'
is_loaded

Whether the track’s data is loaded.

error

An ErrorType associated with the track.

Check to see if there was problems loading the track.

load(timeout=None)[source]

Block until the track’s data is loaded.

After timeout seconds with no results Timeout is raised. If timeout is None the default timeout is used.

The method returns self to allow for chaining of calls.

offline_status

The TrackOfflineStatus of the track.

The metadata_updated callback is called when the offline status changes.

Will always return None if the track isn’t loaded.

availability

The TrackAvailability of the track.

Will always return None if the track isn’t loaded.

is_local

Whether the track is a local track.

Will always return None if the track isn’t loaded.

is_autolinked

Whether the track is a autolinked to another track.

Will always return None if the track isn’t loaded.

See playable.

playable

The actual track that will be played when this track is played.

Will always return None if the track isn’t loaded.

See is_autolinked.

is_placeholder

Whether the track is a placeholder for a non-track object in the playlist.

To convert to the real object:

>>> session = spotify.Session()
# ...
>>> track = session.get_track(
...     'spotify:track:2Foc5Q5nqNiosCNqttzHof')
>>> track.load()
>>> track.is_placeholder
True
>>> track.link.type
<LinkType.ARTIST: ...>
>>> artist = track.link.as_artist()

Will always return None if the track isn’t loaded.

starred

Whether the track is starred by the current user.

Set to True or False to change.

Will always be None if the track isn’t loaded.

artists

The artists performing on the track.

Will always return an empty list if the track isn’t loaded.

album

The album of the track.

Will always return None if the track isn’t loaded.

name

The track’s name.

Will always return None if the track isn’t loaded.

duration

The track’s duration in milliseconds.

Will always return None if the track isn’t loaded.

popularity

The track’s popularity in the range 0-100, 0 if undefined.

Will always return None if the track isn’t loaded.

disc

The track’s disc number. 1 or higher.

Will always return None if the track isn’t part of an album or artist browser.

index

The track’s index number. 1 or higher.

Will always return None if the track isn’t part of an album or artist browser.

A Link to the track.

A Link to the track with an offset in milliseconds into the track.

class spotify.TrackAvailability[source]
AVAILABLE = <TrackAvailability.AVAILABLE: 1>
BANNED_BY_ARTIST = <TrackAvailability.BANNED_BY_ARTIST: 3>
NOT_STREAMABLE = <TrackAvailability.NOT_STREAMABLE: 2>
UNAVAILABLE = <TrackAvailability.UNAVAILABLE: 0>
class spotify.TrackOfflineStatus[source]
DONE = <TrackOfflineStatus.DONE: 3>
DONE_EXPIRED = <TrackOfflineStatus.DONE_EXPIRED: 5>
DONE_RESYNC = <TrackOfflineStatus.DONE_RESYNC: 7>
DOWNLOADING = <TrackOfflineStatus.DOWNLOADING: 2>
ERROR = <TrackOfflineStatus.ERROR: 4>
LIMIT_EXCEEDED = <TrackOfflineStatus.LIMIT_EXCEEDED: 6>
NO = <TrackOfflineStatus.NO: 0>
WAITING = <TrackOfflineStatus.WAITING: 1>