but i ain't the sharpest tool in the shed

This commit is contained in:
Connor Olding 2014-04-27 07:17:32 -07:00
parent 1a2c9ae1e6
commit d1ea330243

View File

@ -47,8 +47,11 @@ def rating_delete(id3, key):
mutagen.easyid3.EasyID3.RegisterTXXXKey('sync', 'SYNC')
mutagen.easyid3.EasyID3.RegisterKey('rating', rating_get, rating_set, rating_delete)
def safetydance(d, k):
if k in d: return d[k]
def G(d, k):
try:
return d[k]
except KeyError:
return None
def walkfiles(walker):
for root, _, files in walker:
@ -62,8 +65,8 @@ def filterext(paths, exts):
yield p
def shouldsync(md):
rating = safetydance(md, 'rating')
sync = safetydance(md, 'sync')
rating = G(md, 'rating')
sync = G(md, 'sync')
if rating != None:
rating = int(rating[0])
if sync:
@ -80,13 +83,13 @@ def shouldsync(md):
return False
def findmatching(haystack, needle):
artist = safetydance(needle, 'artist')
album = safetydance(needle, 'album')
title = safetydance(needle, 'title')
artist = G(needle, 'artist')
album = G(needle, 'album')
title = G(needle, 'title')
for match in haystack:
if artist == safetydance(match, 'artist') \
and album == safetydance(match, 'album') \
and title == safetydance(match, 'title'):
if artist == G(match, 'artist') \
and album == G(match, 'album') \
and title == G(match, 'title'):
return match
def run(args):