Skip to content

Instantly share code, notes, and snippets.

@ashwinreddy
Created January 21, 2017 22:02
Show Gist options
  • Save ashwinreddy/a490f0d935e78d002ec7809c420e517e to your computer and use it in GitHub Desktop.
Save ashwinreddy/a490f0d935e78d002ec7809c420e517e to your computer and use it in GitHub Desktop.
Retrieves Spotify album image
import urllib2
import urllib
import json
music_type = raw_input("Track or Album? [t/a] ")
if music_type.startswith('t'):
music_type = 0
elif music_type.startswith('a'):
music_type = 1
uri = raw_input('Paste Spotify URI: ')
if uri.startswith('spotify'):
uri = uri.split(':')[2]
url = "https://api.spotify.com/v1/"
if music_type == 0:
url += "tracks/"
elif music_type == 1:
url += "albums/"
response = json.load(urllib2.urlopen(url + uri))
if music_type == 0:
img = response["album"]["images"][0]["url"]
elif music_type == 1:
img = response["images"][0]["url"]
print img
urllib.urlretrieve(img, "image.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment