Compare commits
2 commits
8ad255856e
...
37166e146d
Author | SHA1 | Date | |
---|---|---|---|
37166e146d | |||
9d965567e6 |
4 changed files with 18 additions and 6 deletions
|
@ -6,7 +6,7 @@ from ..async_tools import run_background_task
|
||||||
from ..cache import Cache, make_cache
|
from ..cache import Cache, make_cache
|
||||||
from .types import CurrentSongResponse, MpdStateHandler
|
from .types import CurrentSongResponse, MpdStateHandler
|
||||||
|
|
||||||
CACHE_TTL = 60 * 60 # seconds = 1 hour
|
CACHE_TTL = 60 * 60 # seconds = 1 hour
|
||||||
|
|
||||||
|
|
||||||
class ArtCacheEntry(TypedDict):
|
class ArtCacheEntry(TypedDict):
|
||||||
|
@ -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:
|
||||||
|
|
|
@ -95,6 +95,19 @@ 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:
|
||||||
|
try:
|
||||||
|
albumart = await self.client.albumart(file)
|
||||||
|
return albumart.get("binary")
|
||||||
|
except CommandError:
|
||||||
|
return None
|
||||||
|
|
||||||
async def readpicture(self, file: str) -> bytes | None:
|
async def readpicture(self, file: str) -> bytes | None:
|
||||||
try:
|
try:
|
||||||
readpic = await self.client.readpicture(file)
|
readpic = await self.client.readpicture(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"]
|
||||||
|
|
|
@ -13,6 +13,7 @@ class MPDClient(MPDClientBase):
|
||||||
def idle(self, subsystems: Sequence[str] = ...) -> AsyncIterator[Sequence[str]]: ...
|
def idle(self, subsystems: Sequence[str] = ...) -> AsyncIterator[Sequence[str]]: ...
|
||||||
async def status(self) -> types.StatusResponse: ...
|
async def status(self) -> types.StatusResponse: ...
|
||||||
async def currentsong(self) -> types.CurrentSongResponse: ...
|
async def currentsong(self) -> types.CurrentSongResponse: ...
|
||||||
|
async def albumart(self, uri: str) -> types.ReadPictureResponse: ...
|
||||||
async def readpicture(self, uri: str) -> types.ReadPictureResponse: ...
|
async def readpicture(self, uri: str) -> types.ReadPictureResponse: ...
|
||||||
async def play(self) -> None: ...
|
async def play(self) -> None: ...
|
||||||
async def pause(self, pause: Literal[1, 0, None] = None) -> None:
|
async def pause(self, pause: Literal[1, 0, None] = None) -> None:
|
||||||
|
|
Loading…
Reference in a new issue