Skip to content

Commit

Permalink
Centralize check and string literal into MusicBrainzAPIError.__init__…
Browse files Browse the repository at this point in the history
… for #1190
  • Loading branch information
tomjaspers committed Jan 26, 2015
1 parent 67e1065 commit e7f3987
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions beets/autotag/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MusicBrainzAPIError(util.HumanReadableException):
"""
def __init__(self, reason, verb, query, tb=None):
self.query = query
if isinstance(reason, musicbrainzngs.WebServiceError):
reason = 'MusicBrainz not reachable'
super(MusicBrainzAPIError, self).__init__(reason, verb, tb)

def get_message(self):
Expand Down Expand Up @@ -325,11 +327,6 @@ def match_album(artist, album, tracks=None):
try:
res = musicbrainzngs.search_releases(
limit=config['musicbrainz']['searchlimit'].get(int), **criteria)
except musicbrainzngs.WebServiceError:
log.debug(u'MusicBrainz is unreachable.')
raise MusicBrainzAPIError('MusicBrainz not reachable',
'release search', criteria,
traceback.format_exc())
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, 'release search', criteria,
traceback.format_exc())
Expand All @@ -356,11 +353,6 @@ def match_track(artist, title):
try:
res = musicbrainzngs.search_recordings(
limit=config['musicbrainz']['searchlimit'].get(int), **criteria)
except musicbrainzngs.WebServiceError:
log.debug(u'MusicBrainz is unreachable.')
raise MusicBrainzAPIError('MusicBrainz not reachable',
'recording search', criteria,
traceback.format_exc())
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, 'recording search', criteria,
traceback.format_exc())
Expand Down Expand Up @@ -393,11 +385,6 @@ def album_for_id(releaseid):
except musicbrainzngs.ResponseError:
log.debug(u'Album ID match failed.')
return None
except musicbrainzngs.WebServiceError:
log.debug(u'MusicBrainz is unreachable.')
raise MusicBrainzAPIError('MusicBrainz not reachable',
'get release by ID', albumid,
traceback.format_exc())
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, 'get release by ID', albumid,
traceback.format_exc())
Expand All @@ -417,11 +404,6 @@ def track_for_id(releaseid):
except musicbrainzngs.ResponseError:
log.debug(u'Track ID match failed.')
return None
except musicbrainzngs.WebServiceError:
log.debug(u'MusicBrainz is unreachable.')
raise MusicBrainzAPIError('MusicBrainz not reachable',
'get recording by ID', trackid,
traceback.format_exc())
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(exc, 'get recording by ID', trackid,
traceback.format_exc())
Expand Down

0 comments on commit e7f3987

Please sign in to comment.