Skip to content

Commit

Permalink
Rework ID3v2 GEOB abstractions [#22]
Browse files Browse the repository at this point in the history
* Add ``ID3v2GeneralEncapsulatedObject`` class.
* Change ``ID3v2GEOBFrame`` to have only value attribute.
  that contains a single comment.
* Change ``ID3v2Frames`` to present a list of general
  encapsulated objects for ``GEOB`` key.
  • Loading branch information
thebigmunch committed Mar 4, 2020
1 parent 57ca87c commit b6e897e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``OggVorbis``.
* ``OggVorbisStreamInfo``.
* ``OggOpusVorbisComments``.
* ``ID3v2GeneralEncapsulatedObject``.

### Changed

* Make all attrs classes require keyword arguments.
* Rework ID3v2 comments abstractions.
* Add ``ID3v2Comment`` class to encapsulate each comment.
* Change ``ID3v2CommentFrame`` to have only value attribute
* Change ``ID3v2CommentFrame`` to have only value attribute.
that contains a single comment.
* Change ``ID3v2Frames`` to present a list of comments for ``comment`` key.
* Rename ``formats.vorbis`` module to ``formats.vorbis_comments``.
* Load most commonly used unoffical ID3v2 frames.
* Rename class builder methods to ``parse``.
* Rework ID3v2 general encapsulated object abstractions.
* Add ``ID3v2GeneralEncapsulatedObject`` class.
* Change ``ID3v2GEOBFrame`` to have only value attribute.
that contains a single comment.
* Change ``ID3v2Frames`` to present a list of general
encapsulated objects for ``GEOB`` key.

### Removed

Expand Down
9 changes: 0 additions & 9 deletions src/audio_metadata/formats/id3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,6 @@ def parse(cls, data, id3_version):
),
):
frames[f'{frame.id}:{frame.description}:{frame.language}'].append(frame.value)
elif isinstance(frame, ID3v2GEOBFrame):
frames[f'{frame.id}:{frame.description}'].append(
{

'filename': frame.filename,
'mime_type': frame.mime_type,
'value': frame.value,
},
)
elif isinstance(frame, ID3v2PrivateFrame):
frames[f'{frame.id}:{frame.owner}'].append(frame.value)
elif isinstance(
Expand Down
30 changes: 20 additions & 10 deletions src/audio_metadata/formats/id3v2_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
_genre_re = re.compile(r"((?:\((?P<id>\d+|RX|CR)\))*)(?P<name>.+)?")


@attrs(
repr=False,
kw_only=True,
)
class ID3v2Comment(AttrMapping):
language = attrib()
description = attrib()
text = attrib()


@attrs(
repr=False,
kw_only=True,
Expand All @@ -82,10 +92,11 @@ class ID3v2Performer(AttrMapping):
repr=False,
kw_only=True,
)
class ID3v2Comment(AttrMapping):
language = attrib()
class ID3v2GeneralEncapsulatedObject(AttrMapping):
mime_type = attrib()
filename = attrib()
description = attrib()
text = attrib()
value = attrib()


class ID3v2Picture(Picture):
Expand Down Expand Up @@ -153,9 +164,6 @@ class ID3v2GenreFrame(ID3v2BaseFrame):
kw_only=True,
)
class ID3v2GEOBFrame(ID3v2BaseFrame):
mime_type = attrib()
filename = attrib()
description = attrib()
value = attrib()


Expand Down Expand Up @@ -659,10 +667,12 @@ def parse(cls, data, struct_pattern, size_len, per_byte):
filename, remainder = split_encoded(remainder, encoding)
description, value = split_encoded(remainder, encoding)

kwargs['mime_type'] = decode_bytestring(mime_type)
kwargs['filename'] = decode_bytestring(filename, encoding)
kwargs['description'] = decode_bytestring(description, encoding)
kwargs['value'] = value
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 Down

0 comments on commit b6e897e

Please sign in to comment.