From 8554ef8d81e2c5366180670ce8980c74f95d5bcd Mon Sep 17 00:00:00 2001 From: The Wobbler Date: Mon, 17 Mar 2025 17:36:22 +0100 Subject: [PATCH] Implemented writing of numerical strings. --- .gitignore | 3 ++- smalltag/_formats/_id3.py | 8 ++++++-- tests/formats/test_id3.py | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f2ce492..720e093 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ __pycache__ build SmallTag.egg-info -.idea \ No newline at end of file +.idea +tests/pytest.ini \ No newline at end of file diff --git a/smalltag/_formats/_id3.py b/smalltag/_formats/_id3.py index 1b246f3..380abc2 100644 --- a/smalltag/_formats/_id3.py +++ b/smalltag/_formats/_id3.py @@ -81,13 +81,17 @@ class _ID3(SmallTag, tinytag._ID3): def _compose_id3v2_frame(self, field_name, field_value) -> bytes: frame_id = bytes(self._ID3_WRITE_MAPPING[field_name], "ISO-8859-1") - field_value = field_value[0] + if isinstance(field_value, list): + field_value = field_value[0] if isinstance(field_value, str): frame_value = b"\x00" + bytes(field_value, "ISO-8859-1") + elif isinstance(field_value, int) and frame_id.startswith(b"T"): + frame_value = b"\x00" + bytes(str(field_value), "ISO-8859-1") + else: - print(f"Writing of {field_name} is not implemented.") + print(f"Writing of '{field_name}' (type {type(field_value)}) is not implemented.") return b"" frame_size = pack("4B", *self._synchsafe(len(frame_value))) diff --git a/tests/formats/test_id3.py b/tests/formats/test_id3.py index c21e540..458b54c 100644 --- a/tests/formats/test_id3.py +++ b/tests/formats/test_id3.py @@ -28,3 +28,14 @@ def test_written_gets_recognized(): assert tag.artist == field_content assert tag.album == field_content + +def test_int_converted_to_numerical_string(): + tag = SmallTag.get("formats/test.mp3") + + tag.track = 123 + + tag.write() + + tag = SmallTag.get("formats/test.mp3") + + assert tag.track == 123