Browse Source

fix: Working album art

Matthias Ladkau 4 years ago
parent
commit
0daec7d50e
2 changed files with 37 additions and 17 deletions
  1. 37 17
      musikautomat/display.py
  2. BIN
      musikautomat/web/background/purple.jpg

+ 37 - 17
musikautomat/display.py

@@ -6,6 +6,8 @@ import yaml
 import pygame # type: ignore
 from typing import Dict
 import random
+import eyed3
+import tempfile
 
 # Color constants
 
@@ -100,33 +102,51 @@ class Display:
         '''
         Beautify the display.
         '''
-        font = pygame.font.Font('freesansbold.ttf', self._fontsize)
-
-        # Draw a background image
-
-        if self._bgImg is None:
-            bg = os.listdir("web/background")
-            bg = bg[random.randint(0, len(bg)-1)]
-            self._bgImg = pygame.image.load(os.path.join("web/background", bg))
-            pygame.transform.scale(self._bgImg, (self._dx, 50))
-
-        self._pydsp.blit(self._bgImg, (0,0), (0, 0, self._dx, 50))
+        font = pygame.font.Font('freesansbold.ttf', 10)
 
         path = item.get("path")
         title = item.get("name", "")
         artist = item.get("artist", "")
+        album = item.get("album", "")
+        date = item.get("date", "")
 
         # Try to extract meta data
 
-        if path is not None:
-            pass
+        if path is not None and os.path.isfile(path):
+            f = eyed3.load(path)
+            title = f.tag.title
+            artist = f.tag.artist
+            album = f.tag.album
+            if f.tag.best_release_date:
+                date = str(f.tag.best_release_date)
+
+            # Load album art
+
+            for i in f.tag.images:
+                with tempfile.TemporaryFile() as f:
+                    f.write(i.image_data)
+                    f.seek(0)
+                    i = pygame.image.load(f)
+
+                i = pygame.transform.scale(i, (50, 50))
+                self._pydsp.blit(i, (0,0), (0, 0, self._dx, 50))
+
+                break
+
+        text = font.render(title, True, WHITE, BLACK)
+        self._pydsp.blit(text, (50, 0))
 
-        s = title
         if artist != "":
-            s = "%s (%s)" % (s, artist)
+            text = font.render(artist, True, WHITE, BLACK)
+            self._pydsp.blit(text, (50, 10))
+
+        if album != "":
+            text = font.render(album, True, WHITE, BLACK)
+            self._pydsp.blit(text, (50, 20))
 
-        text = font.render(s, True, WHITE, BLACK)
-        self._pydsp.blit(text, (0, 38))
+        if date != "":
+            text = font.render(date, True, WHITE, BLACK)
+            self._pydsp.blit(text, (50, 30))
 
 
     def currentItem(self) -> Dict:

BIN
musikautomat/web/background/purple.jpg