Spotify extension does not work since latest Spotify app update

I just tried it by highlighting black page and running it.
This is what showed up:

I work pretty heavily with the Spotify API and looking at the script all it is:

open "spotify:search:$POPCLIP_TEXT"

That’s pretty standard for Spotify as far as a URI and I don’t think
they are going to change that.
There are other query options you can add to the URI like specifying searing Title or Artist Etc… But that shouldn’t affect it.

try highlighting the text below and use PopClips open Link

spotify:search:black page

If that doesn’t work it’s a problem with Spotify.
Have you cleared your cache?

Hmmmmmm 1st time I tried using the link method it hung for me as well.
I Quit and tried it again… this time it opened by had only searched “black”

spotify:search&q='black page'
spotify:search:black%20page

try those instead

EDIT 1st one didn’t work

1 Like

another update after researching a bit:
in a browser the URI needs to change a bit to

spotify://search:**<URLEscaped Query>**
spotify://search:black%20page

the above will search to see if Spotify is installed and open the search window
and enter general query search “black page”

spotify://search:remaster%20track:Doxy%20artist:Miles%20Davis

the above query will search for

  • the general term remaster
  • a track named Doxy
  • with an artist Miles Davis

There needs to be a space between each query “type”
then a colon, then the text for that type
and also each space needs to escaped

here’s a list of SOME search query types:
album , artist , track , year , genre

You’ve uncovered an interesing quirk of Spotify, which is that it doesn’t like URL-encoded text. If you run the terminal command:

open "spotify:search:Miles Davis"

it works. But if you run:

open "spotify:search:Miles%20Davis"

it fails.

This is why the PopClip extension used a shell script to open the URL instead of its own inbuilt open url function – because the built in one url-encodes the text always.

Regarding the fault … I still seem to have an older version of Spotify (it seems to control its own update schedule, not sure how to get it to update). But it’s working for me at the moment.

Hi Nick,

I tried “black page” and it indeed works, but … my main use case is to pick up on my friends last.fm tracks and do quick search in Spotify. Previously it worked, but now it does not since few days. It might be indeed related to some URL-encoded text. Check this out, sample last.fm page: https://www.last.fm/user/nick

Select the track & artis:

Click Spotify in PopClip and I see blank black page. Previously it searched for the track I highlighted.

Of course it works just fine if you only select the track or artist alone … (NO, sometimes it works, sometimes not, I have no clue what is going on :wink:

And what is visible in Spotify:

Doing copy & paste reveals this, so new line characters that maybe get URL-encoded ?

Wreck of the Edmund Fitzgerald
Cantus

So maybe last.fm changed sth ? Not sure how it was before…

BTW. For me running "open “spotify:search:Miles%20Davis” from iTerm2 or regular Terminal works :wink:

Whoh, my spotify just updated to latest version as you. Now I’m, seeing the same.
Looks like they “fixed” their URL parser to now require URL encoded input.

For now try this snippet (not with nice icon, I’m afraid), is it working?:

#popclip
name: Spotify
icon: circle filled S
url: spotify:search:***

(The above block is an extension snippet - select it to install the extension with PopClip)

Edit: there seems to be a secondary issue specifically with newline charcters causing spotify to show the b;ank page now. Selecting from the last.fm page can cause that.
I’ll look into it some more…

Thx, I installed the extension snippet, but it is as you wrote in the edited part - sth related to new lines. If I type some text in an editor containing new line I get the same blank/black page.

try
openURL spotify://search:xxxxxxxxxx

I’ll also post another version that may work better. It will check if Spotify app is installed and open it, if not it will open it in webpage.

Terminal works with white space in interesting ways that I’ve discovered when using local files as parameters.

if you put quote around the URL then you don’t have to escape anything.
if you don’t put quotes around it then you do have to escape. And normally I’ve
seen that escapes not in URL fashion but in \ fashion.

I just tried no quotes and it worked

open spotify:search:Miles%20Davis

Trying no quotes with the space fails:

djk-tel$ open spotify:search:Miles Davis
The file /Users/djk-tel/Davis does not exist.

Trying with quotes and with space works:

open spotify:search:"Miles Davis"

Trying quoted with spaces and line feed opens Spotify Blank Page:

open spotify:search:"Wreck of the Edmund Fitzgerald
> Cantus"

Trying non-quoted URL escaped opens Blank Page:

open spotify:search:Wreck%20of%20the%20Edmund%20Fitzgerald%0ACantus

for the URL encoding I used PopClips URL encode/decode.

Cutting out Terminal from the equation, you can open these with PopClip’s open link:

spotify:search:xxxxxxxxxx.          -- ok
spotify:search:xxxxx%20xxxxx.   -- ok
spotify:search:xxxxxxxxxx%0a.   -- spotify does not like

On very latest Spotify (1.1.98.691.gf759311c), the first two work but the last one Spotify does NOT like!

So I just tested

NSString's stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet

and while it does find the lineFeed/newLine as illegal. it escapes it.
what needs to be tackled is the newLine and extraWhite space needs to be removed first

here’s quickTests I did with AppleScript to solve (I can convert to Objective-C for anyone)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

property NSString : a reference to current application's NSString
property NSCharacterSet : a reference to current application's NSCharacterSet
property NSMutableCharacterSet : a reference to current application's NSMutableCharacterSet
property NSRegularExpressionSearch : a reference to 1024

set aQuery1 to "Wreck of the Edmund Fitzgerald 
Cantus"

set aCleaned1 to my cleanSearchString:aQuery1
-- Wreck of the Edmund Fitzgerald Cantus
set aEscaped1 to my escapeSearch:aCleaned1
-- Wreck%20of%20the%20Edmund%20Fitzgerald%20Cantus

set aQuery2 to "   Wreck of the Edmund Fitzgerald 
Cantus 
"
set aCleaned2 to my cleanSearchString:aQuery2
-- Wreck of the Edmund Fitzgerald Cantus
set aEscaped2 to my escapeSearch:aCleaned2
-- Wreck%20of%20the%20Edmund%20Fitzgerald%20Cantus

set aQuery3 to "   Wreck of.  !!!! the Edmund			 Fitzgerald 
Cantus 
     "

set aCleaned3 to my cleanSearchString:aQuery3
-- Wreck of. !!!! the Edmund Fitzgerald Cantus
set aEscaped3 to my escapeSearch:aCleaned3
-- Wreck%20of.%20!!!!%20the%20Edmund%20Fitzgerald%20Cantus


---- MAIN FUNCTIONS

on cleanSearchString:aQuery
	set aString to NSString's stringWithString:aQuery
	-- get all whiteSpace and newLines
	set aPattern to (NSString's stringWithString:"[\\s|\\n]+")
	-- replace with single space
	set aNoWhiteSpaceString to (aString's ¬
		stringByReplacingOccurrencesOfString:aPattern withString:" " options:(NSRegularExpressionSearch) range:(current application's NSMakeRange(0, aString's |length|)))
	-- trim any head or tail whiteSpace or newLines	
	set aCleanString to (aNoWhiteSpaceString's ¬
		stringByTrimmingCharactersInSet:(NSCharacterSet's whitespaceAndNewlineCharacterSet))
	return aCleanString as text
end cleanSearchString:

on escapeSearch:aQuery
	set aString to NSString's stringWithString:aQuery
	set aCharSet to NSMutableCharacterSet's new()
	aCharSet's formUnionWithCharacterSet:(NSCharacterSet's URLQueryAllowedCharacterSet())
	aCharSet's formUnionWithCharacterSet:(NSCharacterSet's URLPathAllowedCharacterSet())
	set aEscapeString to (aString's stringByAddingPercentEncodingWithAllowedCharacters:aCharSet)
	return aEscapeString as text
end escapeSearch:

Three tests 2nd with extra tabs, white space, etc
Test 3 willl probably fail

Actually I just tested it by using Spotify Web and pasting in the search:

Wreck of. !!!! the Edmund Fitzgerald Cantus

The weblink in the browser shows this escaping: which matched what my script came up with

Wreck%20of.%20!!!!%20the%20Edmund%20Fitzgerald%20Cantus

And the search was still able to find the right track:

Exacly :slight_smile: … being more of a JS guy myself, this should do it as a first approximation:

#popclip
name: Spotify
icon: circle filled S
javascript: |
  const term = popclip.input.text.trim().split('\n')[0]
  popclip.openUrl('spotify:search:' + encodeURIComponent(term))

I not that well with JavaScript.
Does the trim() clean all whiteSpace: ie head, tail and multiple in the middle?
the split(‘\n’)[0] is that splitting into an array and then only returning the 1st item?
won’t that then lose part of the string?

with your code work with and not lose Cantus?

Wreck of the Edmund Fitzgerald 
Cantus

how about with multiSpaces and tabs in the middle or extra head lineFeed


Wreck    of the		 Edmund Fitzgerald 
Cantus 

Does the trim() clean all whiteSpace: ie head, tail and multiple in the middle?

Only whitespace at head and tail.

the split(‘\n’)[0] is that splitting into an array and then only returning the 1st item?

yes

won’t that then lose part of the string?

Yes indeed, it will only use the first line of the string. As an improvement, we could split on all (multi)whitespace wih regex /\s+/ and then join back with single spaces:

#popclip
name: Spotify
icon: circle filled S
javascript: |
  const term = popclip.input.text.trim().split(/\s+/).join(' ')
  popclip.openUrl('spotify:search:' + encodeURIComponent(term))

Will than also catch the line feeds?
You may want to use:

[\s|\n]+

\s will catch all spaces, tabs and newline characters


Character classes - JavaScript | MDN

1 Like

Hey guys, let me be your guinea pig. I tested the latest improved snippet shared by Nick and it works for me just fine in last.fm and few other use cases :wink: Thx a lot, I got my life back :slight_smile:

2 Likes

That’s great, thanks for the feedback. I’ve now updated the main extension, which you can redownload at Spotify — PopClip Extensions

Thx Nick, just downloaded and everything works fine :slight_smile:

1 Like