|
@@ -9,6 +9,8 @@ import re
|
|
import subprocess
|
|
import subprocess
|
|
import sys
|
|
import sys
|
|
|
|
|
|
|
|
+import symuid
|
|
|
|
+
|
|
# http://id3.org/id3v2.4.0-frames#4.1.
|
|
# http://id3.org/id3v2.4.0-frames#4.1.
|
|
TRACK_UUID_ID3_OWNER_ID = 'symuid'
|
|
TRACK_UUID_ID3_OWNER_ID = 'symuid'
|
|
# freeform keys start with '----'
|
|
# freeform keys start with '----'
|
|
@@ -61,33 +63,25 @@ def get_or_assign_uuid_mp4(mp4_file):
|
|
return mp4_file[TRACK_UUID_MP4_TAG][0]
|
|
return mp4_file[TRACK_UUID_MP4_TAG][0]
|
|
|
|
|
|
|
|
|
|
|
|
+def log_path(track_path, msg, stream=sys.stdout):
|
|
|
|
+ stream.write("{!r}: {}\n".format(track_path, msg))
|
|
|
|
+
|
|
|
|
+def log_path_error(track_path, msg):
|
|
|
|
+ log_path(track_path, msg, stream=sys.stderr)
|
|
|
|
+
|
|
def symuid_sync(path, path_ignore_regex, show_ignored=False):
|
|
def symuid_sync(path, path_ignore_regex, show_ignored=False):
|
|
- if path_ignore_regex.search(path):
|
|
|
|
- if show_ignored:
|
|
|
|
- print("{!r}: path matches ignore pattern".format(path))
|
|
|
|
- elif os.path.isdir(path):
|
|
|
|
- for dirpath, dirnames, filenames in os.walk(path):
|
|
|
|
- for filename in filenames:
|
|
|
|
- symuid_sync(
|
|
|
|
- os.path.join(dirpath, filename),
|
|
|
|
- path_ignore_regex,
|
|
|
|
- show_ignored,
|
|
|
|
- )
|
|
|
|
- else:
|
|
|
|
- try:
|
|
|
|
- f = mutagen.File(filename=path)
|
|
|
|
- except Exception:
|
|
|
|
- raise Exception(path)
|
|
|
|
- if not f:
|
|
|
|
- sys.stderr.write(
|
|
|
|
- "{!r}: unsupported filetype, skipped\n".format(path),
|
|
|
|
- )
|
|
|
|
- elif isinstance(f, mutagen.mp4.MP4):
|
|
|
|
- get_or_assign_uuid_mp4(f)
|
|
|
|
- elif isinstance(f.tags, mutagen.id3.ID3):
|
|
|
|
- get_or_assign_uuid_id3(f.tags)
|
|
|
|
|
|
+ for track in symuid.Track.walk(
|
|
|
|
+ root_path=path,
|
|
|
|
+ path_ignore_regex=path_ignore_regex,
|
|
|
|
+ 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 isinstance(track._iface, symuid.tag_interface.ID3):
|
|
|
|
+ get_or_assign_uuid_id3(track._iface._mutagen_file.tags)
|
|
else:
|
|
else:
|
|
- raise Exception(f)
|
|
|
|
|
|
+ raise Exception(track)
|
|
|
|
|
|
|
|
|
|
def _init_argparser():
|
|
def _init_argparser():
|