mirror of
https://github.com/beetbox/beets.git
synced 2026-01-30 20:13:37 +01:00
mbcollection: human-readable MB exceptions
Fixes #107 by wrapping the API invocation function with exception handlers.
This commit is contained in:
parent
698e54edbc
commit
1fbbe61546
2 changed files with 19 additions and 4 deletions
|
|
@ -23,6 +23,18 @@ from musicbrainzngs import musicbrainz
|
|||
|
||||
SUBMISSION_CHUNK_SIZE = 200
|
||||
|
||||
def mb_request(*args, **kwargs):
|
||||
"""Send a MusicBrainz API request and process exceptions.
|
||||
"""
|
||||
try:
|
||||
return musicbrainz._mb_request(*args, **kwargs)
|
||||
except musicbrainzngs.AuthenticationError:
|
||||
raise ui.UserError('authentication with MusicBrainz failed')
|
||||
except musicbrainzngs.ResponseError as exc:
|
||||
raise ui.UserError('MusicBrainz API error: {0}'.format(exc))
|
||||
except musicbrainzngs.UsageError:
|
||||
raise ui.UserError('MusicBrainz credentials missing')
|
||||
|
||||
def submit_albums(collection_id, release_ids):
|
||||
"""Add all of the release IDs to the indicated collection. Multiple
|
||||
requests are made if there are many release IDs to submit.
|
||||
|
|
@ -30,15 +42,16 @@ def submit_albums(collection_id, release_ids):
|
|||
for i in range(0, len(release_ids), SUBMISSION_CHUNK_SIZE):
|
||||
chunk = release_ids[i:i+SUBMISSION_CHUNK_SIZE]
|
||||
releaselist = ";".join(chunk)
|
||||
musicbrainz._mb_request(
|
||||
mb_request(
|
||||
"collection/%s/releases/%s" % (collection_id, releaselist),
|
||||
'PUT', True, True, body='foo')
|
||||
'PUT', True, True, body='foo'
|
||||
)
|
||||
# A non-empty request body is required to avoid a 411 "Length
|
||||
# Required" error from the MB server.
|
||||
|
||||
def update_collection(lib, opts, args):
|
||||
# Get the collection to modify.
|
||||
collections = musicbrainz._mb_request('collection', 'GET', True, True)
|
||||
collections = mb_request('collection', 'GET', True, True)
|
||||
if not collections['collection-list']:
|
||||
raise ui.UserError('no collections exist for user')
|
||||
collection_id = collections['collection-list'][0]['id']
|
||||
|
|
@ -60,7 +73,7 @@ class MusicBrainzCollectionPlugin(BeetsPlugin):
|
|||
super(MusicBrainzCollectionPlugin, self).__init__()
|
||||
musicbrainzngs.auth(
|
||||
config['musicbrainz']['user'].get(unicode),
|
||||
config['musicbrainz']['pass'].get(unicode)
|
||||
config['musicbrainz']['pass'].get(unicode),
|
||||
)
|
||||
|
||||
def commands(self):
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ Other stuff:
|
|||
pathnames.
|
||||
* Fix a spurious warning from the Unidecode module when matching albums that
|
||||
are missing all metadata.
|
||||
* :doc:`/plugins/mbcollection`: Show friendly, human-readable errors when
|
||||
MusicBrainz exceptions occur.
|
||||
|
||||
1.1b2 (February 16, 2013)
|
||||
-------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue