Created
May 14, 2014 22:25
-
-
Save trygveaa/6fc0244290d94223d540 to your computer and use it in GitHub Desktop.
pyspotify: Fetch all albums of an artist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spotify | |
import threading | |
logged_in_event = threading.Event() | |
def connection_state_listener(session): | |
if session.connection.state is spotify.ConnectionState.LOGGED_IN: | |
logged_in_event.set() | |
session = spotify.Session() | |
session.on( | |
spotify.SessionEvent.CONNECTION_STATE_UPDATED, | |
connection_state_listener) | |
username = input('Username: ') | |
password = input('Password: ') | |
session.login(username, password) | |
while not logged_in_event.wait(0.1): | |
session.process_events() | |
artistname = input('Artist: ') | |
search = session.search('artist:"{0}"'.format(artistname)) | |
search.load() | |
artist = search.artists[0] | |
artistbrowse = artist.browse(type=spotify.ArtistBrowserType.NO_TRACKS) | |
artistbrowse.load() | |
print("Albums by {0} ({1}):".format(artist.name, artist.link)) | |
for album in artistbrowse.albums: | |
if album.is_available: | |
print("\t{0} ({1}) ({2})".format(album.name, album.year, album.link)) |
Oh, it seems you can. my bad. (it's not 'just references', but everything except tracks).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you do
album.is_available:
if you have not first ensured the album is loaded? Particularly sinceNO_TRACKS
will apparently only load album references.