Browse Source

added tag_interface.MP4._set_free()

Fabian Peter Hammerle 6 years ago
parent
commit
838cd3afeb
1 changed files with 11 additions and 8 deletions
  1. 11 8
      symuid/tag_interface.py

+ 11 - 8
symuid/tag_interface.py

@@ -114,26 +114,29 @@ class MP4(_mutagen):
         assert tag is None or tag.dataformat == mutagen.mp4.AtomDataType.UUID, tag.dataformat
         return tag
 
+    def _set_free(self, tag_label, dataformat, data):
+        assert isinstance(data, bytes)
+        tag = mutagen.mp4.MP4FreeForm(dataformat=dataformat, data=data)
+        self._mutagen_file.tags['----:' + tag_label] = [tag]
+        return tag
+
     def set_free_int(self, tag_label, data):
         assert isinstance(data, int)
-        tag = mutagen.mp4.MP4FreeForm(
+        return self._set_free(
+            tag_label=tag_label,
             # "a signed big-endian integer with length one of { 1,2,3,4,8 } bytes"
             dataformat=mutagen.mp4.AtomDataType.INTEGER,
             # TODO set byte length properly
             data=data.to_bytes(1, byteorder='big', signed=True),
         )
-        self._mutagen_file.tags['----:' + tag_label] = tag
-        return tag
 
     def _set_free_uuid(self, tag_label, data):
-        assert isinstance(data, bytes)
-        tag = mutagen.mp4.MP4FreeForm(
-            data=data,
+        return self._set_free(
+            tag_label=tag_label,
             # https://mutagen.readthedocs.io/en/latest/api/mp4.html#mutagen.mp4.AtomDataType.UUID
             dataformat=mutagen.mp4.AtomDataType.UUID,
+            data=data,
         )
-        self._mutagen_file.tags['----:' + tag_label] = [tag]
-        return tag
 
     def get_track_uuid(self):
         return self._get_free_uuid(self._UUID_TAG_KEY)