mpd-now-playable/src/mpd_now_playable/cli.py

33 lines
809 B
Python
Raw Normal View History

import asyncio
from os import environ
from corefoundationasyncio import CoreFoundationEventLoop
from .cocoa import CocoaNowPlaying
from .mpd.listener import MpdStateListener
async def listen() -> None:
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)
listener = MpdStateListener()
now_playing = CocoaNowPlaying(listener)
await listener.start(hostname=host, port=port, password=password)
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()