From e5b27fc24266ceff9b7ad0962d2e22da586f530f Mon Sep 17 00:00:00 2001 From: alix Date: Sun, 11 Oct 2020 17:34:03 +1100 Subject: [PATCH 1/2] Add check for whether to queue the currently playing album (close #78) Check if the album to be played is currently the same as the last album in the playlist. If so, this album should not be appended to the playlist, but instead we should just play the first track from the album. --- mcg/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mcg/client.py b/mcg/client.py index 7ef3028..35826e3 100644 --- a/mcg/client.py +++ b/mcg/client.py @@ -603,7 +603,10 @@ class Client(Base): def _play_album(self, album): - track_ids = self._queue_album(album) + if self._playlist and album == self._playlist[-1]._id: + track_ids = [self._playlist[-1].get_tracks()[0].get_id()] + else: + track_ids = self._queue_album(album) if track_ids: self._logger.info("play track %d", track_ids[0]) self._call('playid', track_ids[0]) From 3301c860f97ed63c54764b4ec11c12bc396ff241 Mon Sep 17 00:00:00 2001 From: alix Date: Mon, 12 Oct 2020 20:40:31 +1100 Subject: [PATCH 2/2] Moved check for avoiding duplicate tracks in the playlist Moved the check for whether queueing an album to the playlist will result in a duplicated album at the end of the playlist. This should appear in the _queue_album method, as it will also catch albums added to the playlist using the queue button in the gui. --- mcg/client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mcg/client.py b/mcg/client.py index 35826e3..6ae6b20 100644 --- a/mcg/client.py +++ b/mcg/client.py @@ -603,10 +603,7 @@ class Client(Base): def _play_album(self, album): - if self._playlist and album == self._playlist[-1]._id: - track_ids = [self._playlist[-1].get_tracks()[0].get_id()] - else: - track_ids = self._queue_album(album) + track_ids = self._queue_album(album) if track_ids: self._logger.info("play track %d", track_ids[0]) self._call('playid', track_ids[0]) @@ -614,6 +611,10 @@ class Client(Base): def _queue_album(self, album): track_ids = [] + # check whether the album to queue is already the last in the playlist + if self._playlist and self._playlist[-1] == self._albums[album]: + # return the first song in the album + return [self._playlist[-1].get_tracks()[0].get_id()] if album in self._albums: self._logger.info("add album %s", album) for track in self._albums[album].get_tracks():