Skip to content

Commit

Permalink
Ass support for ID3v2 Popularimeter frames [#22]
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigmunch committed Apr 9, 2020
1 parent cefaf05 commit 7ca7afa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``ID3v2Track``.
* ``ID3v2TrackFrame``.
* ``ID3v2TPROFrame``.
* Support for ID3v2 Popularimeter frames.
* ``ID3v2Popularimeter``.
* ``ID3v2PopularimeterFrame``.

### Changed

Expand Down
55 changes: 52 additions & 3 deletions src/audio_metadata/formats/id3v2frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'ID3v2PeopleListFrame',
'ID3v2Performer',
'ID3v2Picture',
'ID3v2Popularimeter',
'ID3v2PopularimeterFrame',
'ID3v2PrivateFrame',
'ID3v2PrivateInfo',
'ID3v2SynchronizedLyrics',
Expand Down Expand Up @@ -165,6 +167,16 @@ class ID3v2Lyrics(AttrMapping):
text = attrib()


@attrs(
repr=False,
kw_only=True,
)
class ID3v2Popularimeter(AttrMapping):
email = attrib()
rating = attrib()
count = attrib(default=None)


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -724,6 +736,38 @@ class ID3v2PeopleListFrame(ID3v2Frame):
pass


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

email, remainder = frame_data.split(b'\x00', 1)
rating = remainder[0]
remainder = remainder[1:]

if not remainder:
count = None
else:
if len(remainder) < 4:
raise TagError("Popularimeter count must be at least 4 bytes long.")

count = int.from_bytes(remainder, byteorder='big')

return (
ID3v2Popularimeter(
email=email.decode('iso-8859-1'),
rating=rating,
count=count,
),
None,
)


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -1299,15 +1343,15 @@ def _parse_frame_data(data):

# TODO:ID3v2.2
# TODO: BUF, CNT, CRA, CRM, ETC, EQU, LNK, MCI, MLL, PCS,
# TODO: POP, REV, RVA
# TODO: REV, RVA

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

# TODO: ID3v2.4
# TODO: AENC, ASPI, COMR, ENCR, EQU2, ETCO, LINK, MLLT,
# TODO: OWNE, PCNT, PCST, POPM, POSS, RBUF, RGAD, RVA2, RVRB,
# TODO: OWNE, PCNT, PCST, POSS, RBUF, RGAD, RVA2, RVRB,
# TODO: SEEK, SIGN, XRVA
ID3v2FrameTypes = {
# Binary data frames
Expand Down Expand Up @@ -1380,6 +1424,11 @@ def _parse_frame_data(data):

'APIC': ID3v2APICFrame,

# Popularimeter Frames
'POP': ID3v2PopularimeterFrame,

'POPM': ID3v2PopularimeterFrame,

# Text Frames
'TAL': ID3v2TextFrame,
'TCM': ID3v2TextFrame,
Expand Down

0 comments on commit 7ca7afa

Please sign in to comment.