diff --git a/unsync.py b/unsync.py index a4efd7e..eaa94dc 100755 --- a/unsync.py +++ b/unsync.py @@ -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):