From f071bf2d7432ed9c54682a32f325ef4b6fa39ca4 Mon Sep 17 00:00:00 2001 From: JuniorJPDJ Date: Tue, 11 May 2021 19:04:34 +0200 Subject: [PATCH] New tag: URL --- mediafile.py | 28 ++++++++++++++++++++-------- test/test_mediafile.py | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/mediafile.py b/mediafile.py index 3c6ffd7..89791d6 100644 --- a/mediafile.py +++ b/mediafile.py @@ -840,21 +840,24 @@ class MP3DescStorageStyle(MP3StorageStyle): """Store data in a TXXX (or similar) ID3 frame. The frame is selected based its ``desc`` field. """ - def __init__(self, desc=u'', key='TXXX', **kwargs): + def __init__(self, desc=u'', key='TXXX', attr='text', multispec=True, + **kwargs): assert isinstance(desc, six.text_type) self.description = desc + self.attr = attr + self.multispec = multispec super(MP3DescStorageStyle, self).__init__(key=key, **kwargs) def store(self, mutagen_file, value): frames = mutagen_file.tags.getall(self.key) - if self.key != 'USLT': + if self.multispec: value = [value] # Try modifying in place. found = False for frame in frames: if frame.desc.lower() == self.description.lower(): - frame.text = value + setattr(frame, self.attr, value) frame.encoding = mutagen.id3.Encoding.UTF8 found = True @@ -862,8 +865,8 @@ def store(self, mutagen_file, value): if not found: frame = mutagen.id3.Frames[self.key]( desc=self.description, - text=value, encoding=mutagen.id3.Encoding.UTF8, + **{self.attr: value} ) if self.id3_lang: frame.lang = self.id3_lang @@ -872,10 +875,10 @@ def store(self, mutagen_file, value): def fetch(self, mutagen_file): for frame in mutagen_file.tags.getall(self.key): if frame.desc.lower() == self.description.lower(): - if self.key == 'USLT': - return frame.text + if not self.multispec: + return getattr(frame, self.attr) try: - return frame.text[0] + return getattr(frame, self.attr)[0] except IndexError: return None @@ -1751,8 +1754,17 @@ def update(self, dict): ASFStorageStyle('TotalDiscs'), out_type=int, ) + + url = MediaField( + MP3DescStorageStyle(key='WXXX', attr='url', multispec=False), + MP4StorageStyle('\xa9url'), + StorageStyle('URL'), + StorageStyle('WWW'), + StorageStyle('Website'), + ASFStorageStyle('WM/URL'), + ) lyrics = MediaField( - MP3DescStorageStyle(key='USLT'), + MP3DescStorageStyle(key='USLT', multispec=False), MP4StorageStyle('\xa9lyr'), StorageStyle('LYRICS'), ASFStorageStyle('WM/Lyrics'), diff --git a/test/test_mediafile.py b/test/test_mediafile.py index 2dd4bdf..723cf3f 100644 --- a/test/test_mediafile.py +++ b/test/test_mediafile.py @@ -363,6 +363,7 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin, 'tracktotal', 'disc', 'disctotal', + 'url', 'lyrics', 'comments', 'copyright', @@ -708,7 +709,7 @@ def _generate_tags(self, base=None): # R128 is int tags[key] = -1 else: - tags[key] = 'value\u2010%s' % key + tags[key] = 'value-%s' % key for key in ['disc', 'disctotal', 'track', 'tracktotal', 'bpm']: tags[key] = 1