From 2ad741e23628f9e2d46d849aef12046ba99e3f6e Mon Sep 17 00:00:00 2001 From: thebigmunch Date: Mon, 23 Mar 2020 07:59:09 -0400 Subject: [PATCH] Add support for ID3v2 ``OWNE`` frames [#22] --- CHANGELOG.md | 3 ++ src/audio_metadata/formats/id3v2_frames.py | 40 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be5a03..69c45c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/audio_metadata/formats/id3v2_frames.py b/src/audio_metadata/formats/id3v2_frames.py index b2d6a86..44a29cd 100644 --- a/src/audio_metadata/formats/id3v2_frames.py +++ b/src/audio_metadata/formats/id3v2_frames.py @@ -18,6 +18,8 @@ 'ID3v2LyricsFrame', 'ID3v2NumberFrame', 'ID3v2NumericTextFrame', + 'ID3v2OWNEFrame', + 'ID3v2OwnershipTransaction', 'ID3v2PeopleListFrame', 'ID3v2Performer', 'ID3v2Picture', @@ -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, @@ -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=date_of_purchase, + seller=decode_bytestring(remainder[8:], encoding), + ), + encoding, + ) + + @attrs( repr=False, kw_only=True,