From: kaliko Date: Mon, 5 Jul 2021 08:19:58 +0000 (+0200) Subject: More robust MPD client (start addressing #53) X-Git-Tag: 0.18.0~26 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=e684e20d8d72f49d5fdaf69c58cdd4aa0e4980be;p=mpd-sima.git 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. --- 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: