Try both readpicture and albumart, prefer the former

This commit is contained in:
Danielle McLean 2024-05-17 10:18:54 +10:00
parent 569372d4e2
commit fd7866ed14
Signed by: 00dani
GPG key ID: 6854781A0488421C
3 changed files with 10 additions and 6 deletions

View file

@ -49,7 +49,7 @@ class MpdArtworkCache:
return None return None
async def cache_artwork(self, song: CurrentSongResponse) -> None: async def cache_artwork(self, song: CurrentSongResponse) -> None:
art = ArtCacheEntry(data=await self.mpd.readpicture(song["file"])) art = ArtCacheEntry(data=await self.mpd.get_art(song["file"]))
try: try:
await self.album_cache.add(calc_album_key(song), art, ttl=CACHE_TTL) await self.album_cache.add(calc_album_key(song), art, ttl=CACHE_TTL)
except ValueError: except ValueError:

View file

@ -95,6 +95,12 @@ class MpdStateListener(Player):
print(song) print(song)
listener.update(song) listener.update(song)
async def get_art(self, file: str) -> bytes | None:
picture = await self.readpicture(file)
if picture:
return picture
return await self.albumart(file)
async def albumart(self, file: str) -> bytes | None: async def albumart(self, file: str) -> bytes | None:
try: try:
albumart = await self.client.albumart(file) albumart = await self.client.albumart(file)

View file

@ -2,11 +2,9 @@ from typing import Literal, NotRequired, Protocol, TypedDict
class MpdStateHandler(Protocol): class MpdStateHandler(Protocol):
async def readpicture(self, file: str) -> bytes | None: async def get_art(self, file: str) -> bytes | None: ...
...
async def refresh(self) -> None: async def refresh(self) -> None: ...
...
BooleanFlag = Literal["0", "1"] BooleanFlag = Literal["0", "1"]