diff --git a/beets/importer.py b/beets/importer.py index 0c53b8da7..458039482 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -294,6 +294,7 @@ class ImportSession(object): pl = pipeline.Pipeline(stages) # Run the pipeline. + plugins.send('import_begin', session=self) try: if config['threaded']: pl.run_parallel(QUEUE_SIZE) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index b12802c6a..234d9b6cd 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -1,5 +1,5 @@ # This file is part of beets. -# Copyright 2013, Adrian Sampson. +# Copyright 2014, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -46,7 +46,12 @@ class DiscogsPlugin(BeetsPlugin): 'tokenfile': 'discogs_token.json', 'source_weight': 0.5, }) + self.discogs_client = None + self.register_listener('import_begin', self.setup) + def setup(self): + """Create the `discogs_client` field. Authenticate if necessary. + """ c_key = self.config['apikey'].get(unicode) c_secret = self.config['apisecret'].get(unicode) @@ -102,6 +107,9 @@ class DiscogsPlugin(BeetsPlugin): """Returns a list of AlbumInfo objects for discogs search results matching an album and artist (if not various). """ + if not self.discogs_client: + return + if va_likely: query = album else: @@ -119,6 +127,9 @@ class DiscogsPlugin(BeetsPlugin): """Fetches an album by its Discogs ID and returns an AlbumInfo object or None if the album is not found. """ + if not self.discogs_client: + return + log.debug(u'Searching Discogs for release {0}'.format(str(album_id))) # Discogs-IDs are simple integers. We only look for those at the end # of an input string as to avoid confusion with other metadata plugins. diff --git a/docs/changelog.rst b/docs/changelog.rst index 0f4c908ab..5dfc0c5ae 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,8 @@ Fixed: * Fix a new crash with the latest version of Mutagen (1.26). * We now print a better error message when the database file is corrupted. +* :doc:`/plugins/discogs`: Only prompt for authentication when running the + :ref:`import-cmd` command. :bug:`1123` .. _Plex: https://plex.tv/ diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index 07758adf8..c79d49645 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -183,6 +183,9 @@ currently available are: * *cli_exit*: called just before the ``beet`` command-line program exits. Parameter: ``lib``. +* *import_begin*: called just before a ``beet import`` session starts up. + Parameter: ``session``. + The included ``mpdupdate`` plugin provides an example use case for event listeners. Extend the Autotagger diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index 7c263f324..48332864e 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -15,9 +15,9 @@ To use the ``discogs`` plugin, first enable it in your configuration (see pip install discogs-client You will also need to register for a `Discogs`_ account. The first time you -run beets after enabling the plugin, it will ask you to authorize with Discogs -by visiting the site in a browser. Subsequent runs will not require -re-authorization. +run the :ref:`import-cmd` command after enabling the plugin, it will ask you +to authorize with Discogs by visiting the site in a browser. Subsequent runs +will not require re-authorization. Matches from Discogs will now show up during import alongside matches from MusicBrainz.