BODY once told me
This commit is contained in:
parent
e5b036d9b8
commit
6a1562c5f5
1 changed files with 30 additions and 29 deletions
37
unsync.py
37
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,30 +101,20 @@ 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)
|
||||
for p in paths(indir):
|
||||
md = mutagen.File(p, easy=True)
|
||||
if shouldsync(md):
|
||||
if inonly: print(path)
|
||||
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)
|
||||
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?)
|
||||
|
@ -121,10 +122,10 @@ def run(args):
|
|||
# TODO: don't sync files that wouldn't match!
|
||||
# TODO: convert files in loop that works on altered tosync
|
||||
if match:
|
||||
print("MATCHING", path)
|
||||
print("MATCHING", p)
|
||||
else:
|
||||
# TODO: just delete missing ones here
|
||||
print("MISSING", path)
|
||||
print("MISSING", p)
|
||||
|
||||
try:
|
||||
run(sys.argv)
|
||||
|
|
Loading…
Reference in a new issue