]> kaliko git repositories - mpd-sima.git/commitdiff
MPD client: Tries to resolve MusicBrainzArtistID when possible (fixed b36c71a)
authorkaliko <kaliko@azylum.org>
Tue, 8 Jun 2021 18:39:15 +0000 (20:39 +0200)
committerkaliko <kaliko@azylum.org>
Tue, 8 Jun 2021 18:39:15 +0000 (20:39 +0200)
sima/lib/meta.py
sima/mpdclient.py
tests/test_meta.py

index 5a2305eceb09169663860083bc43b3122a03e4ab..e6b9f46229554e008422017281de51db7d9be680 100644 (file)
@@ -136,12 +136,12 @@ class Meta:
 
         :param str other: Alias to add, could be any object with ``__str__`` method.
         """
+        if isinstance(other, Meta):
+            self.__aliases |= other.__aliases
+            self.__aliases -= {self.name}
         if getattr(other, '__str__', None):
             if callable(other.__str__) and other.__str__() != self.name:
                 self.__aliases |= {other.__str__()}
-        elif isinstance(other, Meta):
-            if other.name != self.name:
-                self.__aliases |= other.__aliases
         else:
             raise MetaException('No __str__ method found in {!r}'.format(other))
 
@@ -158,13 +158,6 @@ 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
index fbd8cd8b32a157d778fd6e920c50f769b12657b3..6b5b9767e95dd3eca58e3e1c6a16d7763da66c88 100644 (file)
@@ -59,7 +59,10 @@ def set_artist_mbid(func):
         result = func(*args, **kwargs)
         if Meta.use_mbid:
             if result and not result.mbid:
-                result.mbid = cls._find_musicbrainz_artistid(result)
+                mbid = cls._find_musicbrainz_artistid(result)
+                artist = Artist(name=result.name, mbid=mbid)
+                artist.add_alias(result)
+                return artist
         return result
     return wrapper
 
@@ -368,8 +371,13 @@ class MPD(MPDClient):
         """
         if not self.use_mbid:
             return None
-        mbids = self.list('MUSICBRAINZ_ARTISTID',
-                          f'(artist == "{artist.name_sz}")')
+        mbids = None
+        for name in artist.names_sz:
+            self.log.debug(name)
+            filt = f'((artist == "{name}") AND (MUSICBRAINZ_ARTISTID != ""))'
+            mbids = self.list('MUSICBRAINZ_ARTISTID', filt)
+            if mbids:
+                break
         if not mbids:
             return None
         if len(mbids) > 1:
index b7782b4129b6fa8aae67b784b6a7d3c6f774ca4c..aefd339d83934bc08b414643fbcb02cc4445bbe2 100644 (file)
@@ -56,6 +56,15 @@ class TestMetaObject(unittest.TestCase):
         # test equality Obj.__name with OgjBis.__aliases
         self.assertTrue(art0 == Meta(name='A Silver Mt. Zion'))
 
+        art1 = Meta(name='Silver Mt. Zion')
+        art1.add_alias(art0)
+        self.assertIn('A Silver Mt. Zion', art1.aliases)
+
+        art3 = Meta(name='foo')
+        art3.add_alias('Silver Mt. Zion')
+        art1.add_alias(art3)
+        self.assertNotIn('Silver Mt. Zion', art1.aliases)
+
     def test_union(self):
         art00 = Meta(name='Aphex Twin',
                            mbid='f22942a1-6f70-4f48-866e-238cb2308fbd')