Skip to content

Commit

Permalink
Add ID3v2AENCFrame [#22]
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigmunch committed Apr 9, 2020
1 parent 0173c97 commit f1dab46
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``ID3v2Popularimeter``.
* ``ID3v2PopularimeterFrame``.
* ``ID3v2PodcastFrame``.
* Support for Apple ``GRP1`` and ``TCAT`` ID3v2 frames
* Support for Apple ``GRP1`` and ``TCAT`` ID3v2 frames.
* ``ID3v2AENCFrame``.

### Changed

Expand Down
42 changes: 40 additions & 2 deletions src/audio_metadata/formats/id3v2frames.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# http://id3.org/Developer%20Information

__all__ = [
'ID3v2AENCFrame',
'ID3v2APICFrame',
'ID3v2AudioEncryption',
'ID3v2BinaryDataFrame',
'ID3v2Comment',
'ID3v2CommentFrame',
Expand Down Expand Up @@ -109,6 +111,17 @@
_genre_re = re.compile(r"((?:\((?P<id>\d+|RX|CR)\))*)(?P<name>.+)?")


@attrs(
repr=False,
kw_only=True,
)
class ID3v2AudioEncryption(AttrMapping):
owner = attrib()
preview_start = attrib()
preview_size = attrib()
info = attrib()


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -1052,6 +1065,30 @@ def _parse_frame_data(data):
)


@attrs(
repr=False,
kw_only=True,
)
class ID3v2AENCFrame(ID3v2Frame):
@datareader
@staticmethod
def _parse_frame_data(data):
frame_data = data.read()

owner, remainder = frame_data.split(b'\x00', 1)
preview_start, preview_size = struct.unpack('>HH', remainder[0:4])

return (
ID3v2AudioEncryption(
owner=owner.decode('iso-8859-1'),
preview_start=preview_start,
preview_size=preview_size,
info=remainder[4:],
),
None,
)


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -1355,11 +1392,11 @@ def _parse_frame_data(data):
# TODO: REV, RVA

# TODO: ID3v2.3
# TODO: AENC, COMR, ENCR, EQUA, ETCO, LINK, MLLT, OWNE
# TODO: COMR, ENCR, EQUA, ETCO, LINK, MLLT, OWNE
# TODO: PCNT, POSS, RBUF, RGAD, RVAD, RVRB, XRVA

# TODO: ID3v2.4
# TODO: AENC, ASPI, COMR, ENCR, EQU2, ETCO, LINK, MLLT,
# TODO: ASPI, COMR, ENCR, EQU2, ETCO, LINK, MLLT,
# TODO: OWNE, PCNT, POSS, RBUF, RGAD, RVA2, RVRB,
# TODO: SEEK, SIGN, XRVA
ID3v2FrameTypes = {
Expand All @@ -1372,6 +1409,7 @@ def _parse_frame_data(data):
'STC': ID3v2SynchronizedTempoCodesFrame,
'UFI': ID3v2UniqueFileIdentifierFrame,

'AENC': ID3v2AENCFrame,
'GEOB': ID3v2GeneralEncapsulatedObjectFrame,
'GRID': ID3v2GRIDFrame,
'PRIV': ID3v2PrivateFrame,
Expand Down

0 comments on commit f1dab46

Please sign in to comment.