Refactor Cocoa stuff into a 'receiver'

The idea here is that there are other places that might want to know
what's playing, besides MPNowPlayingInfoCenter. For example, to expose
the now playing info to Übersicht efficiently, it needs to be available
from a web browser, ideally using WebSockets. So there could be a
receiver that runs a small WebSockets server and sends out now playing
info to anyone who connects.

Additionally, I hope to write receivers for MPRIS and for the System
Media Transport Controls on Windows, making mpd-now-playable equally
useful across all platforms.

None of this is implemented yet, of course, but I hope to get the
WebSockets receiver done pretty soon!

I'm going to keep the default behaviour unchanged. Unless you
explicitly configure different receivers in config.toml,
mpd-now-playable will just behave as an MPNowPlayingInfoCenter
integration as it's always done.
This commit is contained in:
Danielle McLean 2024-07-09 12:52:49 +10:00
parent 27d8c37139
commit 00ba34bd0b
Signed by: 00dani
GPG key ID: 6854781A0488421C
12 changed files with 214 additions and 38 deletions

View file

@ -1,10 +1,33 @@
from dataclasses import dataclass, field
from typing import Optional
from typing import Annotated, Literal, Optional, Protocol
from pydantic import Field
from ..tools.schema.define import schema
from .fields import Host, Password, Port, Url
__all__ = ("MpdConfig", "Config")
__all__ = (
"Config",
"MpdConfig",
"BaseReceiverConfig",
"CocoaReceiverConfig",
)
class BaseReceiverConfig(Protocol):
@property
def kind(self) -> str: ...
@dataclass(slots=True)
class CocoaReceiverConfig(BaseReceiverConfig):
kind: Literal["cocoa"] = "cocoa"
ReceiverConfig = Annotated[
CocoaReceiverConfig,
Field(discriminator="kind"),
]
@dataclass(slots=True)
@ -27,3 +50,4 @@ class Config:
#: protocols are memory://, redis://, and memcached://.
cache: Optional[Url] = None
mpd: MpdConfig = field(default_factory=MpdConfig)
receivers: tuple[ReceiverConfig, ...] = (CocoaReceiverConfig(),)