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