From 37fa6fecb9b383c12c26bbce0322506fa3f1ae0e Mon Sep 17 00:00:00 2001 From: JuniorJPDJ Date: Tue, 11 May 2021 00:25:38 +0200 Subject: [PATCH] Convert `mb_artistid` and `mb_albumartistid` to multivalue Resolves #43 --- mediafile.py | 17 +++++++++-------- test/test_mediafile.py | 22 ++++++++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/mediafile.py b/mediafile.py index 19f3a41..bd9cb44 100644 --- a/mediafile.py +++ b/mediafile.py @@ -1947,16 +1947,17 @@ def update(self, dict): StorageStyle('MUSICBRAINZ_ALBUMID'), ASFStorageStyle('MusicBrainz/Album Id'), ) - mb_artistid = MediaField( - MP3DescStorageStyle(u'MusicBrainz Artist Id'), - MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Artist Id'), - StorageStyle('MUSICBRAINZ_ARTISTID'), + mb_artistid = ListMediaField( + MP3ListDescStorageStyle(u'MusicBrainz Artist Id'), + MP4ListStorageStyle('----:com.apple.iTunes:MusicBrainz Artist Id'), + ListStorageStyle('MUSICBRAINZ_ARTISTID'), ASFStorageStyle('MusicBrainz/Artist Id'), ) - mb_albumartistid = MediaField( - MP3DescStorageStyle(u'MusicBrainz Album Artist Id'), - MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Album Artist Id'), - StorageStyle('MUSICBRAINZ_ALBUMARTISTID'), + mb_albumartistid = ListMediaField( + MP3ListDescStorageStyle(u'MusicBrainz Album Artist Id'), + MP4ListStorageStyle( + '----:com.apple.iTunes:MusicBrainz Album Artist Id'), + ListStorageStyle('MUSICBRAINZ_ALBUMARTISTID'), ASFStorageStyle('MusicBrainz/Album Artist Id'), ) mb_releasegroupid = MediaField( diff --git a/test/test_mediafile.py b/test/test_mediafile.py index 43c136c..fca849c 100644 --- a/test/test_mediafile.py +++ b/test/test_mediafile.py @@ -340,7 +340,7 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, 'mb_trackid': '8b882575-08a5-4452-a7a7-cbb8a1531f9e', 'mb_releasetrackid': 'c29f3a57-b439-46fd-a2e2-93776b1371e0', 'mb_albumid': '9e873859-8aa4-4790-b985-5a953e8ef628', - 'mb_artistid': '7cf0ea9d-86b9-4dad-ba9e-2355a64899ea', + 'mb_artistid': ['7cf0ea9d-86b9-4dad-ba9e-2355a64899ea'], 'art': None, 'label': u'the label', } @@ -371,7 +371,6 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, 'mb_releasetrackid', 'mb_workid', 'mb_albumid', - 'mb_artistid', 'art', 'label', 'rg_track_peak', @@ -381,7 +380,6 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, 'r128_track_gain', 'r128_album_gain', 'albumartist', - 'mb_albumartistid', 'artist_sort', 'albumartist_sort', 'acoustid_fingerprint', @@ -449,7 +447,11 @@ def test_read_full(self): def test_read_empty(self): mediafile = self._mediafile_fixture('empty') for field in self.tag_fields: - self.assertIsNone(getattr(mediafile, field)) + value = getattr(mediafile, field) + if isinstance(value, list): + assert len(value) == 0 + else: + self.assertIsNone(value) def test_write_empty(self): mediafile = self._mediafile_fixture('empty') @@ -620,7 +622,11 @@ def test_delete_tag(self): mediafile = MediaFile(mediafile.path) for key in keys: - self.assertIsNone(getattr(mediafile, key)) + value = getattr(mediafile, key) + if isinstance(value, list): + assert len(value) == 0 + else: + self.assertIsNone(value) def test_delete_packed_total(self): mediafile = self._mediafile_fixture('full') @@ -705,6 +711,9 @@ def _generate_tags(self, base=None): for key in ['disc', 'disctotal', 'track', 'tracktotal', 'bpm']: tags[key] = 1 + for key in ['mb_artistid', 'mb_albumartistid']: + tags[key] = ['multival', 'test'] + tags['art'] = self.jpg_data tags['comp'] = True @@ -976,7 +985,8 @@ def test_properties_from_readable_fields(self): def test_known_fields(self): fields = list(ReadWriteTestBase.tag_fields) - fields.extend(('encoder', 'images', 'genres', 'albumtype')) + fields.extend(('encoder', 'images', 'genres', 'albumtype', + 'mb_artistid', 'mb_albumartistid')) assertCountEqual(self, MediaFile.fields(), fields) def test_fields_in_readable_fields(self):