X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Fmpdclient.py;h=c2560ae9dc28c7b446f07ac0bde7d217983c4d92;hb=1b77e7b6b9e1200e769765200accba84f0ef2f39;hp=82c6dbb505e2fc40a008fb2b2b87024497733834;hpb=5f1dd8bdf50cd25c049e5c20742be87b461e6385;p=mpd-sima.git diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 82c6dbb..c2560ae 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -249,8 +249,10 @@ class MPD(MPDClient): if isinstance(payload, Track): super().__getattr__('add')(payload.file) elif isinstance(payload, list): + self.command_list_ok_begin() for tr in payload: # TODO: use send command here self.add(tr) + results = client.command_list_end() else: self.log.error('Cannot add %s', payload) @@ -289,14 +291,6 @@ class MPD(MPDClient): # ######### / Properties ################### # #### find_tracks #### - def find_album(self, artist, album_name): - self.log.warning('update call to find_album→find_tracks()') - return self.find_tracks(Album(name=album_name, artist=artist)) - - def find_track(self, *args, **kwargs): - self.log.warning('update call to find_track→find_tracks') - return self.find_tracks(*args, **kwargs) - def find_tracks(self, what): """Find tracks for a specific artist or album >>> player.find_tracks(Artist('Nirvana')) @@ -315,29 +309,28 @@ class MPD(MPDClient): def _find_art(self, artist): tracks = set() - if self.use_mbid and artist.mbid: + if artist.mbid: tracks |= set(self.find('musicbrainz_artistid', artist.mbid)) for name in artist.names: tracks |= set(self.find('artist', name)) return list(tracks) def _find_alb(self, album): - if album.mbid and self.use_mbid: + albums = [] + if self.use_mbid and album.mbid: filt = f'(MUSICBRAINZ_ALBUMID == {album.mbid})' - return self.find(filt) + albums = self.find(filt) # Now look for album with no MusicBrainzIdentifier - if album.artist.mbid and self.use_mbid: # Use album artist MBID if possible + if not albums and album.artist.mbid and self.use_mbid: # Use album artist MBID if possible filt = f"((MUSICBRAINZ_ALBUMARTISTID == '{album.artist.mbid}') AND (album == '{album!s}'))" - return self.find(filt) - tracks = [] - # Falls back to albumartist/album name - filt = f"((albumartist == '{album.artist!s}') AND (album == '{album!s}'))" - tracks = self.find(filt) - # Falls back to artist/album name - if not tracks: + albums = self.find(filt) + if not albums: # Falls back to albumartist/album name + filt = f"((albumartist == '{album.artist!s}') AND (album == '{album!s}'))" + albums = self.find(filt) + if not albums: # Falls back to artist/album name filt = f"((artist == '{album.artist!s}') AND (album == '{album!s}'))" - tracks = self.find(filt) - return tracks + albums = self.find(filt) + return albums # #### / find_tracks ## # #### Search Methods ##### @@ -351,15 +344,17 @@ class MPD(MPDClient): >>> ['The Beatles', 'Beatles', 'the beatles'] Returns an Artist object - TODO: Re-use find method here!!! """ + self.log.trace('Looking for "%r" in library', artist) found = False - if artist.mbid: + if self.use_mbid and artist.mbid: # look for exact search w/ musicbrainz_artistid - exact_m = self.list('artist', 'musicbrainz_artistid', artist.mbid) + exact_m = self.list('artist', f"(MUSICBRAINZ_ARTISTID == '{artist.mbid}')") if exact_m: - _ = [artist.add_alias(name) for name in exact_m] found = True + # Looking for "Esthero" adds "DJ Krush feat. Esthero" to aliases + # This seems wrong, disables it for now + #_ = [artist.add_alias(name) for name in exact_m] # then complete with fuzzy search on artist with no musicbrainz_artistid if artist.mbid: # we already performed a lookup on artists with mbid set @@ -446,10 +441,16 @@ class MPD(MPDClient): if album and album not in albums: albums.append(Album(name=album, **kwalbart)) for album in self.list('album', 'artist', name): - album_trks = [trk for trk in self.find('album', album)] + if not album: # list can return "" as an album + continue + album_trks = self.find_tracks(Album(name=album, artist=Artist(name=name))) + album_artists = [tr.albumartist for tr in album_trks if tr.albumartist] if 'Various Artists' in [tr.albumartist for tr in album_trks]: self.log.debug('Discarding %s ("Various Artists" set)', album) continue + if name not in album_artists: + self.log.debug('Discarding "%s", "%s" not set as albumartist', album, name) + continue arts = {trk.artist for trk in album_trks} # Avoid selecting album where artist is credited for a single # track of the album