Created
April 19, 2010 20:18
-
-
Save jpstacey/371541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Music collection reconcile - which tracks are new locally/on external HD? | |
# | |
# Basically a poor-man's rsync, but it seems faster for solely this task. Also | |
# less likely to generate false positives, although it can make false negatives | |
# e.g. if files have been changed (ID3 information etc.) | |
import sys | |
import glob | |
def reconcile(l,r): | |
lr = { | |
'local': { | |
'arg': l, 'tracks': [], 'extra': [], 'other': 'remote' | |
}, | |
'remote': { | |
'arg': r, 'tracks': [], 'extra': [], 'other': 'local' | |
} | |
} | |
print "Globbing both directories..." | |
for k,v in lr.items(): | |
v['tracks'] = glob.glob(v['arg'] + "*/*/*.*") | |
for k,v in lr.items(): | |
print "Checking for new %s tracks..." % k | |
for t in [t for t in v['tracks'] if not t.replace(v['arg'], lr[v['other']]['arg']) in lr[v['other']]['tracks']]: | |
v['extra'].append(t) | |
print "Done." | |
# Report any unmatched files | |
for k,v in lr.items(): | |
if v['extra']: | |
print "New %s tracks:" % k | |
print "\t" + "\n\t".join(v['extra']) | |
try: | |
# Normalize both directories for ease of stripping them off globs | |
dir_local = sys.argv[1].rstrip("/") + "/" | |
dir_remote = sys.argv[2].rstrip("/") + "/" | |
# Run reconcile | |
reconcile(dir_local, dir_remote) | |
except IndexError: | |
print "Usage: %s dir_local dir_remote" % sys.argv[0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment