2020-12-19 20:13:22 +00:00
|
|
|
import sys
|
|
|
|
import spotipy
|
|
|
|
import spotipy.util as util
|
2020-12-19 20:34:44 +00:00
|
|
|
import config as cfg
|
2020-12-19 20:13:22 +00:00
|
|
|
from PIL import Image
|
2020-12-19 21:32:34 +00:00
|
|
|
import asyncio
|
2020-12-19 21:08:07 +00:00
|
|
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
2020-12-19 21:41:21 +00:00
|
|
|
import threading
|
2020-12-19 20:13:22 +00:00
|
|
|
import requests
|
|
|
|
from io import BytesIO
|
2020-12-19 21:42:40 +00:00
|
|
|
import time
|
2020-12-19 21:53:29 +00:00
|
|
|
import urllib.request import urlretrieve
|
2020-12-19 21:51:17 +00:00
|
|
|
|
2020-12-19 20:13:22 +00:00
|
|
|
|
2020-12-19 20:34:44 +00:00
|
|
|
client_id = cfg.client_id
|
|
|
|
client_secret = cfg.client_secret
|
|
|
|
redirect_uri = cfg.redirect_uri
|
|
|
|
username = cfg.username
|
2020-12-19 20:13:22 +00:00
|
|
|
|
|
|
|
scope = 'user-read-currently-playing'
|
|
|
|
|
2020-12-19 21:08:07 +00:00
|
|
|
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
|
2020-12-19 21:09:02 +00:00
|
|
|
screen = RGBMatrix(options = options) #pygame.display.set_mode(self.size, self.flags)
|
2020-12-19 21:08:07 +00:00
|
|
|
|
2020-12-19 20:13:22 +00:00
|
|
|
|
2020-12-19 20:34:44 +00:00
|
|
|
|
|
|
|
token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
|
2020-12-19 20:13:22 +00:00
|
|
|
|
2020-12-19 21:39:56 +00:00
|
|
|
def get_track():
|
2020-12-19 21:44:06 +00:00
|
|
|
print('getting info')
|
2020-12-19 20:13:22 +00:00
|
|
|
sp = spotipy.Spotify(auth=token)
|
2020-12-19 20:52:10 +00:00
|
|
|
track = sp.currently_playing()
|
|
|
|
print(track['is_playing'])
|
2020-12-19 20:13:22 +00:00
|
|
|
print(track['item']['name'] + ' - ' + track['item']['artists'][0]['name'])
|
2020-12-19 21:46:29 +00:00
|
|
|
print('getting image')
|
2020-12-19 21:53:06 +00:00
|
|
|
urlretrieve(track['item']['album']['images'][0]['url'], 'thumbnail.jpg')
|
2020-12-19 21:50:24 +00:00
|
|
|
#imageString = requests.get(track['item']['album']['images'][0]['url'])
|
2020-12-19 21:53:06 +00:00
|
|
|
image = Image.open('thumbnail.jpg')
|
2020-12-19 21:46:29 +00:00
|
|
|
print('resizing image')
|
2020-12-19 20:13:22 +00:00
|
|
|
image = image.resize((32,32))
|
2020-12-19 21:46:29 +00:00
|
|
|
#return image
|
2020-12-19 21:13:19 +00:00
|
|
|
#image.save("thumbnail.jpg","JPEG")
|
2020-12-19 21:43:23 +00:00
|
|
|
print('set image')
|
2020-12-19 21:50:24 +00:00
|
|
|
screen.SetImage(image.convert('RGB'))
|
2020-12-19 21:46:29 +00:00
|
|
|
print('image set')
|
2020-12-19 21:27:06 +00:00
|
|
|
|
|
|
|
#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:
|
2020-12-19 20:13:22 +00:00
|
|
|
print("Can't get token for", username)
|
2020-12-19 21:39:56 +00:00
|
|
|
def main():
|
2020-12-19 21:44:48 +00:00
|
|
|
x = threading.Thread(target=get_track)
|
|
|
|
x.start()
|
2020-12-19 21:39:56 +00:00
|
|
|
|
2020-12-19 21:36:09 +00:00
|
|
|
|
2020-12-19 21:29:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-12-19 21:39:56 +00:00
|
|
|
main()
|
|
|
|
print('text')
|
2020-12-19 21:42:40 +00:00
|
|
|
while True:
|
|
|
|
time.sleep(10)
|
|
|
|
print('timed')
|
|
|
|
|
2020-12-19 21:39:56 +00:00
|
|
|
|
|
|
|
|