From: kaliko Date: Tue, 8 Jun 2021 14:46:40 +0000 (+0200) Subject: MPD client: Tries to resolve MusicBrainzArtistID when possible. X-Git-Tag: 0.18.0~34 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=b36c71a;p=mpd-sima.git MPD client: Tries to resolve MusicBrainzArtistID when possible. --- diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 725bfb0..5a2305e 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -158,6 +158,13 @@ class Meta: def mbid(self): return self.__mbid + @mbid.setter + def mbid(self, mbid): + if mbid and not is_uuid4(mbid): + self.log.warning('Wrong mbid %s:%s', self.__name, mbid) + return + self.__mbid = mbid + @property def aliases(self): return self.__aliases diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 1d86813..338c3cf 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -42,20 +42,26 @@ def bl_artist(func): cls = args[0] if not cls.database: return func(*args, **kwargs) - results = func(*args, **kwargs) - if not results: + result = func(*args, **kwargs) + if not result: return None - for art in results.names: - mbid = results.mbid - if not mbid: - mbid = cls._find_musicbrainz_artistid(results) - artist = Artist(name=art, mbid=mbid) + for art in result.names: + artist = Artist(name=art, mbid=result.mbid) if cls.database.get_bl_artist(artist, add=False): cls.log.debug('Artist in blocklist: %s', artist) return None - return results + return result return wrapper +def set_artist_mbid(func): + def wrapper(*args, **kwargs): + cls = args[0] + result = func(*args, **kwargs) + if Meta.use_mbid: + if result and not result.mbid: + result.mbid = cls._find_musicbrainz_artistid(result) + return result + return wrapper def tracks_wrapper(func): """Convert plain track mapping as returned by MPDClient into :py:obj:Track @@ -355,6 +361,11 @@ class MPD(MPDClient): # #### Search Methods ##### def _find_musicbrainz_artistid(self, artist): + """Find MusicBrainzArtistID when possible. + For artist with aliases having a mbid but not the main name, no mbid is + fetched… + Searching for Artist('Russian Circls') do not reslove the MBID + """ if not self.use_mbid: return None mbids = self.list('MUSICBRAINZ_ARTISTID', @@ -372,6 +383,7 @@ class MPD(MPDClient): return mbids[0] @bl_artist + @set_artist_mbid def search_artist(self, artist): """ Search artists based on a fuzzy search in the media library