]> kaliko git repositories - mpd-sima.git/commitdiff
Fixed issue with multivalued musicbrainz_artistid (Closes #47)
authorkaliko <kaliko@azylum.org>
Mon, 7 Jun 2021 12:28:32 +0000 (14:28 +0200)
committerkaliko <kaliko@azylum.org>
Mon, 7 Jun 2021 12:28:32 +0000 (14:28 +0200)
sima/lib/meta.py
tests/test_meta.py

index 3f6a641c3460938966eb2ef84431c55b3222667e..9d15c69dacef0594f9bdcd7ecd76ac75f04b6c77 100644 (file)
@@ -93,13 +93,13 @@ class Meta:
         if not isinstance(kwargs.get('name'), str):
             raise MetaException('"name" argument not a string')
         else:
-            self.__name = kwargs.pop('name')
+            self.__name = kwargs.pop('name').split(SEPARATOR)[0]
         if 'mbid' in kwargs and kwargs.get('mbid'):
-            if is_uuid4(kwargs.get('mbid')):
-                self.__mbid = kwargs.pop('mbid').lower()
+            mbid = kwargs.get('mbid').lower().split(SEPARATOR)[0]
+            if is_uuid4(mbid):
+                self.__mbid = mbid
             else:
-                self.log.warning('Wrong mbid %s:%s', self.__name,
-                                 kwargs.get('mbid'))
+                self.log.warning('Wrong mbid %s:%s', self.__name, mbid)
             # mbid immutable as hash rests on
         self.__dict__.update(**kwargs)
 
@@ -184,7 +184,7 @@ class Album(Meta):
     @mbidfilter
     def __init__(self, name=None, mbid=None, **kwargs):
         if kwargs.get('musicbrainz_albumid', False):
-            mbid = kwargs.get('musicbrainz_albumid').split(SEPARATOR)[0]
+            mbid = kwargs.get('musicbrainz_albumid')
         super().__init__(name=name, mbid=mbid, **kwargs)
 
     @property
@@ -214,11 +214,11 @@ class Artist(Meta):
     @mbidfilter
     def __init__(self, name=None, mbid=None, **kwargs):
         if kwargs.get('artist', False):
-            name = kwargs.get('artist').split(SEPARATOR)[0]
+            name = kwargs.get('artist')
         if kwargs.get('musicbrainz_artistid', False):
-            mbid = kwargs.get('musicbrainz_artistid').split(SEPARATOR)[0]
-        if not kwargs.get('albumartist', False):
-            kwargs['albumartist'] = name
+            mbid = kwargs.get('musicbrainz_artistid')
+        if name and not kwargs.get('albumartist', False):
+            kwargs['albumartist'] = name.split(SEPARATOR)[0]
         super().__init__(name=name, mbid=mbid,
                          albumartist=kwargs.get('albumartist'))
 
index e1be51b63681beead721a00952c13a525d8ceff1..b7782b4129b6fa8aae67b784b6a7d3c6f774ca4c 100644 (file)
@@ -121,22 +121,24 @@ class TestMetaObject(unittest.TestCase):
 class TestArtistObject(unittest.TestCase):
 
     def test_init(self):
-        artist = {'artist': SEPARATOR.join(['Original Name', 'Featuring Nane', 'Featureā€¦']),
+        artist = {'artist':
+                SEPARATOR.join(['Original Name', 'Featuring Nane', 'Featureā€¦']),
                   'albumartist': 'Name',
-                  'musicbrainz_artistid': VALID,
+                  'musicbrainz_artistid':
+                  SEPARATOR.join([VALID, VALID.replace('0000', '1312')]),
                   }
         art = Artist(**artist)
         self.assertEqual(art.name, 'Original Name')
-        self.assertTrue(art.mbid == VALID)
+        self.assertEqual(art.mbid, VALID)
         self.assertEqual(art.albumartist, artist['albumartist'])
         artist.pop('albumartist')
         art = Artist(**artist)
-        self.assertTrue(art.name, 'Original Name')
-        self.assertTrue(art.albumartist, 'Original Name')
+        self.assertEqual(art.name, 'Original Name')
+        self.assertEqual(art.albumartist, 'Original Name')
 
     def test_empty_name(self):
         for args in [
-                {'mbid':VALID},
+                {'mbid': VALID},
                 {'name': None},
                 {},
                 ]: