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
Trackyourself from a Spotify URI:>>> session = spotify.Session() # ... >>> track = session.get_track('spotify:track:2Foc5Q5nqNiosCNqttzHof') >>> track.load().name u'Get Lucky'
-
property
is_loaded¶ Whether the track’s data is loaded.
-
property
error¶ An
ErrorTypeassociated 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
timeoutseconds with no resultsTimeoutis raised. IftimeoutisNonethe default timeout is used.The method returns
selfto allow for chaining of calls.
-
property
offline_status¶ The
TrackOfflineStatusof the track.The
metadata_updatedcallback is called when the offline status changes.Will always return
Noneif the track isn’t loaded.
-
property
availability¶ The
TrackAvailabilityof the track.Will always return
Noneif the track isn’t loaded.
-
property
is_local¶ Whether the track is a local track.
Will always return
Noneif the track isn’t loaded.
-
property
is_autolinked¶ Whether the track is a autolinked to another track.
Will always return
Noneif the track isn’t loaded.See
playable.
-
property
playable¶ The actual track that will be played when this track is played.
Will always return
Noneif the track isn’t loaded.See
is_autolinked.
-
property
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
Noneif the track isn’t loaded.
-
property
starred¶ Whether the track is starred by the current user.
Set to
TrueorFalseto change.Will always be
Noneif the track isn’t loaded.
-
property
artists¶ The artists performing on the track.
Will always return an empty list if the track isn’t loaded.
-
property
album¶ The album of the track.
Will always return
Noneif the track isn’t loaded.
-
property
name¶ The track’s name.
Will always return
Noneif the track isn’t loaded.
-
property
duration¶ The track’s duration in milliseconds.
Will always return
Noneif the track isn’t loaded.
-
property
popularity¶ The track’s popularity in the range 0-100, 0 if undefined.
Will always return
Noneif the track isn’t loaded.
-
property
disc¶ The track’s disc number. 1 or higher.
Will always return
Noneif the track isn’t part of an album or artist browser.
-
property
index¶ The track’s index number. 1 or higher.
Will always return
Noneif the track isn’t part of an album or artist browser.
-
property