From 5554fe00b7f7ceb827cd34eb3d80f871f66becdb Mon Sep 17 00:00:00 2001 From: JuniorJPDJ Date: Tue, 11 May 2021 20:02:15 +0200 Subject: [PATCH] Add support for splitting of ID3v2.3 multi-value tags for MP3ListDescStorageStyle fixes rest of problems in #43 Shouldn't be enabled on tags like `artists` or other without confidence that values will not contain separator (eg. `artists: ['AC/DC']`). Format of mbid is known and I'm sure we can enable it here. When solving #21 this separator value in `el.split('/')` also should be taken into account. --- mediafile.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/mediafile.py b/mediafile.py index ff1429c..eefd58d 100644 --- a/mediafile.py +++ b/mediafile.py @@ -893,14 +893,19 @@ def delete(self, mutagen_file): class MP3ListDescStorageStyle(MP3DescStorageStyle, ListStorageStyle): - def __init__(self, desc=u'', key='TXXX', **kwargs): - super(MP3ListDescStorageStyle, self).__init__(desc=desc, key=key, - **kwargs) + def __init__(self, desc=u'', key='TXXX', split_v23=False, **kwargs): + self.split_v23 = split_v23 + super(MP3ListDescStorageStyle, self).__init__( + desc=desc, key=key, **kwargs + ) def fetch(self, mutagen_file): for frame in mutagen_file.tags.getall(self.key): if frame.desc.lower() == self.description.lower(): - return frame.text + if mutagen_file.tags.version == (2, 3, 0) and self.split_v23: + return sum([el.split('/') for el in frame.text], start=[]) + else: + return frame.text return [] def store(self, mutagen_file, values): @@ -1988,15 +1993,19 @@ def update(self, dict): ASFStorageStyle('MusicBrainz/Album Id'), ) mb_artistid = ListMediaField( - MP3ListDescStorageStyle(u'MusicBrainz Artist Id'), + MP3ListDescStorageStyle(u'MusicBrainz Artist Id', split_v23=True), MP4ListStorageStyle('----:com.apple.iTunes:MusicBrainz Artist Id'), ListStorageStyle('MUSICBRAINZ_ARTISTID'), ASFStorageStyle('MusicBrainz/Artist Id'), ) mb_albumartistid = ListMediaField( - MP3ListDescStorageStyle(u'MusicBrainz Album Artist Id'), + MP3ListDescStorageStyle( + u'MusicBrainz Album Artist Id', + split_v23=True, + ), MP4ListStorageStyle( - '----:com.apple.iTunes:MusicBrainz Album Artist Id'), + '----:com.apple.iTunes:MusicBrainz Album Artist Id', + ), ListStorageStyle('MUSICBRAINZ_ALBUMARTISTID'), ASFStorageStyle('MusicBrainz/Album Artist Id'), )