From e684e20d8d72f49d5fdaf69c58cdd4aa0e4980be Mon Sep 17 00:00:00 2001 From: kaliko Date: Mon, 5 Jul 2021 10:19:58 +0200 Subject: [PATCH] More robust MPD client (start addressing #53) This actually closes the issue but I believe the client does not currently detect half-opened connection, for instance router reboot|crash|host roaming. --- sima/mpdclient.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 4e6af68..ebf39a7 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -115,9 +115,12 @@ class MPD(MPDClient): def __getattr__(self, cmd): """Wrapper around MPDClient calls for abstract overriding""" track_wrapped = {'currentsong', 'find', 'playlistinfo', } - if cmd in track_wrapped: - return tracks_wrapper(super().__getattr__(cmd)) - return super().__getattr__(cmd) + try: + if cmd in track_wrapped: + return tracks_wrapper(super().__getattr__(cmd)) + return super().__getattr__(cmd) + except OSError as err: + raise PlayerError(err) def disconnect(self): """Overriding explicitly MPDClient.disconnect()""" @@ -226,10 +229,7 @@ class MPD(MPDClient): * skipped current track skipped """ curr = self.current - try: - ret = self.idle('database', 'playlist', 'player', 'options') - except (PlayerError, OSError) as err: - raise PlayerError("Couldn't init idle: %s" % err) + ret = self.idle('database', 'playlist', 'player', 'options') if self._skipped_track(curr): ret.append('skipped') if 'database' in ret: -- 2.39.5