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:
parent
27d8c37139
commit
00ba34bd0b
12 changed files with 214 additions and 38 deletions
|
|
@ -1,30 +1,41 @@
|
|||
import asyncio
|
||||
from collections.abc import Iterable
|
||||
|
||||
from corefoundationasyncio import CoreFoundationEventLoop
|
||||
from rich import print
|
||||
|
||||
from .__version__ import __version__
|
||||
from .cocoa.now_playing import CocoaNowPlaying
|
||||
from .config.load import loadConfig
|
||||
from .config.model import Config
|
||||
from .mpd.listener import MpdStateListener
|
||||
from .song_receiver import (
|
||||
Receiver,
|
||||
choose_loop_factory,
|
||||
import_receiver,
|
||||
)
|
||||
|
||||
|
||||
async def listen() -> None:
|
||||
print(f"mpd-now-playable v{__version__}")
|
||||
config = loadConfig()
|
||||
print(config)
|
||||
listener = MpdStateListener(config.cache)
|
||||
now_playing = CocoaNowPlaying(listener)
|
||||
async def listen(
|
||||
config: Config, listener: MpdStateListener, receiver_types: Iterable[type[Receiver]]
|
||||
) -> None:
|
||||
await listener.start(config.mpd)
|
||||
await listener.loop(now_playing)
|
||||
|
||||
|
||||
def make_loop() -> CoreFoundationEventLoop:
|
||||
return CoreFoundationEventLoop(console_app=True)
|
||||
receivers = (rec(listener, config) for rec in receiver_types)
|
||||
await listener.loop(receivers)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
asyncio.run(listen(), loop_factory=make_loop, debug=True)
|
||||
print(f"mpd-now-playable v{__version__}")
|
||||
config = loadConfig()
|
||||
print(config)
|
||||
|
||||
listener = MpdStateListener(config.cache)
|
||||
receiver_types = tuple(import_receiver(rec) for rec in config.receivers)
|
||||
|
||||
factory = choose_loop_factory(receiver_types)
|
||||
asyncio.run(
|
||||
listen(config, listener, receiver_types),
|
||||
loop_factory=factory.make_loop,
|
||||
debug=True,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue