]> kaliko git repositories - mpd-sima.git/commitdiff
More robust MPD client (start addressing #53)
authorkaliko <kaliko@azylum.org>
Mon, 5 Jul 2021 08:19:58 +0000 (10:19 +0200)
committerkaliko <kaliko@azylum.org>
Mon, 5 Jul 2021 08:19:58 +0000 (10:19 +0200)
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

index 4e6af68f37ec2614b71f3114da9746d56ae85af8..ebf39a787c6be6905a7bd2f1fdca023ed21a6a26 100644 (file)
@@ -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: