Is it only me, but since last Spotify app update (I have version 1.1.98.691.gf759311c Apple Silicon) the search via Spotify PopClip extension does not work. It results in a completely blank / black page in Spotify app. PopClip 2022.5 (1003895), also redownloaded latest version of the extension from the PopClip page.
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ā
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.
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
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.
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.
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
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
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))
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 Thx a lot, I got my life back