|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
import mutagen
|
|
|
import mutagen.id3
|
|
|
+import mutagen.mp4
|
|
|
import os
|
|
|
import subprocess
|
|
|
|
|
@@ -17,7 +18,7 @@ def generate_uuid():
|
|
|
|
|
|
|
|
|
def get_uuid(id3_tags):
|
|
|
- assert isinstance(id3_tags, mutagen.id3.ID3)
|
|
|
+ assert isinstance(id3_tags, mutagen.id3.ID3), type(id3_tags)
|
|
|
ufids = id3_tags.getall('UFID')
|
|
|
for ufid in ufids:
|
|
|
if ufid.owner == TRACK_UUID_ID3_OWNER_ID:
|
|
@@ -41,15 +42,28 @@ def get_or_assign_uuid(id3_tags):
|
|
|
return uuid
|
|
|
|
|
|
|
|
|
-def symuid(track_path):
|
|
|
- f = mutagen.File(filename=track_path)
|
|
|
- print(get_or_assign_uuid(f.tags))
|
|
|
+def symuid(path):
|
|
|
+ if os.path.isdir(path):
|
|
|
+ for dirpath, dirnames, filenames in os.walk(path):
|
|
|
+ for filename in filenames:
|
|
|
+ symuid(os.path.join(dirpath, filename))
|
|
|
+ else:
|
|
|
+ try:
|
|
|
+ f = mutagen.File(filename=path)
|
|
|
+ except Exception:
|
|
|
+ raise Exception(path)
|
|
|
+ if not f:
|
|
|
+ print("{!r}: unsupported filetype, ignored".format(path))
|
|
|
+ elif isinstance(f.tags, mutagen.mp4.MP4Tags):
|
|
|
+ print("{!r}: mp4 tags not supported, ignored".format(path))
|
|
|
+ else:
|
|
|
+ get_or_assign_uuid(f.tags)
|
|
|
|
|
|
|
|
|
def _init_argparser():
|
|
|
import argparse
|
|
|
argparser = argparse.ArgumentParser(description=None)
|
|
|
- argparser.add_argument('track_path')
|
|
|
+ argparser.add_argument('path')
|
|
|
return argparser
|
|
|
|
|
|
|