Closed tarrant33 closed 5 months ago
Can you post a code snippet? And just so you know, you can use a codeblock in comments like this:
```python3
<paste in your code here>
.```
Just remove the dot at the end, that's just so I can post this with correct formatting
import os
import time
from spotipy.oauth2 import SpotifyOAuth
from PIL import Image, ImageDraw, ImageFont
import spotipy
from rgbmatrix import RGBMatrix, RGBMatrixOptions
SPOTIPY_CLIENT_ID = 'xxx'
SPOTIPY_CLIENT_SECRET = 'xxx'
SPOTIPY_REDIRECT_URI = 'http://localhost:8080/callback'
# Initialize Spotipy with your credentials
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=os.environ['SPOTIPY_CLIENT_ID'],
client_secret=os.environ['SPOTIPY_CLIENT_SECRET'],
redirect_uri=os.environ['SPOTIPY_REDIRECT_URI'],
scope="user-library-read user-read-currently-playing"))
# Initialize RGB matrix display with your provided options
options = RGBMatrixOptions()
options.rows = 64 # Number of rows (64 pixels)
options.cols = 64 # Number of columns (64 pixels)
options.chain_length = 2 # 2 chains
matrix = RGBMatrix(options=options)
# Set up custom font
font_directory = "fonts"
font_filename = "04B_03__.TTF"
font_path = os.path.join(font_directory, font_filename)
font = ImageFont.truetype(font_path, size=8)
while True:
# Get currently playing track information
current_track = sp.current_playback()
if current_track is not None and 'item' in current_track:
track_name = current_track['item']['name']
album_name = current_track['item']['album']['name']
artist_name = current_track['item']['artists'][0]['name']
album_image_url = current_track['item']['album']['images'][0]['url']
# Load and resize the album image
album_image = Image.open(album_image_url)
album_image = album_image.resize((40, 40))
# Create a blank image for displaying information
display = Image.new('RGB', (64, 64), color=(0, 0, 0))
draw = ImageDraw.Draw(display)
# Paste the resized album image on the left side
display.paste(album_image, (0, 0))
# Draw track name, album name, and artist name using custom font
draw.text((45, 0), track_name, fill=(255, 255, 255), font=font)
draw.text((45, 15), album_name, fill=(255, 255, 255), font=font)
draw.text((45, 30), artist_name, fill=(255, 255, 255), font=font)
# Display the information on the RGB matrix
matrix.Clear()
matrix.SetImage(display, 0, 0)
time.sleep(10) # Display the information for 10 seconds
time.sleep(5) # Poll for currently playing track every 5 seconds
Hm, can't really figure out where the "Permission denied" comes from. The other error seems to be caused by you trying to stop the script. But it would probably work with sudo.
If you want, try to debug your script and go through line by line until you get the error again.
Any updates?
Closing as there is no activity or reply from the author.
I try running some code for a test but keep getting below errors. Im new to python and using raspberry pi
any help or insight would be greatly appreciated