58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
import sys
|
|
import spotipy
|
|
import spotipy.util as util
|
|
import config as cfg
|
|
from PIL import Image
|
|
|
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
|
|
|
import requests
|
|
from io import BytesIO
|
|
|
|
client_id = cfg.client_id
|
|
client_secret = cfg.client_secret
|
|
redirect_uri = cfg.redirect_uri
|
|
username = cfg.username
|
|
|
|
scope = 'user-read-currently-playing'
|
|
|
|
options = RGBMatrixOptions()
|
|
options.rows = 32
|
|
options.cols = 64
|
|
options.chain_length = 6
|
|
options.parallel = 2
|
|
options.hardware_mapping = 'regular'
|
|
options.pixel_mapper_config = 'U-mapper'
|
|
options.limit_refresh_rate_hz = 240
|
|
options.gpio_slowdown = 4
|
|
screen = RGBMatrix(options = options) #pygame.display.set_mode(self.size, self.flags)
|
|
|
|
|
|
|
|
token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
|
|
|
|
async def get_track():
|
|
sp = spotipy.Spotify(auth=token)
|
|
track = sp.currently_playing()
|
|
print(track['is_playing'])
|
|
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))
|
|
return image
|
|
#image.save("thumbnail.jpg","JPEG")
|
|
|
|
#if token:
|
|
# sp = spotipy.Spotify(auth=token)
|
|
# track = sp.currently_playing()
|
|
# print(track['is_playing'])
|
|
# 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)
|
|
while(True):
|
|
screen.SetImage(await get_track().convert('RGB'))
|
|
print("Text")
|