Skip to content

Commit

Permalink
Add support for ID3v2 OWNE frames [#22]
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigmunch committed Mar 23, 2020
1 parent a92dd53 commit 4f94d58
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ This project adheres to [Semantic Versioning](https://semver.org).
* Support for ID3v2 ``GRID`` frames.
* ``ID3v2GroupID``.
* ``ID3v2GRIDFrame``.
* Support for ID3v2 ``OWNE`` frames.
* ``ID3v2OwnershipTransaction``.
* ``ID3v2OWNEFrame``.

### Changed

Expand Down
40 changes: 40 additions & 0 deletions src/audio_metadata/formats/id3v2_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
'ID3v2LyricsFrame',
'ID3v2NumberFrame',
'ID3v2NumericTextFrame',
'ID3v2OWNEFrame',
'ID3v2OwnershipTransaction',
'ID3v2PeopleListFrame',
'ID3v2Performer',
'ID3v2Picture',
Expand Down Expand Up @@ -156,6 +158,16 @@ class ID3v2UnsynchronizedLyrics(ID3v2Lyrics):
pass


@attrs(
repr=False,
kw_only=True,
)
class ID3v2OwnershipTransaction(AttrMapping):
price_paid = attrib()
date_of_purchase = attrib()
seller = attrib()


@attrs(
repr=False,
kw_only=True,
Expand Down Expand Up @@ -864,6 +876,34 @@ def _parse_frame_data(cls, data, frame_size):
)


@attrs(
repr=False,
kw_only=True,
)
class ID3v2OWNEFrame(ID3v2Frame):
@datareader
@classmethod
def _parse_frame_data(cls, data, frame_size):
frame_data = data.read(frame_size)

encoding = determine_encoding(frame_data)

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

date_of_purchase = remainder[:8].decode('iso-8859-1')
if not date_of_purchase.is_digit():
raise TagError("ID3v2 ``OWNE`` frame date of purchase must be in the form of ``YYYYMMDD``.")

return (
ID3v2OwnershipTransaction(
price_paid=price_paid.decode('iso-8859-1'),
date_of_purchase=,
seller=decode_bytestring(remainder[8:], encoding),
),
encoding,
)


@attrs(
repr=False,
kw_only=True,
Expand Down

0 comments on commit 4f94d58

Please sign in to comment.