beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.86k stars 1.82k forks source link

spotify: Authenticate API requests #2694

Open dtvu opened 7 years ago

dtvu commented 7 years ago

Problem

I was playing around with the Spotify plugin and I noticed that none of my tracks matched a Spotify ID. I wondered if this was potentially related to Spotify removing unauthenticated calls to the web API.

Setup

sampsyo commented 7 years ago

Hmm; interesting. Could you perhaps include some verbose output?

dtvu commented 7 years ago

Sorry, I should have included that before:

$ beet -vv
user configuration: /home/tony/.config/beets/config.yaml
data directory: /home/tony/.config/beets
plugin paths: 
Sending event: pluginload
library database: /home/tony/.config/beets/library.db
library directory: /media/archive/music
Sending event: library_opened
Usage: 
  beet COMMAND [ARGS...]
  beet help COMMAND

Options:
  --format-item=FORMAT_ITEM
                        print with custom format
  --format-album=FORMAT_ALBUM
                        print with custom format
  -l LIBRARY, --library=LIBRARY
                        library database file to use
  -d DIRECTORY, --directory=DIRECTORY
                        destination music directory
  -v, --verbose         log more details (use twice for even more)
  -c CONFIG, --config=CONFIG
                        path to configuration file
  -h, --help            show this help message and exit

Commands:
  clearart          remove images from file metadata
  config            show or edit the user configuration
  embedart          embed image files into file metadata
  extractart        extract an image from file metadata
  fetchart          download album art
  fields            show fields available for queries and format strings
  gmusic-songs      list of songs in Google Play Music library
  gmusic-upload     upload your tracks to Google Play Music
  help (?)          give detailed help on a specific sub-command
  import (imp, im)  import new music
  list (ls)         query the library
  mbsync            update metadata from musicbrainz
  modify (mod)      change metadata fields
  move (mv)         move or copy items
  remove (rm)       remove matching items from the library
  spotify           build a Spotify playlist
  stats             show statistics about the library or a query
  update (upd, up)  update the library
  version           output version information
  write             write tag information to files
Sending event: cli_exit
sampsyo commented 7 years ago

Thanks! Just seeing the setup output is useful in itself, but what would be really helpful is a verbose log from a situation where the problem actually came up. That might include messages that show failed requests to the Spotify API, for example.

dtvu commented 7 years ago

Can do!

$ beet -vv spotify "Andrew Belle"
user configuration: /home/tony/.config/beets/config.yaml
data directory: /home/tony/.config/beets
plugin paths: 
Sending event: pluginload
library database: /home/tony/.config/beets/library.db
library directory: /media/archive/music
Sending event: library_opened
spotify: Processing 10 tracks...
spotify: https://api.spotify.com/v1/search?q=Dark+Matter+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Pieces+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Sister+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Black+Bear+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Wants+What+It+Wants+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Details+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Santa+Fe+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=The+Enemy+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=Many+Lives+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: https://api.spotify.com/v1/search?q=I+Won%27t+Fight+It+album%3ABlack+Bear+artist%3AAndrew+Belle&type=track
spotify: URL returned a 401 error
spotify: 10 track(s) did not match a Spotify ID:
spotify: track: Dark Matter album:Black Bear artist:Andrew Belle
spotify: track: Pieces album:Black Bear artist:Andrew Belle
spotify: track: Sister album:Black Bear artist:Andrew Belle
spotify: track: Black Bear album:Black Bear artist:Andrew Belle
spotify: track: Wants What It Wants album:Black Bear artist:Andrew Belle
spotify: track: Details album:Black Bear artist:Andrew Belle
spotify: track: Santa Fe album:Black Bear artist:Andrew Belle
spotify: track: The Enemy album:Black Bear artist:Andrew Belle
spotify: track: Many Lives album:Black Bear artist:Andrew Belle
spotify: track: I Won't Fight It album:Black Bear artist:Andrew Belle
spotify: 
spotify: No Spotify tracks found from beets query
Sending event: cli_exit
jackwilsdon commented 7 years ago

Looks like it is related to the removal of unauthorised calls, as visiting one of those URLs gives this response;

{
  "error": {
    "status": 401,
    "message": "No token provided"
  }
}
sampsyo commented 7 years ago

Thanks for investigating, @jackwilsdon! That does indeed look like the explanation. It looks like this plugin will need to authenticate its API requests.

plittlefield commented 6 years ago

Same here. I have created an app here - https://developer.spotify.com/my-applications/#!/applications so just needs a config setting to make it work!