led-matrix-player/main.py
2020-12-19 21:13:22 +01:00

31 lines
752 B
Python

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)