Skip to content

Commit

Permalink
Rework ID3v2 user URL link frame abstractions [#22]
Browse files Browse the repository at this point in the history
* Add ``ID3v2UserURLLink`` class.
* Change ``ID3v2UserURLLinkFrame`` to have only value attribute.
  that contains a single user URL link object.
* Change ``ID3v2Frames`` to present a list of user URL link
  objects for ``WXXX`` key.
  • Loading branch information
thebigmunch committed Mar 4, 2020
1 parent e380a2f commit f39bc1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``OggOpusVorbisComments``.
* ``ID3v2GeneralEncapsulatedObject``.
* ``ID3v2PrivateInfo``.
* ``ID3v2UserURLLink``.

### Changed

Expand All @@ -64,6 +65,12 @@ This project adheres to [Semantic Versioning](https://semver.org).
that contains a single private information object.
* Change ``ID3v2Frames`` to present a list of private info
objects for ``PRIV`` key.
* Rework ID3v2 user URL link frame abstractions.
* Add ``ID3v2UserURLLink`` class.
* Change ``ID3v2UserURLLinkFrame`` to have only value attribute.
that contains a single user URL link object.
* Change ``ID3v2Frames`` to present a list of user URL link
objects for ``WXXX`` key.

### Removed

Expand Down
5 changes: 1 addition & 4 deletions src/audio_metadata/formats/id3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,7 @@ def parse(cls, data, id3_version):
frames[f'{frame.id}:{frame.description}:{frame.language}'].append(frame.value)
elif isinstance(
frame,
(
ID3v2UserTextFrame,
ID3v2UserURLLinkFrame,
),
ID3v2UserTextFrame,
):
frames[f'{frame.id}:{frame.description}'].append(frame.value)
elif isinstance(
Expand Down
27 changes: 7 additions & 20 deletions src/audio_metadata/formats/id3v2_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'ID3v2UnsynchronizedLyricsFrame',
'ID3v2URLLinkFrame',
'ID3v2UserTextFrame',
'ID3v2UserURLLink',
'ID3v2UserURLLinkFrame',
'ID3v2YearFrame',
]
Expand Down Expand Up @@ -114,11 +115,9 @@ class ID3v2PrivateInfo(AttrMapping):
repr=False,
kw_only=True,
)
class ID3v2GeneralEncapsulatedObject(AttrMapping):
mime_type = attrib()
filename = attrib()
class ID3v2UserURLLink(AttrMapping):
description = attrib()
value = attrib()
url = attrib()


class ID3v2Picture(Picture):
Expand Down Expand Up @@ -312,7 +311,6 @@ class ID3v2URLLinkFrame(ID3v2BaseFrame):
kw_only=True,
)
class ID3v2UserURLLinkFrame(ID3v2BaseFrame):
description = attrib()
value = attrib()


Expand Down Expand Up @@ -694,19 +692,6 @@ def parse(cls, data, struct_pattern, size_len, per_byte):
genres.append('Remix')

kwargs['value'] = genres
elif frame_type is ID3v2GEOBFrame:
encoding = determine_encoding(frame_data[0:1])

mime_type, remainder = split_encoded(frame_data[1:], encoding)
filename, remainder = split_encoded(remainder, encoding)
description, value = split_encoded(remainder, encoding)

kwargs['value'] = ID3v2GeneralEncapsulatedObject(
mime_type=mime_type,
filename=filename,
description=description,
value=value,
)
elif frame_type is ID3v2PictureFrame:
kwargs['value'] = frame_data
elif frame_type is ID3v2PrivateFrame:
Expand All @@ -730,8 +715,10 @@ def parse(cls, data, struct_pattern, size_len, per_byte):
encoding = determine_encoding(frame_data)

description, url = split_encoded(frame_data[1:], encoding)
kwargs['description'] = decode_bytestring(description, encoding)
kwargs['url'] = unquote(decode_bytestring(url))
kwargs['value'] = ID3v2UserURLLink(
description=decode_bytestring(description, encoding),
url=unquote(decode_bytestring(url)),
)
elif issubclass(
frame_type,
(
Expand Down

0 comments on commit f39bc1b

Please sign in to comment.