Skip to content

Commit

Permalink
TODO: interactive rebase to actual cool named commits
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorJPDJ committed May 10, 2021
1 parent 760232f commit b954c5e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
48 changes: 39 additions & 9 deletions mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,29 @@ def delete(self, mutagen_file):
del mutagen_file[frame.HashKey]


class MP3ListDescStorageStyle(MP3DescStorageStyle, ListStorageStyle):
def __init__(self, desc=u'', key='TXXX', **kwargs):
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
return []

def store(self, mutagen_file, values):
self.delete(mutagen_file)
frame = mutagen.id3.Frames[self.key](
desc=self.description,
text=values,
encoding=mutagen.id3.Encoding.UTF8,
)
if self.id3_lang:
frame.lang = self.id3_lang
mutagen_file.tags.add(frame)


class MP3SlashPackStorageStyle(MP3StorageStyle):
"""Store value as part of pair that is serialized as a slash-
separated string.
Expand Down Expand Up @@ -1644,7 +1667,7 @@ def update(self, dict):
ASFStorageStyle('Author'),
)
artists = ListMediaField(
# MP3ListDescStorageStyle(desc='ARTISTS'),
MP3ListDescStorageStyle(desc=u'ARTISTS'),
MP4ListStorageStyle('----:com.apple.iTunes:ARTISTS'),
ListStorageStyle('ARTISTS'),
ASFStorageStyle('WM/ARTISTS'),
Expand Down Expand Up @@ -1769,6 +1792,12 @@ def update(self, dict):
StorageStyle('ALBUMARTIST'),
ASFStorageStyle('WM/AlbumArtist'),
)
albumartists = ListMediaField(
MP3ListDescStorageStyle(desc=u'ALBUMARTISTS'),
MP4ListStorageStyle('----:com.apple.iTunes:ALBUMARTISTS'),
ListStorageStyle('ALBUMARTISTS'),
ASFStorageStyle('WM/AlbumArtists'),
)
albumtype = MediaField(
MP3DescStorageStyle(u'MusicBrainz Album Type'),
MP4StorageStyle('----:com.apple.iTunes:MusicBrainz Album Type'),
Expand Down Expand Up @@ -1945,16 +1974,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(
Expand Down
24 changes: 17 additions & 7 deletions test/test_mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,14 @@ 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',
}

tag_fields = [
'title',
'artist',
'artists'
'album',
'genre',
'lyricist',
Expand All @@ -373,7 +372,6 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin,
'mb_releasetrackid',
'mb_workid',
'mb_albumid',
'mb_artistid',
'art',
'label',
'rg_track_peak',
Expand All @@ -383,7 +381,6 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin,
'r128_track_gain',
'r128_album_gain',
'albumartist',
'mb_albumartistid',
'artist_sort',
'albumartist_sort',
'acoustid_fingerprint',
Expand Down Expand Up @@ -452,7 +449,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')
Expand Down Expand Up @@ -623,7 +624,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')
Expand Down Expand Up @@ -708,6 +713,10 @@ def _generate_tags(self, base=None):
for key in ['disc', 'disctotal', 'track', 'tracktotal', 'bpm']:
tags[key] = 1

for key in ['artists', 'albumartists', 'mb_artistid',
'mb_albumartistid']:
tags[key] = ['multival', 'test']

tags['art'] = self.jpg_data
tags['comp'] = True

Expand Down Expand Up @@ -979,7 +988,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', 'artists',
'albumartists', 'mb_artistid', 'mb_albumartistid'))
assertCountEqual(self, MediaFile.fields(), fields)

def test_fields_in_readable_fields(self):
Expand Down

0 comments on commit b954c5e

Please sign in to comment.