Last active
October 13, 2020 15:52
-
-
Save sinanatra/7e01674d1aa28196408d9def6753ef6e to your computer and use it in GitHub Desktop.
spotify raspberry led
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import argparse | |
from luma.led_matrix.device import max7219 | |
from luma.core.interface.serial import spi, noop | |
from luma.core.legacy import show_message | |
from luma.core.legacy.font import proportional, CP437_FONT | |
import spotipy | |
import spotipy.util as util | |
import types | |
def output(n, block_orientation, rotate, inreverse, text): | |
serial = spi(port=0, device=0, gpio=noop()) | |
device = max7219(serial, width=64, height=8, block_orientation=-90) | |
show_message(device, text, fill="white", font=proportional(CP437_FONT), scroll_delay=0.05) | |
time.sleep(1) | |
def current_user_recently_played(self, limit=50): | |
return self._get('me/player/currently-playing', limit=limit) | |
token = util.prompt_for_user_token( | |
username="sinanatra", | |
scope="user-read-recently-played user-read-private user-top-read user-read-currently-playing", | |
client_id = 'c2c70abbacf7442789011e4321b3a66d', | |
client_secret='df21241c9fc64d6e8ffdbaf8fb419cda', | |
redirect_uri="http://example.com/") | |
spotify = spotipy.Spotify(auth = token) | |
spotify.current_user_recently_played = types.MethodType(current_user_recently_played, spotify) | |
def currentlyPlaying(): | |
playing = spotify.current_user_recently_played() | |
song = playing['item']['name'] | |
artists = playing['item']['album']['artists'] | |
artistList = '' | |
for j in range(0, len(artists)): | |
artistList += artists[j]['name'] + ' ' | |
text = song + ' by: ' + artistList | |
return text | |
while True: | |
text = currentlyPlaying() | |
print(text) | |
output(1, 0, 0, False, str(text)) | |
time.sleep(20) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment