Skip to content

Commit

Permalink
Add support for TMCL ID3v2.4 frame [#22]
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigmunch committed Mar 2, 2020
1 parent c31bcbd commit 68ae1ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org).

* Support for ID3v2 involved people list frames.
* ``ID3v2InvolvedPerson``.
* ``ID3v2InvolvedPeopleListFrame``.
* ``ID3v2MappingListFrame``.
* ``ID3v2Comment``.
* Ogg machinery.
* ``Ogg``.
Expand All @@ -31,6 +31,8 @@ This project adheres to [Semantic Versioning](https://semver.org).
* ``TDRC``.
* ``TDRL``.
* ``TDTG``.
* Support for TMCL ID3v2.4 frame.
* ``ID3v2Performer``.

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/audio_metadata/formats/id3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def load(cls, data, id3_version):
frame,
(
ID3v2GenreFrame,
ID3v2InvolvedPeopleListFrame,
ID3v2MappingListFrame,
ID3v2NumericTextFrame,
ID3v2TextFrame,
ID3v2TimestampFrame,
Expand Down
50 changes: 35 additions & 15 deletions src/audio_metadata/formats/id3v2_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
'ID3v2Frame',
'ID3v2GEOBFrame',
'ID3v2GenreFrame',
'ID3v2InvolvedPeopleListFrame',
'ID3v2InvolvedPerson',
'ID3v2MappingListFrame',
'ID3v2NumberFrame',
'ID3v2NumericTextFrame',
'ID3v2Performer',
'ID3v2Picture',
'ID3v2PictureFrame',
'ID3v2PrivateFrame',
Expand Down Expand Up @@ -68,6 +69,15 @@ class ID3v2InvolvedPerson(AttrMapping):
name = attrib()


@attrs(
repr=False,
kw_only=True,
)
class ID3v2Performer(AttrMapping):
instrument = attrib()
name = attrib()


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -153,7 +163,7 @@ class ID3v2GEOBFrame(ID3v2BaseFrame):
repr=False,
kw_only=True,
)
class ID3v2InvolvedPeopleListFrame(ID3v2BaseFrame):
class ID3v2MappingListFrame(ID3v2BaseFrame):
value = attrib()


Expand Down Expand Up @@ -369,7 +379,7 @@ class ID3v2Frame(ID3v2BaseFrame):

# TODO: ID3v2.4
# TODO: ASPI, EQU2, PCST, RGAD, RVA2, SEEK, SIGN,
# TODO: TMCL, TPRO, XRVA
# TODO: TPRO, XRVA

_FRAME_TYPES = {
# Binary data frames
Expand All @@ -379,14 +389,15 @@ class ID3v2Frame(ID3v2BaseFrame):
# Complex Text Frames
'COM': ID3v2CommentFrame,
'GEO': ID3v2GEOBFrame,
'IPL': ID3v2InvolvedPeopleListFrame,
'IPL': ID3v2MappingListFrame,
'TXX': ID3v2UserTextFrame,

'COMM': ID3v2CommentFrame,
'GEOB': ID3v2GEOBFrame,
'IPLS': ID3v2InvolvedPeopleListFrame,
'IPLS': ID3v2MappingListFrame,
'PRIV': ID3v2PrivateFrame,
'TIPL': ID3v2InvolvedPeopleListFrame,
'TIPL': ID3v2MappingListFrame,
'TMCL': ID3v2MappingListFrame,
'TXXX': ID3v2UserTextFrame,

# Genre Frame
Expand Down Expand Up @@ -574,7 +585,7 @@ def load(cls, data, struct_pattern, size_len, per_byte):
)

kwargs['value'] = comment
elif frame_type is ID3v2InvolvedPeopleListFrame:
elif frame_type is ID3v2MappingListFrame:
encoding = determine_encoding(frame_data[0:1])

values = []
Expand All @@ -584,19 +595,28 @@ def load(cls, data, struct_pattern, size_len, per_byte):
head, tail = split_encoded(tail, encoding)
values.append(head)

people = [
ID3v2InvolvedPerson(
involvement=decode_bytestring(involvement, encoding),
name=decode_bytestring(name, encoding),
)
for involvement, name in more_itertools.chunked(values, 2)
]
if frame_id == 'TMCL':
mapping_list = [
ID3v2Performer(
instrument=decode_bytestring(instrument, encoding),
name=decode_bytestring(name, encoding),
)
for instrument, name in more_itertools.chunked(values, 2)
]
else:
mapping_list = [
ID3v2InvolvedPerson(
involvement=decode_bytestring(involvement, encoding),
name=decode_bytestring(name, encoding),
)
for involvement, name in more_itertools.chunked(values, 2)
]

# Ignore empty people list.
if len(values) < 1:
return None

kwargs['value'] = people
kwargs['value'] = mapping_list
elif frame_type is ID3v2GenreFrame:
encoding = determine_encoding(frame_data[0:1])

Expand Down

0 comments on commit 68ae1ba

Please sign in to comment.