From 46f7ce78f138b60a81b5dff295e21ac7bbd3bf2a Mon Sep 17 00:00:00 2001 From: David Logie Date: Sat, 9 Sep 2017 18:59:22 +0100 Subject: [PATCH 1/3] mbcollection: Support specifiying collection ID. --- beetsplug/mbcollection.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/beetsplug/mbcollection.py b/beetsplug/mbcollection.py index 99cb30d15..9c13b66fd 100644 --- a/beetsplug/mbcollection.py +++ b/beetsplug/mbcollection.py @@ -60,10 +60,33 @@ 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: {0}'.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 +105,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 = [] From 7db09c6abae9482acea0e8b2d6284943c2bbfe22 Mon Sep 17 00:00:00 2001 From: David Logie Date: Sat, 9 Sep 2017 19:13:44 +0100 Subject: [PATCH 2/3] Silence pep8 warning. --- beetsplug/mbcollection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/mbcollection.py b/beetsplug/mbcollection.py index 9c13b66fd..bd6e84188 100644 --- a/beetsplug/mbcollection.py +++ b/beetsplug/mbcollection.py @@ -81,7 +81,8 @@ class MusicBrainzCollectionPlugin(BeetsPlugin): collection = self.config['collection'].as_str() if collection: if collection not in collection_ids: - raise ui.UserError(u'invalid collection ID: {0}'.format(collection)) + raise ui.UserError(u'invalid collection ID: {}' + .format(collection)) return collection # No specified collection. Just return the first collection ID From 8eb233331c1f518c43046f7904ad47a59839d5b5 Mon Sep 17 00:00:00 2001 From: David Logie Date: Sat, 9 Sep 2017 21:38:33 +0100 Subject: [PATCH 3/3] Update changelog/docs for new ``mbcollection.collection`` option. --- docs/changelog.rst | 3 +++ docs/plugins/mbcollection.rst | 2 ++ 2 files changed, 5 insertions(+) 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``.