beets
beets copied to clipboard
Update Beatport plugin to use API v4
Description
Fixes #3862
As Beatport had killed their API v3, the stock beatport plugin does not work anymore. It is also currently not possible to request the access to the API "normal" way (by using your client credentials or API token generated by Beatport, see the linked issue #3862). I have found a workaround and was able to update the code to use the new specification of API v4.
Currently, to use the plugin, you need to obtain the access token yourself. As soon as Beatport allows official way of the authorization, I am willing to update the code to use it, whether it be client_credentials
grant or any other OAuth2 flow they are now presenting in the API docs.
I have also created a beatport4
plugin that uses the above code and added there an unoficcial way of acquiring the token (not part of this PR). To see more details, please see the plugin repository: https://github.com/Samik081/beets-beatport4
Beatport Authorization
Steps:
- Add
beatport
plugin to yourbeets/config.yaml
plugins list - When the first import with plugin enabled happens, you will be prompted to paste the access token JSON
- Obtain a token (currently rather not possible official way, see the description above) in a following format (those two fields are required):
{
"access_token": "XXX",
"expires_in": 36000,
...
}
- Paste it to the terminal (or
beatport_token.json
file next to yourbeets/config.yaml
- you can check the path by runningbeet config --paths
command)
P.S I am not a daily python developer, so don't hesitate to point out anything you think looks ugly :)
EDIT 10.09.2022
Removed authorization part that uses user credentials, Beatport swagger-ui client ID and authorization_code
flow, see the comments.
EDIT 16.09.2022
Edited PR description so it reflects the current code (removed part about Beatport unofficial authorization).
As Beatport had killed their API v3, the stock beatport plugin does not work anymore. It is also currently not possible to request the access to the API "normal" way (by using your client credentials or API token generated by Beatport, see the linked issue #3862), so I have found a workaround that uses public API client ID used for Beatport docs frontend and updated the code to use the new specification of API v4.
I understand that the current beatport situation is frustrating, but (assuming that I understand correctly what your workaround consists of) I'm strongly opposed to merging this branch: Abusing the docs client ID in this way sounds like a surefire way to guarantee that beets will not be granted a proper client ID ever again (when and if they re-open registration). Obviously, it's your business to host a third-party plugin under your profile.
As Beatport had killed their API v3, the stock beatport plugin does not work anymore. It is also currently not possible to request the access to the API "normal" way (by using your client credentials or API token generated by Beatport, see the linked issue #3862), so I have found a workaround that uses public API client ID used for Beatport docs frontend and updated the code to use the new specification of API v4.
I understand that the current beatport situation is frustrating, but (assuming that I understand correctly what your workaround consists of) I'm strongly opposed to merging this branch: Abusing the docs client ID in this way sounds like a surefire way to guarantee that beets will not be granted a proper client ID ever again (when and if they re-open registration). Obviously, it's your business to host a third-party plugin under your profile.
Hey @wisp3rwind, thank you for your input! I agree with you - this is not the way it should be done in official repo.
I am going to delete the username/password configuration, and code responsible for the authorization, but leave the option to paste the OAuth token. This way it is not going to be dependent on docs' client ID. I think using OAuth token provided by user is fine, isn't it? In the future, this is still going to be a decent fallback method if the authorization fails.
The rest of the code is not related to the "workaround" and could be easily used now (by passing the access token if the user has it) or in the future by just implementing Beatport4Client._authorize()
method and passing configuration options.
What do you think?
I have made the refactor I mentioned in the previous comment, but ~~I'll leave the PR description for a little longer to keep the track of what happened in the PR.~~
EDIT: 16.09.2022
I have updated the PR description, so it now describes the current state of the code. More info and code containing authorization part is still available in my repo tho.