diff --git a/beetsplug/mbcollection.py b/beetsplug/mbcollection.py index 99cb30d15..bd6e84188 100644 --- a/beetsplug/mbcollection.py +++ b/beetsplug/mbcollection.py @@ -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 = [] diff --git a/docs/changelog.rst b/docs/changelog.rst index 1bf02a83e..1c86011fd 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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: diff --git a/docs/plugins/mbcollection.rst b/docs/plugins/mbcollection.rst index df9a5ddc8..f48996164 100644 --- a/docs/plugins/mbcollection.rst +++ b/docs/plugins/mbcollection.rst @@ -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``.