|
@@ -21,19 +21,12 @@ def generate_uuid():
|
|
|
return subprocess.check_output(['uuid', '-v', '4', '-F', 'BIN']).strip()
|
|
|
|
|
|
|
|
|
-def get_or_assign_uuid_mp4(mp4_file):
|
|
|
- if not TRACK_UUID_MP4_TAG in mp4_file:
|
|
|
- mp4_file[TRACK_UUID_MP4_TAG] = mutagen.mp4.MP4FreeForm(
|
|
|
- data=generate_uuid(),
|
|
|
- # https://mutagen.readthedocs.io/en/latest/api/mp4.html#mutagen.mp4.AtomDataType.UUID
|
|
|
- dataformat=mutagen.mp4.AtomDataType.UUID,
|
|
|
- )
|
|
|
- mp4_file.save()
|
|
|
- mp4_file.load(filename=mp4_file.filename)
|
|
|
- print("{!r}: assigned uuid {!r}".format(
|
|
|
- mp4_file.filename, mp4_file[TRACK_UUID_MP4_TAG][0],
|
|
|
- ))
|
|
|
- return mp4_file[TRACK_UUID_MP4_TAG][0]
|
|
|
+def assign_uuid_mp4(mp4_file):
|
|
|
+ mp4_file[TRACK_UUID_MP4_TAG] = [mutagen.mp4.MP4FreeForm(
|
|
|
+ data=generate_uuid(),
|
|
|
+ # https://mutagen.readthedocs.io/en/latest/api/mp4.html#mutagen.mp4.AtomDataType.UUID
|
|
|
+ dataformat=mutagen.mp4.AtomDataType.UUID,
|
|
|
+ )]
|
|
|
|
|
|
|
|
|
def log_path(track_path, msg, stream=sys.stdout):
|
|
@@ -51,10 +44,11 @@ def symuid_sync(path, path_ignore_regex, show_ignored=False):
|
|
|
ignored_cb=lambda p: show_ignored and log_path(p, 'ignored'),
|
|
|
unsupported_cb=lambda p, e: log_path_error(p, 'unsupported type, skipped'),
|
|
|
):
|
|
|
- if isinstance(track._iface, symuid.tag_interface.MP4):
|
|
|
- get_or_assign_uuid_mp4(track._iface._mutagen_file)
|
|
|
- elif track._iface.get_uuid() is None:
|
|
|
- track._iface.set_uuid(generate_uuid())
|
|
|
+ if track._iface.get_uuid() is None:
|
|
|
+ if isinstance(track._iface, symuid.tag_interface.MP4):
|
|
|
+ assign_uuid_mp4(track._iface._mutagen_file)
|
|
|
+ else:
|
|
|
+ track._iface.set_uuid(generate_uuid())
|
|
|
track._iface.save()
|
|
|
log_path(track.path, 'assigned uuid {!r}'.format(track._iface.get_uuid()))
|
|
|
|