]> kaliko git repositories - mpd-sima.git/commitdiff
Some more cleanup, logs and player calls
authorkaliko <kaliko@azylum.org>
Sun, 10 May 2020 13:58:05 +0000 (15:58 +0200)
committerkaliko <kaliko@azylum.org>
Sun, 10 May 2020 13:58:05 +0000 (15:58 +0200)
sima/lib/webserv.py
sima/mpdclient.py

index 38339f2aecb772d310308757c15bc2ca8008bee2..2a9b8558ce4ce482d4d97f76438e9ce937461b25 100644 (file)
@@ -317,9 +317,9 @@ class WebService(Plugin):
             albums = self.player.search_albums(artist)
             # str conversion while Album type is not propagated
             albums = [str(album) for album in albums]
-            if albums:
-                self.log.debug('Albums candidate: %s', ' / '.join(albums))
-            else: continue
+            if not albums:
+                continue
+            self.log.debug('Albums candidate: %s', ' / '.join(albums))
             # albums yet in history for this artist
             albums = set(albums)
             albums_yet_in_hist = albums & self._get_album_history(artist=artist)
@@ -387,13 +387,13 @@ class WebService(Plugin):
         """Get some tracks for track queue mode
         """
         artists = self.get_local_similar_artists()
-        nbtracks_target = self.plugin_conf.getint('track_to_add') # pylint: disable=no-member
+        nbtracks_target = self.plugin_conf.getint('track_to_add')  # pylint: disable=no-member
         for artist in artists:
             self.log.debug('Trying to find titles to add for "%r"', artist)
-            found = self.player.find_track(artist)
+            found = self.player.find_tracks(artist)
             random.shuffle(found)
             if not found:
-                self.log.debug('Found nothing to queue for {0}'.format(artist))
+                self.log.debug('Found nothing to queue for %s', artist)
                 continue
             # find tracks not in history for artist
             self.filter_track(found)
@@ -403,7 +403,7 @@ class WebService(Plugin):
             self.log.debug('Found no tracks to queue!')
             return None
         for track in self.to_add:
-            self.log.info('{1} candidates: {0!s}'.format(track, self.ws.name))
+            self.log.info('%s candidates: %s', track, self.ws.name)
 
     def _album(self):
         """Get albums for album queue mode
index 82c6dbb505e2fc40a008fb2b2b87024497733834..13aa0b01c3cca749c922d8cfc0f6ba61309b2e85 100644 (file)
@@ -289,14 +289,6 @@ class MPD(MPDClient):
     # ######### / Properties ###################
 
 # #### find_tracks ####
-    def find_album(self, artist, album_name):
-        self.log.warning('update call to find_album→find_tracks(<Album object>)')
-        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'))
@@ -351,12 +343,11 @@ class MPD(MPDClient):
             >>> ['The Beatles', 'Beatles', 'the beatles']
 
         Returns an Artist object
-        TODO: Re-use find method here!!!
         """
         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
@@ -446,7 +437,7 @@ 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)]
+                album_trks = self.find_tracks(Album(name=album, artist=Artist(name=name)))
                 if 'Various Artists' in [tr.albumartist for tr in album_trks]:
                     self.log.debug('Discarding %s ("Various Artists" set)', album)
                     continue