From fe55526cbc6015c4268ee155f21bcb11de5609b5 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 13 Nov 2026 13:06:56 +0100 Subject: feat(music): covers for embedded art and videos Haruna sends an embedded audio cover inline as a data:image URL, which the module dropped, and clears mpris:artUrl for every video on purpose so the task manager shows the live window. Serve both at /api/music/image/: the data URL decoded, a local video as one ffmpeg frame (thumbnail filter, 480 px wide), made on first request and kept until the track changes. Only the current track's key answers, so the tablet names a key, never a path. Co-Authored-By: Claude Opus 5.5 --- tests/test_music.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/test_music.py b/tests/test_music.py index fe603cb..878c5f8 100644 --- a/tests/test_music.py +++ b/tests/test_music.py @@ -49,6 +49,28 @@ class Music(unittest.TestCase): st = music.make({"run": fake}).state() self.assertAlmostEqual(st["length"], 65.82, places=2) + def _state(self, art, url, frame=None): + out = "\x1f".join(["Playing", "t", "", "", "1", "0", art, "haruna", url]) + fake = lambda cmd, timeout=2: {"metadata": out, "get-volume": ""}[cmd[1]] + m = music.make({"run": fake, "frame": frame or (lambda path: b"")}) + return m, m.state() + + def test_embedded_cover_served_decoded(self): + m, st = self._state("data:image/png;base64,aGVsbG8=", "file:///a/song.flac") + key = st["art"].rsplit("/", 1)[1] + self.assertEqual(m.image(key), (b"hello", "image/png")) + self.assertIsNone(m.image("other")) + + def test_video_gets_a_frame(self): + paths = [] + m, st = self._state("", "file:///v/a%20clip.mp4", + lambda path: paths.append(path) or b"jpeg") + self.assertEqual(m.image(st["art"].rsplit("/", 1)[1]), (b"jpeg", "image/jpeg")) + self.assertEqual(paths, ["/v/a clip.mp4"]) + + def test_audio_without_cover_has_no_art(self): + self.assertIsNone(self._state("", "file:///a/song.flac")[1]["art"]) + def test_action_commands(self): self.assertEqual(music.BASE_ACTIONS["next"], ["playerctl", "next"]) -- cgit v1.2.3