From c1b05226a93cf526407927317f06b959560fda2e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 10 Jan 2019 01:28:12 +0100 Subject: [PATCH] Made the mpd backend a bit more resiliant --- platypush/backend/http/static/js/music.mpd.js | 4 ++++ platypush/backend/music/mpd/__init__.py | 12 ++++++++---- platypush/message/event/music/__init__.py | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/platypush/backend/http/static/js/music.mpd.js b/platypush/backend/http/static/js/music.mpd.js index 3fc9bf92f..36ccf4dfc 100644 --- a/platypush/backend/http/static/js/music.mpd.js +++ b/platypush/backend/http/static/js/music.mpd.js @@ -230,6 +230,10 @@ $(document).ready(function() { }; var updatePlaylist = function(tracks) { + if (tracks == null) { + return; + } + var $playlistContent = $('#playlist-content'); $playlistContent.find('.playlist-track').remove(); diff --git a/platypush/backend/music/mpd/__init__.py b/platypush/backend/music/mpd/__init__.py index 3275877ce..28c762c27 100644 --- a/platypush/backend/music/mpd/__init__.py +++ b/platypush/backend/music/mpd/__init__.py @@ -66,10 +66,11 @@ class MusicMpdBackend(Backend): state = status['state'].lower() playlist = status['playlist'] success = True - except StopIteration: - pass except Exception as e: self.logger.debug(e) + if not state: state = last_state + if not playlist: playlist = last_playlist + if not track: track = last_track finally: time.sleep(self.poll_seconds) @@ -83,8 +84,11 @@ class MusicMpdBackend(Backend): if playlist != last_playlist: if last_playlist: - changes = plugin.plchanges(last_playlist).output - self.bus.post(PlaylistChangeEvent(changes=changes)) + # XXX plchanges can become heavy with big playlists, + # PlaylistChangeEvent temporarily disabled + # changes = plugin.plchanges(last_playlist).output + # self.bus.post(PlaylistChangeEvent(changes=changes)) + self.bus.post(PlaylistChangeEvent()) last_playlist = playlist if state == 'play' and track != last_track: diff --git a/platypush/message/event/music/__init__.py b/platypush/message/event/music/__init__.py index d1ebc39d8..72f449b47 100644 --- a/platypush/message/event/music/__init__.py +++ b/platypush/message/event/music/__init__.py @@ -93,7 +93,7 @@ class PlaylistChangeEvent(MusicEvent): Event fired upon playlist change """ - def __init__(self, changes, status=None, track=None, *args, **kwargs): + def __init__(self, changes=None, status=None, track=None, *args, **kwargs): """ :param changes: List with the tracks being added or removed :type changes: list