query live overlay data from mpd for display

This commit is contained in:
Sundog Jones 2020-07-20 18:42:57 -07:00
parent f186281a6e
commit aa7201fc2a

View File

@ -5,6 +5,7 @@ from glob import glob
import struct
import smbus
import sys
import musicpd
class SoundslabDisplay:
def __init__(self):
@ -23,8 +24,12 @@ class SoundslabDisplay:
self.current_menu = Image.new("RGBA", self.screen_size, (0, 0, 0, 0))
self.fg_color = (255, 255, 255, 211)
self.bg_color = (0, 0, 0, 78)
# set up connection to mpd here - TODO: this belongs elsewhere and should be passed or pulled in
self.player_client = musicpd.MPDClient()
self.player_client.connect()
def updateOverlay(self, current_track_number, total_track_number, battery_level_percent, track_progress_percent):
def updateOverlay(self, battery_level_percent):
# initialize overlay
im_overlay = Image.new("RGBA", self.screen_size, (0, 0, 0, 0))
font = ImageFont.truetype(font='/usr/share/fonts/truetype/hack/Hack-Bold.ttf', size=18)
@ -36,6 +41,12 @@ class SoundslabDisplay:
overlay.rectangle([(0, 20), (20, self.screen_size[1] - 20)], self.bg_color) # left bar
overlay.rectangle([(self.screen_size[0] - 20, 20), (self.screen_size[0], self.screen_size[1] - 20)], self.bg_color) # right bar
# get status from mpd
current_status = self.player_client.status()
current_track_number = int(current_status['song']) + 1
total_track_number = current_status['playlistlength']
track_progress_percent = float(current_status['elapsed']) / float(current_status['duration'])
print("track progress:" + str(track_progress_percent))
# add track # / total #
track_and_queue = str(current_track_number) + " of " + str(total_track_number)
overlay.text((10, 0), track_and_queue, font=font, fill=self.fg_color)
@ -46,11 +57,17 @@ class SoundslabDisplay:
# add progress meter
overlay.rectangle([(10, self.screen_size[1] - 15), (self.screen_size[0] - 10, self.screen_size[1] - 5)], fill=(0, 0, 0, 0), outline=self.fg_color, width=1)
overlay.rectangle([(10, self.screen_size[1] - 15), (int((self.screen_size[0] - 20) * (track_progress_percent / 100)) + 10, self.screen_size[1] - 5)], fill=self.fg_color, outline=self.fg_color, width=1)
overlay.rectangle([(10, self.screen_size[1] - 15), (int((self.screen_size[0] - 20) * track_progress_percent) + 10, self.screen_size[1] - 5)], fill=self.fg_color, outline=self.fg_color, width=1)
self.current_overlay = im_overlay.copy()
def updateAlbumArt(self, cover_image_file):
def updateAlbumArt(self):
current_status = self.player_client.status()
song_data = self.player_client.playlistid(current_status['songid'])
print(song_data[0]['file'])
path_info = song_data[0]['file'].split('/')
print(path_info)
cover_image_file = '/media/usb0/' + path_info[0] + '/' + path_info[1] + '/cover.jpg'
im = Image.open(cover_image_file).convert("RGBA")
image = im.resize(self.screen_size)
self.current_background = image.copy()