BODY once told me
This commit is contained in:
parent
e5b036d9b8
commit
6a1562c5f5
1 changed files with 30 additions and 29 deletions
59
unsync.py
59
unsync.py
|
@ -50,6 +50,17 @@ mutagen.easyid3.EasyID3.RegisterKey('rating', rating_get, rating_set, rating_del
|
||||||
def safetydance(d, k):
|
def safetydance(d, k):
|
||||||
if k in d: return 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):
|
def shouldsync(md):
|
||||||
rating = -1
|
rating = -1
|
||||||
sync = u''
|
sync = u''
|
||||||
|
@ -90,41 +101,31 @@ def run(args):
|
||||||
goodexts = ('.mp3', '.m4a', '.flac', '.ogg')
|
goodexts = ('.mp3', '.m4a', '.flac', '.ogg')
|
||||||
tosync = []
|
tosync = []
|
||||||
indir = args[1]
|
indir = args[1]
|
||||||
walker = os.walk(indir)
|
paths = lambda dir: filterext(walkfiles(os.walk(dir)), goodexts)
|
||||||
|
|
||||||
# TODO: abstract to mdloop(callback)
|
for p in paths(indir):
|
||||||
for root, _, files in walker:
|
md = mutagen.File(p, easy=True)
|
||||||
for f in files:
|
if shouldsync(md):
|
||||||
ext = os.path.splitext(f)[1].lower()
|
if inonly: print(p)
|
||||||
if not ext in goodexts: continue
|
else: tosync.append(md)
|
||||||
path = os.path.join(root, f)
|
|
||||||
md = mutagen.File(path, easy=True)
|
|
||||||
if shouldsync(md):
|
|
||||||
if inonly: print(path)
|
|
||||||
else: tosync.append(md)
|
|
||||||
|
|
||||||
if inonly: return
|
if inonly: return
|
||||||
print("Beginning matching...", file=sys.stderr)
|
print("Beginning matching...", file=sys.stderr)
|
||||||
|
|
||||||
outdir = args[2]
|
outdir = args[2]
|
||||||
walker = os.walk(outdir)
|
for p in paths(outdir):
|
||||||
for root, _, files in walker:
|
md = mutagen.File(p, easy=True)
|
||||||
for f in files:
|
match = findmatching(tosync, md)
|
||||||
ext = os.path.splitext(f)[1].lower()
|
# TODO: don't print anything
|
||||||
if not ext in goodexts: continue
|
# TODO: don't match mismatched lengths (Xing?)
|
||||||
path = os.path.join(root, f)
|
# TODO: update important tags on mostly matching files
|
||||||
md = mutagen.File(path, easy=True)
|
# TODO: don't sync files that wouldn't match!
|
||||||
match = findmatching(tosync, md)
|
# TODO: convert files in loop that works on altered tosync
|
||||||
# TODO: don't print anything
|
if match:
|
||||||
# TODO: don't match mismatched lengths (Xing?)
|
print("MATCHING", p)
|
||||||
# TODO: update important tags on mostly matching files
|
else:
|
||||||
# TODO: don't sync files that wouldn't match!
|
# TODO: just delete missing ones here
|
||||||
# TODO: convert files in loop that works on altered tosync
|
print("MISSING", p)
|
||||||
if match:
|
|
||||||
print("MATCHING", path)
|
|
||||||
else:
|
|
||||||
# TODO: just delete missing ones here
|
|
||||||
print("MISSING", path)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run(sys.argv)
|
run(sys.argv)
|
||||||
|
|
Loading…
Reference in a new issue