This commit is contained in:
Lukas Schulz 2020-12-19 21:13:22 +01:00
parent 39b75b7717
commit ff3268eb04

31
main.py Normal file
View file

@ -0,0 +1,31 @@
import sys
import spotipy
import spotipy.util as util
from PIL import Image
import requests
from io import BytesIO
scope = 'user-read-currently-playing'
if len(sys.argv) > 1:
username = sys.argv[1]
else:
print("Usage: %s username" % (sys.argv[0],))
sys.exit()
token = util.prompt_for_user_token(username, scope)
if token:
sp = spotipy.Spotify(auth=token)
track = sp.current_user_playing_track()
print(track['item']['name'] + ' - ' + track['item']['artists'][0]['name'])
imageString = requests.get(track['item']['album']['images'][0]['url'])
image = Image.open(BytesIO(imageString.content))
image = image.resize((32,32))
image.save("thumbnail.jpg","JPEG")
else:
print("Can't get token for", username)