Skip to content

Instantly share code, notes, and snippets.

@trygveaa
Created May 14, 2014 22:25
Show Gist options
  • Save trygveaa/6fc0244290d94223d540 to your computer and use it in GitHub Desktop.
Save trygveaa/6fc0244290d94223d540 to your computer and use it in GitHub Desktop.
pyspotify: Fetch all albums of an artist
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))
@kingosticks
Copy link

Can you do album.is_available: if you have not first ensured the album is loaded? Particularly since NO_TRACKS will apparently only load album references.

@kingosticks
Copy 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