Restructured the write functions and added some type hints.

This commit is contained in:
The Wobbler 2025-03-15 18:51:16 +01:00
parent dfa9ab6529
commit 8ae272ac18

View file

@ -33,13 +33,7 @@ class _ID3(SmallTag, tinytag._ID3):
if len(frame_id) == 4:
self._ID3_WRITE_MAPPING[name] = frame_id
new_frames = self._compose_id3v2_frames()
size = len(new_frames)
new_header = self._compose_id3v2_header(size)
new_tag = new_header + new_frames
new_tag = self._compose_id3v2_tag()
size, extended, major = self._parse_id3v2_header(self._filehandler)
@ -53,7 +47,17 @@ class _ID3(SmallTag, tinytag._ID3):
if should_close_file:
self._filehandler.close()
def _compose_id3v2_header(self, size: int):
def _compose_id3v2_tag(self) -> bytes:
frames = self._compose_id3v2_frames()
frame_size = len(frames)
header = self._compose_id3v2_header(frame_size)
tag = header + frames
return tag
def _compose_id3v2_header(self, size: int) -> bytes:
header = b"ID3\x04\x00\x00"
synchsafe_size = self._synchsafe(size)
@ -61,7 +65,7 @@ class _ID3(SmallTag, tinytag._ID3):
return header
def _compose_id3v2_frames(self):
def _compose_id3v2_frames(self) -> bytes:
tag_dict = self.as_dict()
frames = b""
@ -74,7 +78,7 @@ class _ID3(SmallTag, tinytag._ID3):
return frames
def _compose_id3v2_frame(self, field_name, field_value):
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]