From 6a1562c5f55f98c368d310de9d0cef9b5e8dafbc Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 27 Apr 2014 06:46:24 -0700 Subject: [PATCH] BODY once told me --- unsync.py | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/unsync.py b/unsync.py index 6c5bd86..d96508c 100755 --- a/unsync.py +++ b/unsync.py @@ -50,6 +50,17 @@ mutagen.easyid3.EasyID3.RegisterKey('rating', rating_get, rating_set, rating_del def safetydance(d, k): if k in d: return d[k] +def walkfiles(walker): + for root, _, files in walker: + for f in files: + yield os.path.join(root, f) + +def filterext(paths, exts): + for p in paths: + ext = os.path.splitext(p)[1].lower() + if ext in exts: + yield p + def shouldsync(md): rating = -1 sync = u'' @@ -90,41 +101,31 @@ def run(args): goodexts = ('.mp3', '.m4a', '.flac', '.ogg') tosync = [] indir = args[1] - walker = os.walk(indir) + paths = lambda dir: filterext(walkfiles(os.walk(dir)), goodexts) - # TODO: abstract to mdloop(callback) - for root, _, files in walker: - for f in files: - ext = os.path.splitext(f)[1].lower() - if not ext in goodexts: continue - path = os.path.join(root, f) - md = mutagen.File(path, easy=True) - if shouldsync(md): - if inonly: print(path) - else: tosync.append(md) + for p in paths(indir): + md = mutagen.File(p, easy=True) + if shouldsync(md): + if inonly: print(p) + else: tosync.append(md) if inonly: return print("Beginning matching...", file=sys.stderr) outdir = args[2] - walker = os.walk(outdir) - for root, _, files in walker: - for f in files: - ext = os.path.splitext(f)[1].lower() - if not ext in goodexts: continue - path = os.path.join(root, f) - md = mutagen.File(path, easy=True) - match = findmatching(tosync, md) - # TODO: don't print anything - # TODO: don't match mismatched lengths (Xing?) - # TODO: update important tags on mostly matching files - # TODO: don't sync files that wouldn't match! - # TODO: convert files in loop that works on altered tosync - if match: - print("MATCHING", path) - else: - # TODO: just delete missing ones here - print("MISSING", path) + for p in paths(outdir): + md = mutagen.File(p, easy=True) + match = findmatching(tosync, md) + # TODO: don't print anything + # TODO: don't match mismatched lengths (Xing?) + # TODO: update important tags on mostly matching files + # TODO: don't sync files that wouldn't match! + # TODO: convert files in loop that works on altered tosync + if match: + print("MATCHING", p) + else: + # TODO: just delete missing ones here + print("MISSING", p) try: run(sys.argv)