2023-11-26 23:49:33 -05:00
|
|
|
import asyncio
|
|
|
|
from os import environ
|
|
|
|
|
|
|
|
from corefoundationasyncio import CoreFoundationEventLoop
|
|
|
|
|
|
|
|
from .cocoa import CocoaNowPlaying
|
|
|
|
from .mpd.listener import MpdStateListener
|
|
|
|
|
|
|
|
|
|
|
|
async def listen() -> None:
|
2023-12-05 19:42:50 -05:00
|
|
|
port = int(environ.get("MPD_PORT", "6600"))
|
|
|
|
host = environ.get("MPD_HOST", "localhost")
|
|
|
|
password = environ.get("MPD_PASSWORD")
|
|
|
|
if password is None and "@" in host:
|
|
|
|
password, host = host.split("@", maxsplit=1)
|
|
|
|
|
2023-11-26 23:49:33 -05:00
|
|
|
listener = MpdStateListener()
|
|
|
|
now_playing = CocoaNowPlaying(listener)
|
2023-12-05 19:54:28 -05:00
|
|
|
await listener.start(host=host, port=port, password=password)
|
2023-11-26 23:49:33 -05:00
|
|
|
await listener.loop(now_playing)
|
|
|
|
|
|
|
|
|
|
|
|
def make_loop() -> CoreFoundationEventLoop:
|
|
|
|
return CoreFoundationEventLoop(console_app=True)
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
asyncio.run(listen(), loop_factory=make_loop, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|