After combining a few ideas, I got my firefox to open spotify links à la
directly in my running Linux Spotify client. Here's how:
1. Install Greasemonkey (Firefox) or Tampermonkey (Chrome) and then this script.
I modified it to not even open the web-player but directly redirect to spotify by adding the line
// @run-at document-start
in the header section of the script. I sent a request to the author to incorporate that change.
2. Create a new spotify URI handler at ~/.local/share/applications/spotify-open.desktop with the content
Name=Open in Spotify
Exec=qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri %U
Make sure you have qdbus installed. On Arch Linux, this is found in package qt5-tools.
Now if you click on any open.spotify.com link, it will automatically play in your client.
An alternative to qdbus is dbus-send, which is probably more commonly installed:
dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:'spotify:track:1WNPappMd13lY5o9POZ4gU'
replace spotify:track:... with %U for use in the desktop entry file.
Hey there you,
Yeah, you! 😁
Welcome - we're glad you joined the Spotify Community!
While you here, let's have a fun game…