Merge pull request #2447 from robbat2/discogs-simpleauth

discogs: support simple auth.
This commit is contained in:
Adrian Sampson 2017-02-21 09:47:15 -05:00
commit 1373c0c7b8
2 changed files with 26 additions and 4 deletions

View file

@ -54,9 +54,11 @@ class DiscogsPlugin(BeetsPlugin):
'apisecret': 'plxtUTqoCzwxZpqdPysCwGuBSmZNdZVy',
'tokenfile': 'discogs_token.json',
'source_weight': 0.5,
'user_token': None,
})
self.config['apikey'].redact = True
self.config['apisecret'].redact = True
self.config['user_token'].redact = True
self.discogs_client = None
self.register_listener('import_begin', self.setup)
@ -66,6 +68,12 @@ class DiscogsPlugin(BeetsPlugin):
c_key = self.config['apikey'].as_str()
c_secret = self.config['apisecret'].as_str()
user_token = self.config['user_token'].as_str()
if user_token is not None and user_token != '':
self.discogs_client = Client(USER_AGENT, user_token=user_token)
return
# Get the OAuth token from a file or log in.
try:
with open(self._tokenfile()) as f:

View file

@ -14,10 +14,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 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.
You will also need to register for a `Discogs`_ account, and provide
authentication credentials via a personal access token or an OAuth2
authorization.
Matches from Discogs will now show up during import alongside matches from
MusicBrainz.
@ -25,6 +24,21 @@ MusicBrainz.
If you have a Discogs ID for an album you want to tag, you can also enter it
at the "enter Id" prompt in the importer.
OAuth authorization
```````````````````
The first time you 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.
Authentication via personal access token
````````````````````````````````````````
To get a personal access token (called a user token in the `discogs-client`_
documentation), login to `Discogs`_, and visit the
`Developer settings page
<https://www.discogs.com/settings/developers>`_. Press the ``Generate new
token`` button, and place the generated token in your configuration, as the
``user_token`` config option in the ``discogs`` section.
Troubleshooting
---------------