Working prototype of cover downloader
This commit is contained in:
49
cover.py
Normal file
49
cover.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from PIL import Image
|
||||
import ST7789 as ST7789
|
||||
import urllib2 as urllib
|
||||
import requests
|
||||
import io
|
||||
|
||||
# My music server URL
|
||||
url = "http://192.168.0.114:6680/mopidy/rpc"
|
||||
|
||||
# Define the display
|
||||
disp = ST7789.ST7789(
|
||||
port=0,
|
||||
cs=ST7789.BG_SPI_CS_FRONT,
|
||||
dc=9,
|
||||
backlight=13,
|
||||
spi_speed_hz=80 * 1000 * 1000,
|
||||
)
|
||||
|
||||
|
||||
# First request fetches the current track info
|
||||
js1 = { "method": "core.playback.get_current_track", "jsonrpc": "2.0", "params": {}, "id": 1 }
|
||||
js2 = requests.post(url, json=js1)
|
||||
uri = js2.json()['result']['uri']
|
||||
|
||||
# Second request gets the url for the cover image
|
||||
js3 = { "method": "core.library.get_images", "jsonrpc": "2.0", "params": { "uris": [uri] }, "id": 1}
|
||||
js4 = requests.post(url, json=js3)
|
||||
cover = js4.json()['result'].values()[0][0]['uri']
|
||||
|
||||
fd = urllib.urlopen(cover)
|
||||
image_file = io.BytesIO(fd.read())
|
||||
|
||||
WIDTH = disp.width
|
||||
HEIGHT = disp.height
|
||||
|
||||
# Initialize display.
|
||||
disp.begin()
|
||||
|
||||
# Load an image.
|
||||
print('Loading image: {}...'.format(image_file))
|
||||
image = Image.open(image_file)
|
||||
|
||||
# Resize the image
|
||||
image = image.resize((WIDTH, HEIGHT))
|
||||
|
||||
# Draw the image on the display hardware.
|
||||
print('Drawing image')
|
||||
|
||||
disp.display(image)
|
||||
Reference in New Issue
Block a user