Skip to content

Commit

Permalink
Add support for splitting of ID3v2.3 multi-value tags
Browse files Browse the repository at this point in the history
fixes rest of problems in beetbox#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 beetbox#21 this separator value in `el.split('/')` also should be taken into account.
  • Loading branch information
JuniorJPDJ committed May 11, 2021
1 parent f071bf2 commit 6ff1a87
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -1988,15 +1993,16 @@ 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'),
)
Expand Down

0 comments on commit 6ff1a87

Please sign in to comment.