|
@@ -27,6 +27,12 @@ class Track:
|
|
|
def has_mp4_tags(self):
|
|
|
return self.has_tags and isinstance(self._mutagen.tags, mutagen.mp4.MP4Tags)
|
|
|
|
|
|
+ def _get_mp4_freeform_int(self, tag_label):
|
|
|
+ tag, = self._mutagen.tags['----:' + tag_label]
|
|
|
+
|
|
|
+ assert tag.dataformat == mutagen.mp4.AtomDataType.INTEGER, tag.dataformat
|
|
|
+ return int.from_bytes(tag, byteorder='big', signed=True)
|
|
|
+
|
|
|
def _set_mp4_freeform_int(self, tag_label, data):
|
|
|
assert isinstance(data, int)
|
|
|
tag = mutagen.mp4.MP4FreeForm(
|
|
@@ -63,17 +69,10 @@ class Track:
|
|
|
if tag_set_cb:
|
|
|
tag_set_cb(self, tag)
|
|
|
elif self.has_mp4_tags:
|
|
|
- tag_label_mp4 = '----:' + tag_label
|
|
|
- if tag_label_mp4 in self._mutagen.tags:
|
|
|
- reg_data = self._mutagen.tags[tag_label_mp4]
|
|
|
- assert len(reg_data) == 1, reg_data
|
|
|
- reg_count = int.from_bytes(
|
|
|
- bytes=reg_data[0],
|
|
|
- byteorder='big',
|
|
|
- signed=True,
|
|
|
- )
|
|
|
+ try:
|
|
|
+ reg_count = self._get_mp4_freeform_int(tag_label)
|
|
|
assert reg_count == play_count, (reg_count, play_count)
|
|
|
- else:
|
|
|
+ except KeyError:
|
|
|
tag = self._set_mp4_freeform_int(
|
|
|
tag_label=tag_label,
|
|
|
data=play_count,
|