she was looking kinda dumb
This commit is contained in:
parent
d1ea330243
commit
6ae05ac68d
1 changed files with 50 additions and 17 deletions
63
unsync.py
63
unsync.py
|
@ -68,7 +68,10 @@ def shouldsync(md):
|
||||||
rating = G(md, 'rating')
|
rating = G(md, 'rating')
|
||||||
sync = G(md, 'sync')
|
sync = G(md, 'sync')
|
||||||
if rating != None:
|
if rating != None:
|
||||||
|
try:
|
||||||
rating = int(rating[0])
|
rating = int(rating[0])
|
||||||
|
except ValueError:
|
||||||
|
rating = None
|
||||||
if sync:
|
if sync:
|
||||||
sync = sync[0].lower()
|
sync = sync[0].lower()
|
||||||
else:
|
else:
|
||||||
|
@ -82,14 +85,35 @@ def shouldsync(md):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def fixmetadata(md):
|
||||||
|
if 'artist' not in md:
|
||||||
|
md['artist'] = "Unknown Artist"
|
||||||
|
if 'album' not in md:
|
||||||
|
md['album'] = "Unknown Album"
|
||||||
|
if 'title' not in md:
|
||||||
|
fn = os.path.basename(md.path)
|
||||||
|
fn = os.path.splitext(fn)[0]
|
||||||
|
# TODO: attempt to infer trackNum/diskNum from fn
|
||||||
|
md['title'] = fn
|
||||||
|
|
||||||
def findmatching(haystack, needle):
|
def findmatching(haystack, needle):
|
||||||
|
# TODO: don't match mismatched lengths (Xing?)
|
||||||
artist = G(needle, 'artist')
|
artist = G(needle, 'artist')
|
||||||
album = G(needle, 'album')
|
album = G(needle, 'album')
|
||||||
title = G(needle, 'title')
|
title = G(needle, 'title')
|
||||||
for match in haystack:
|
match = None
|
||||||
if artist == G(match, 'artist') \
|
for hay in haystack:
|
||||||
and album == G(match, 'album') \
|
if artist == G(hay, 'artist') \
|
||||||
and title == G(match, 'title'):
|
and album == G(hay, 'album') \
|
||||||
|
and title == G(hay, 'title'):
|
||||||
|
match = hay
|
||||||
|
if match.seen:
|
||||||
|
# TODO: check other tags and filename and such?
|
||||||
|
print("Warning: duplicate match found:", file=sys.stderr)
|
||||||
|
print("{0} by {1} from {2}".format(artist,album,title), file=sys.stderr)
|
||||||
|
else:
|
||||||
|
match.seen = True
|
||||||
|
break
|
||||||
return match
|
return match
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
|
@ -108,26 +132,35 @@ def run(args):
|
||||||
for p in paths(indir):
|
for p in paths(indir):
|
||||||
md = mutagen.File(p, easy=True)
|
md = mutagen.File(p, easy=True)
|
||||||
if shouldsync(md):
|
if shouldsync(md):
|
||||||
if inonly: print(p)
|
if inonly:
|
||||||
else: tosync.append(md)
|
print(p)
|
||||||
|
else:
|
||||||
|
# TODO: don't use custom members on external metadata class
|
||||||
|
md.path = p
|
||||||
|
md.seen = False
|
||||||
|
fixmetadata(md)
|
||||||
|
tosync.append(md)
|
||||||
|
|
||||||
if inonly: return 0
|
if inonly:
|
||||||
|
return 0
|
||||||
|
# TODO: don't print anything
|
||||||
print("Beginning matching...", file=sys.stderr)
|
print("Beginning matching...", file=sys.stderr)
|
||||||
|
|
||||||
outdir = args[2]
|
outdir = args[2]
|
||||||
for p in paths(outdir):
|
for p in paths(outdir):
|
||||||
md = mutagen.File(p, easy=True)
|
md = mutagen.File(p, easy=True)
|
||||||
match = findmatching(tosync, md)
|
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:
|
if match:
|
||||||
print("MATCHING", p)
|
print("UPD", p)
|
||||||
|
# update tags here if updatemetadata returns true
|
||||||
else:
|
else:
|
||||||
# TODO: just delete missing ones here
|
print("DEL", p)
|
||||||
print("MISSING", p)
|
# delete files here
|
||||||
|
|
||||||
|
for md in tosync:
|
||||||
|
if md.seen:
|
||||||
|
continue
|
||||||
|
print("ADD", md.path)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue