Use the same environment variables as mpc does

This commit is contained in:
Danielle McLean 2023-12-06 11:42:50 +11:00
parent 9ff488d807
commit 095c099a38
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
3 changed files with 13 additions and 11 deletions

View file

@ -8,13 +8,15 @@ 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=environ.get("MPD_HOSTNAME", "localhost"),
port=int(environ.get("MPD_PORT", "6600")),
password=environ.get("MPD_PASSWORD"),
)
await listener.start(hostname=host, port=port, password=password)
await listener.loop(now_playing)

View file

@ -46,10 +46,10 @@ class MpdStateListener(Player):
self.art_cache = MpdArtworkCache(self)
async def start(
self, hostname: str = "localhost", port: int = 6600, password: str | None = None
self, host: str = "localhost", port: int = 6600, password: str | None = None
) -> None:
print(f"Connecting to MPD server {hostname}:{port}...")
await self.client.connect(hostname, port)
print(f"Connecting to MPD server {host}:{port}...")
await self.client.connect(host, port)
if password is not None:
print("Authorising to MPD with your password...")
await self.client.password(password)