diff --git a/beetsplug/mbcollection.py b/beetsplug/mbcollection.py index 1abdfec51..95c3beef3 100644 --- a/beetsplug/mbcollection.py +++ b/beetsplug/mbcollection.py @@ -54,7 +54,9 @@ def submit_albums(collection_id, release_ids): ) -def update_collection(lib, opts, args): +def update_album_list(album_list): + """Update the MusicBrainz colleciton from a list of Beets albums + """ # Get the collection to modify. collections = mb_call(musicbrainzngs.get_collections) if not collections['collection-list']: @@ -63,7 +65,7 @@ def update_collection(lib, opts, args): # Get a list of all the album IDs. album_ids = [] - for album in lib.albums(): + for album in album_list: aid = album.mb_albumid if aid: if re.match(UUID_REGEX, aid): @@ -76,6 +78,11 @@ def update_collection(lib, opts, args): submit_albums(collection_id, album_ids) print('...MusicBrainz collection updated.') + +def update_collection(lib, opts, args): + update_album_list(lib.albums()) + + update_mb_collection_cmd = Subcommand('mbupdate', help='Update MusicBrainz collection') update_mb_collection_cmd.func = update_collection @@ -88,6 +95,18 @@ class MusicBrainzCollectionPlugin(BeetsPlugin): config['musicbrainz']['user'].get(unicode), config['musicbrainz']['pass'].get(unicode), ) + self.config.add({'auto': False}) + self.automatic = self.config['auto'].get(bool) + self.import_stages = [self.imported] def commands(self): return [update_mb_collection_cmd] + + def imported(self, session, task): + """Add each added album to the musicbrainz collection + """ + if not self.automatic: + return + + if task.is_album: + update_album_list([task.album]) diff --git a/docs/plugins/mbcollection.rst b/docs/plugins/mbcollection.rst index dc59ad88c..bab73e2e8 100644 --- a/docs/plugins/mbcollection.rst +++ b/docs/plugins/mbcollection.rst @@ -18,3 +18,17 @@ Then, use the ``beet mbupdate`` command to send your albums to MusicBrainz. The command automatically adds all of your albums to the first collection it finds. If you don't have a MusicBrainz collection yet, you may need to add one to your profile first. + +Auto Update Mode +---------------- + +You can now add each imported album to your MusicBrainz collection, without +needing a separate ``beet mbupdate`` command. To do this, first enable the +plugin and add your MusicBrainz account using the instructions above. Then, +add a block for the ``mbcollection`` plugin to enable ``auto`` configuration:: + + mbcollection: + auto: yes + +During future imports, your default collection will be updated with the +imported album. \ No newline at end of file