From d6409a4f0fc96ece23aa441516e21a85418fa3b7 Mon Sep 17 00:00:00 2001 From: kaliko Date: Sun, 3 Mar 2024 14:13:28 +0100 Subject: [PATCH] Swith more MPD command to asyncio --- mpdaio/client.py | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/mpdaio/client.py b/mpdaio/client.py index 65e1497..a8ae0cd 100644 --- a/mpdaio/client.py +++ b/mpdaio/client.py @@ -251,7 +251,6 @@ class CmdHandler: retval = self._commands[command] await self._write_command(command, args) if callable(retval): - log.debug('retvat: %s', retval) return await retval() return retval @@ -270,7 +269,7 @@ class CmdHandler: parts.append(f'"{escape(str(arg))}"') if '\n' in ' '.join(parts): raise MPDCommandError('new line found in the command!') - #log.debug(' '.join(parts)) + log.debug(' '.join(parts)) await self._write_line(' '.join(parts)) def _read_binary(self, amount): @@ -334,7 +333,7 @@ class CmdHandler: yield value async def _read_playlist(self): - for _, value in await self._read_pairs(":"): + async for _, value in self._read_pairs(":"): yield value async def _read_objects(self, delimiters=None): @@ -357,13 +356,13 @@ class CmdHandler: if obj: yield obj - def _read_command_list(self): + async def _read_command_list(self): try: for retval in self._command_list: yield retval() finally: self._command_list = None - self._fetch_nothing() + await self._fetch_nothing() async def _fetch_nothing(self): line = await self._read_line() @@ -379,8 +378,8 @@ class CmdHandler: async def _fetch_list(self): return [_ async for _ in self._read_list()] - def _fetch_playlist(self): - return self._read_playlist() + async def _fetch_playlist(self): + return [_ async for _ in self._read_pairs(':')] async def _fetch_object(self): objs = [obj async for obj in self._read_objects()] @@ -391,32 +390,32 @@ class CmdHandler: async def _fetch_objects(self, delimiters): return [_ async for _ in self._read_objects(delimiters)] - def _fetch_changes(self): - return self._fetch_objects(["cpos"]) + async def _fetch_changes(self): + return await self._fetch_objects(["cpos"]) async def _fetch_songs(self): return await self._fetch_objects(["file"]) - def _fetch_playlists(self): - return self._fetch_objects(["playlist"]) + async def _fetch_playlists(self): + return await self._fetch_objects(["playlist"]) - def _fetch_database(self): - return self._fetch_objects(["file", "directory", "playlist"]) + async def _fetch_database(self): + return await self._fetch_objects(["file", "directory", "playlist"]) - def _fetch_outputs(self): - return self._fetch_objects(["outputid"]) + async def _fetch_outputs(self): + return await self._fetch_objects(["outputid"]) - def _fetch_plugins(self): - return self._fetch_objects(["plugin"]) + async def _fetch_plugins(self): + return await self._fetch_objects(["plugin"]) - def _fetch_messages(self): - return self._fetch_objects(["channel"]) + async def _fetch_messages(self): + return await self._fetch_objects(["channel"]) - def _fetch_mounts(self): - return self._fetch_objects(["mount"]) + async def _fetch_mounts(self): + return await self._fetch_objects(["mount"]) - def _fetch_neighbors(self): - return self._fetch_objects(["neighbor"]) + async def _fetch_neighbors(self): + return await self._fetch_objects(["neighbor"]) async def _fetch_composite(self): obj = {} @@ -445,5 +444,5 @@ class CmdHandler: await self._read_line(binary=True) return obj - def _fetch_command_list(self): - return self._read_command_list() + async def _fetch_command_list(self): + return [_ async for _ in self._read_command_list()] -- 2.39.5