From: kaliko Date: Mon, 7 Jun 2021 12:28:32 +0000 (+0200) Subject: Fixed issue with multivalued musicbrainz_artistid (Closes #47) X-Git-Tag: 0.18.0~41 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=2b41de301271772c0a4667e81e1f2d180f349279;p=mpd-sima.git Fixed issue with multivalued musicbrainz_artistid (Closes #47) --- diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 3f6a641..9d15c69 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -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')) diff --git a/tests/test_meta.py b/tests/test_meta.py index e1be51b..b7782b4 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -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}, {}, ]: