BODY once told me

This commit is contained in:
Connor Olding 2014-04-27 06:46:24 -07:00
parent e5b036d9b8
commit 6a1562c5f5

View file

@ -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)