beetbox / beets

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

spotify: Pre-process some special characters in search strings #4514

Open JOJ0 opened 1 year ago

JOJ0 commented 1 year ago

While working on something else I realized that a string containing single quotes is not handled well (educated guess! no further testing if it really is the cause, sorry!) I thought I'll let you know @arsaboo

Problem

(beets)      ~/git/beets   fix_discogs_multi_artist ●  beet ls carolina     
DJ Marky & XRS, Stamina MC - LK 'Carolina Carol Bela' - LK (Full Length Version)
DJ Marky & XRS, Stamina MC - LK 'Carolina Carol Bela' - LK (Full Length Instrumental Version)
(beets)    ~/git/beets   fix_discogs_multi_artist ●  beet -vv spotify carolina
user configuration: /home/jojo/.config/beets/config.yaml
data directory: /home/jojo/.config/beets
plugin paths: 
Sending event: pluginload
library database: /home/jojo/.config/beets/library.db
library directory: /home/jojo/Music
Sending event: library_opened
spotify: Processing 2 tracks...
spotify: Searching Spotify for 'LK (Full Length Version) artist:DJ Marky & XRS, Stamina MC album:LK 'Carolina Carol Bela''
spotify: Found 0 result(s) from Spotify for 'LK (Full Length Version) artist:DJ Marky & XRS, Stamina MC album:LK 'Carolina Carol Bela''
spotify: Searching Spotify for 'LK (Full Length Instrumental Version) artist:DJ Marky & XRS, Stamina MC album:LK 'Carolina Carol Bela''
error: Spotify API error:
{
  "error" : {
    "status" : 400,
    "message" : "Bad request."
  }
}
URL:
https://api.spotify.com/v1/search
params:
{'q': "LK (Full Length Instrumental Version) artist:DJ Marky & XRS, Stamina MC album:LK 'Carolina Carol Bela'", 'type': 'track'}

Setup

My configuration (output of beet config -e) is:

import:
  write: yes
  copy: no
  detail: yes
  duplicate_action: ask

musicbrainz:
  url_rels:
    discogs: yes
    spotify: yes
    bandcamp: yes

discogs:
    source_weight: 0.0
    append_style_genre: yes

spotify:
    source_weight: 1.0

plugins:
  - convert
  - info
  - edit
  - discogs
  - spotify
arsaboo commented 1 year ago

Thanks @JOJ0 for filing this. I may have seen this error. If I recall correctly, strings with [ or ] also cause this issue.

I did not touch the search part, but I am guessing we will have to pre-process the strings to remove the offending characters.

JOJ0 commented 1 year ago

Hi, I had a quick look what the Discogs plugin actually does for preprocessing the query string. This is what I found: https://github.com/beetbox/beets/blob/472c3ab7975e5933f8111a2182f177a0fe5642d5/beetsplug/discogs.py#L243-L247

Not sure if it helps. You could also have a look at the Deezer plugin, I suppose it is a little more similar to the Spotify plugin than the Discogs plugin is.

HTH