mirror of
https://github.com/beetbox/beets.git
synced 2025-12-26 10:34:09 +01:00
Merge pull request #2685 from beetbox/mbc-customids
mbcollection: Support specifiying collection ID.
This commit is contained in:
commit
cdd440244b
3 changed files with 31 additions and 14 deletions
|
|
@ -60,10 +60,34 @@ class MusicBrainzCollectionPlugin(BeetsPlugin):
|
|||
config['musicbrainz']['user'].as_str(),
|
||||
config['musicbrainz']['pass'].as_str(),
|
||||
)
|
||||
self.config.add({'auto': False})
|
||||
self.config.add({
|
||||
'auto': False,
|
||||
'collection': u'',
|
||||
})
|
||||
if self.config['auto']:
|
||||
self.import_stages = [self.imported]
|
||||
|
||||
def _get_collection(self):
|
||||
collections = mb_call(musicbrainzngs.get_collections)
|
||||
if not collections['collection-list']:
|
||||
raise ui.UserError(u'no collections exist for user')
|
||||
|
||||
# Get all collection IDs, avoiding event collections
|
||||
collection_ids = [x['id'] for x in collections['collection-list']]
|
||||
if not collection_ids:
|
||||
raise ui.UserError(u'No collection found.')
|
||||
|
||||
# Check that the collection exists so we can present a nice error
|
||||
collection = self.config['collection'].as_str()
|
||||
if collection:
|
||||
if collection not in collection_ids:
|
||||
raise ui.UserError(u'invalid collection ID: {}'
|
||||
.format(collection))
|
||||
return collection
|
||||
|
||||
# No specified collection. Just return the first collection ID
|
||||
return collection_ids[0]
|
||||
|
||||
def commands(self):
|
||||
mbupdate = Subcommand('mbupdate',
|
||||
help=u'Update MusicBrainz collection')
|
||||
|
|
@ -82,19 +106,7 @@ class MusicBrainzCollectionPlugin(BeetsPlugin):
|
|||
def update_album_list(self, album_list):
|
||||
"""Update the MusicBrainz collection from a list of Beets albums
|
||||
"""
|
||||
# Get the available collections.
|
||||
collections = mb_call(musicbrainzngs.get_collections)
|
||||
if not collections['collection-list']:
|
||||
raise ui.UserError(u'no collections exist for user')
|
||||
|
||||
# Get the first release collection. MusicBrainz also has event
|
||||
# collections, so we need to avoid adding to those.
|
||||
for collection in collections['collection-list']:
|
||||
if 'release-count' in collection:
|
||||
collection_id = collection['id']
|
||||
break
|
||||
else:
|
||||
raise ui.UserError(u'No collection found.')
|
||||
collection_id = self._get_collection()
|
||||
|
||||
# Get a list of all the album IDs.
|
||||
album_ids = []
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ New features:
|
|||
* :doc:`/plugins/fetchart`: The plugin has now a quiet switch that will only
|
||||
display missing album arts. Thanks to :user:`euri10`.
|
||||
:bug:`2683`
|
||||
* :doc:`/plugins/mbcollection`: The plugin now supports a custom MusicBrainz
|
||||
collection via the ``collection`` configuration option.
|
||||
:bug:`2685`
|
||||
|
||||
Fixes:
|
||||
|
||||
|
|
|
|||
|
|
@ -29,3 +29,5 @@ configuration file. There is one option available:
|
|||
- **auto**: Automatically amend your MusicBrainz collection whenever you
|
||||
import a new album.
|
||||
Default: ``no``.
|
||||
- **collection**: Which MusicBrainz collection to update.
|
||||
Default: ``None``.
|
||||
|
|
|
|||
Loading…
Reference in a new issue