From d1ea33024334b482926c22faf02b34376bb5f36e Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 27 Apr 2014 07:17:32 -0700 Subject: [PATCH] but i ain't the sharpest tool in the shed --- unsync.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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):