Skip to content

Commit

Permalink
Add support for ID3v2 unique file identifier frames [#22]
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigmunch committed Mar 22, 2020
1 parent e79c15a commit eac0805
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``RIFFTag``.
* ``ID3v1Field``.
* ``ID3v1AlbumField``.
* ``ID3v2ArtistField``.
* ``ID3v1ArtistField``.
* ``ID3v1CommentField``.
* ``ID3v1GenreField``.
* ``ID3v1TitleField``.
Expand All @@ -25,6 +25,9 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``FormatError``.
* ``TagError``.
* ``FLACVorbisComments``.
* Support for ID3v2 unique file identifier frames.
* ``ID3v2UniqueFileIdentifier``.
* ``ID3v2UniqueFileIdentifierFrame``.

### Changed

Expand All @@ -33,7 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org).
* Refactor ID3v1 to use tag classes.
* ``ID3v1Field``.
* ``ID3v1AlbumField``.
* ``ID3v2ArtistField``.
* ``ID3v1ArtistField``.
* ``ID3v1CommentField``.
* ``ID3v1GenreField``.
* ``ID3v1TitleField``.
Expand Down
39 changes: 37 additions & 2 deletions src/audio_metadata/formats/id3v2_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'ID3v2TMCLFrame',
'ID3v2TextFrame',
'ID3v2TimestampFrame',
'ID3v2UniqueFileIdentifier',
'ID3v2UniqueFileIdentifierFrame',
'ID3v2UnsynchronizedLyrics',
'ID3v2UnsynchronizedLyricsFrame',
'ID3v2URLLinkFrame',
Expand Down Expand Up @@ -128,6 +130,15 @@ class ID3v2PrivateInfo(AttrMapping):
data = attrib()


@attrs(
repr=False,
kw_only=True,
)
class ID3v2UniqueFileIdentifier(AttrMapping):
owner = attrib()
identifier = attrib()


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -798,14 +809,37 @@ def validate_value(self, attribute, value):
)


@attrs(
repr=False,
kw_only=True,
)
class ID3v2UniqueFileIdentifierFrame(ID3v2Frame):
@datareader
@classmethod
def _parse_frame_data(cls, data, frame_size):
frame_data = data.read(frame_size)
owner, identifier = frame_data.split(b'\x00')

if len(identifier) > 64:
raise TagError("ID3v2 unique file identifier must be no more than 64 bytes.")

return (
ID3v2UFID(
owner=owner.decode('iso-8859-1'),
identifier=identifier,
),
None,
)


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

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

# TODO: ID3v2.4
# TODO: ASPI, EQU2, PCST, RGAD, RVA2, SEEK, SIGN,
Expand All @@ -828,6 +862,7 @@ def validate_value(self, attribute, value):
'TIPL': ID3v2InvolvedPeopleListFrame,
'TMCL': ID3v2TMCLFrame,
'TXXX': ID3v2UserTextFrame,
'UFID': ID3v2UFIDFrame,

# Genre Frame
'TCO': ID3v2GenreFrame,
Expand Down
3 changes: 3 additions & 0 deletions src/audio_metadata/formats/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class ID3Version(_BaseEnum):
'title': 'TT2',
'titlesort': 'TST',
'tracknumber': 'TRK',
'ufid': 'UFI',
'usertext': 'TXX',
'userurl': 'WXX',
},
Expand Down Expand Up @@ -200,6 +201,7 @@ class ID3Version(_BaseEnum):
'title': 'TIT2',
'titlesort': 'TSOT',
'tracknumber': 'TRCK',
'ufid': 'UFID',
'usertext': 'TXXX',
'userurl': 'WXXX',
},
Expand Down Expand Up @@ -255,6 +257,7 @@ class ID3Version(_BaseEnum):
'title': 'TIT2',
'titlesort': 'TSOT',
'tracknumber': 'TRCK',
'ufid': 'UFID',
'usertext': 'TXXX',
'userurl': 'WXXX',
},
Expand Down

0 comments on commit eac0805

Please sign in to comment.