From e1497033f890e738bdd95e74f5ec4fb9586863c8 Mon Sep 17 00:00:00 2001 From: kaliko Date: Sun, 3 May 2020 15:42:05 +0200 Subject: [PATCH] Fixed bug in PlayerClient().search_albums() search_albums method was ignoring some albums when Artist object had aliases. --- doc/Changelog | 3 +++ sima/client.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index fc30791..48b711b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,9 @@ MPD_sima v0.15.3 UNRELEASED * Improve HTTP client (use persistent connection) + * Fixed a serious bug in PlayerClient().search_albums() + "search_albums" method was ignoring some albums when Artist object had + aliases. -- kaliko jack diff --git a/sima/client.py b/sima/client.py index 40842ba..d10a3fe 100644 --- a/sima/client.py +++ b/sima/client.py @@ -272,23 +272,29 @@ class PlayerClient(Player): def search_albums(self, artist): """ Fetch all albums for "AlbumArtist" == artist - Filter albums returned for "artist" == artist since MPD returns any - album containing at least a single track for artist + Then look for albums for "artist" == artist and try to filters + multi-artists albums + + NB: Running "client.list('album', 'artist', name)" MPD returns any album + containing at least a track with "artist" == name + TODO: Use MusicBrainzID here cf. #30 @gitlab """ albums = [] for name in artist.names: - if len(artist.names) > 1: + if artist.aliases: self.log.debug('Searching album for aliase: "%s"', name) kwalbart = {'albumartist':name, 'artist':name} - for album in self.list('album', 'albumartist', artist): + for album in self.list('album', 'albumartist', name): if album and album not in albums: albums.append(Album(name=album, **kwalbart)) - for album in self.list('album', 'artist', artist): + for album in self.list('album', 'artist', name): album_trks = [trk for trk in self.find('album', album)] if 'Various Artists' in [tr.albumartist for tr in album_trks]: self.log.debug('Discarding %s ("Various Artists" set)', album) continue arts = set([trk.artist for trk in album_trks]) + # Avoid selecting album where artist is credited for a single + # track of the album if len(set(arts)) < 2: # TODO: better heuristic, use a ratio instead if album not in albums: albums.append(Album(name=album, **kwalbart)) -- 2.39.5