Home > linux, personal > Using Spotify Links in Linux

Using Spotify Links in Linux

I’ve yet to officially start my tutorials on Linux, but I’ve been playing around with Spotify recently and I’ve been annoyed by the problem of getting Spotify playlists to load from my web browser directly into Spotify. For those who don’t know about Spotify, I suggest you read my previous post, and if you still want invites, I am getting them on a daily basis, so please apply. Spotify playlists can be shared easily in the form of a link, and there have been several websites set up to publish these links. The problem of using these links in Linux consists of two issues:

  1. Getting the browser to recognize a Spotify link (in the form: spotify:user:jacken:playlist:5CUB76CWjf2vFxZymgO3cW).
  2. Getting the browser to execute the link as an argument on a program running through wine, the Linux windows compatibility layer.

The first problem can be solved quite easily in Firefox, but it does involve messing around with the configuration a bit. Open a new tab, type “about:config” (without the quotes) and press enter. If you are running a recent version of Firefox, you should click the button accepting the “this might void your warranty” message. Right click anywhere on the page (which should have filled with a table of options) and create a new boolean. In the preference name box, type “network.protocol-handler.external.spotify” (again without quotes), and then choose the value true for the option. This has now enabled the spotify protocol in Firefox, meaning that whenever the browser is sent a request to open something with the prefix spotify: it will ask the user what to do with the request. Of course, the 2nd problem is getting Firefox to communicate to a program that does not run natively within Linux. To bypass this, we can create a simple script that Firefox can execute. The script will then do all the complicated bits that Firefox can’t do. Open up a terminal, and execute this command:

cd ~/.wine/drive_c/Program\ Files/Spotify/

If you have installed wine with default settings, this is where all the Spotify files are located. Otherwise, you will have to modify the command to cd you into the correct Program Files directory. Once in the directory, you should find two files, spotify.exe and Uninstall.exe (use the ls command to check). Create a file called “spotify.sh” in this directory, and edit it with your favourite text editor. Copy and paste the following into the file:

1
2
#!/bin/bash
wine "$HOME/.wine/drive_c/Program Files/Spotify/spotify.exe" /uri "$1"

Save the file and exit the text editor. What does this code mean? Well, the first line (known as a sha-bang!) tells the system what type of file our script is, and which interpreter to use when executing it. In this case, we want to run the script through the bash shell, so we give it the location of bash on the system (which is 99.9999% always /bin/bash, but you can find out by typing which bash into a terminal and alter accordingly). The next line is the command we want the script to execute, which calls on wine to run spotify.exe file with the argument /uri and the link url given by Firefox when executing ($1). $HOME is simply a shell variable that stores your home directory location (usually in the form: /home/username). Now all you have to do is make the file executable:

chmod +x spotify.sh

Now try it out on a spotify link! If spotify is already open, the playlist should appear on the left, otherwise spotify will open up and display the playlist for you. When you click on the link, Firefox should ask you what you want to do with it, and all you have to do is select the spotify.sh file we just wrote. If it doesn’t ask when you click on a link, you will need to go into Edit -> Preferences -> Applications and find “spotify” in the list, then select the file using the “use other” action.

Share and Enjoy:
  • Facebook
  • Digg
  • Google Bookmarks
  • del.icio.us
  • NewsVine
  • StumbleUpon
  • Technorati
  • Tumblr
  • Twitter
Categories: linux, personal Tags: , , , ,
  1. Etu
    January 11th, 2009 at 11:07 | #1

    I didn't get it working with your method.

    But I created a solution wich works perfecly for me.

    I took yor short bash script, placed it in /usr/local/bin/

    Made it executeble.

    Added a string to about:config with the name: network.protocol-handler.app.spotify
    and the value: /usr/local/bin/spotify.sh

    Works perfecltly :)

    • Tom
      August 29th, 2009 at 10:15 | #2

      I had a similar experience. (I'm using firefox 3.0.13 on Ubuntu)

  2. Sugar Kane
    February 16th, 2009 at 21:47 | #3

    Here's a Debian/Ubuntu package that configures everything automatically: http://www.filesco.com/download.php?id=6FB7EC1F1

  3. Truxx
    April 26th, 2009 at 22:08 | #4

    I can’t get it to work fully with any of your methods. Etu’s method works for me when I all ready have spotify started, but spotify wants to update itself (just after logging in) for some reason when the script tries to open the app. “The spotify updater is trying to install the update, but didn’t succed.
    The error message is: Access denied (5)

    Any ideas what I can do to work around this?

  4. hjw
    June 4th, 2009 at 13:06 | #5

    Thanks for this, works for me with the addition from grus

  5. June 14th, 2009 at 00:28 | #6

    Worked with the add from gruff here to
    Iceweasel 3.0.6 on Debian Lenny

    Thanks

  6. pip
    September 9th, 2009 at 09:41 | #7

    Worked for me in Ubuntu 8.10 and FF 3.x with also adding prtocol from grus

  7. Andy
    September 16th, 2009 at 15:46 | #8

    Thanks. I couldn't get the script to work from the instructions off Spotifys website but this works great thanks.

  8. September 24th, 2009 at 17:25 | #9

    None of the proposed solutions works for me. I get the following error:

    Firefox doesn't know how to open this address, because the protocol (spotify) isn't associated with any program.

  9. Emma
    September 30th, 2009 at 23:10 | #10

    Heyhey,

    This blogpost didn't work for me, and after a couple of hours, I finally figured out why not!

    The problem is that Firefox requires two config mods to create the pop-up box: a boolean, and a string.

    So, right click -> new -> string

    Name: network.protocol-handler.app.spotify
    Value: path/to/spotify.sh (this will be different for each person)

    If this does not work, you should now at least get a dialogue box the next time you try to open a spotify link. Use the 'open with' to browse your file system until you locate spotify.sh, and open it.

    When the link works, a little page will appear next to the spotify.sh program suggestion.

    Hope this helps!

    Em

  10. October 1st, 2009 at 05:05 | #11

    Ditto. I've added all three of the about:config settings suggested in this post and comments

    network.protocol-handler.app.spotify ;/usr/local/bin/spotify
    network.protocol-handler.expose.spotify ;false
    network.protocol-handler.app.spotify ;/usr/local/bin/spotify

    I get the exact same error.

  11. October 1st, 2009 at 05:08 | #12

    Ditto. I've added all three of the about:config settings suggested in this post and comments

    network.protocol-handler.app.spotify -> /usr/local/bin/spotify
    network.protocol-handler.expose.spotify -> false
    network.protocol-handler.external.spotify -> true

    I get the exact same error. Firefox 3.5.3.

  12. PaYul
    October 6th, 2009 at 10:41 | #13

    it works for me ! thanks !
    firefox created the string line by itself, using "Edit/Preference/Applications/spotify", as said in the article
    is my english readable ? i'm french…

  13. October 11th, 2009 at 17:06 | #14

    Instructions worked (after I used the additional boolean mentioned in comments) but Spotify then crashes when I open a link. Oh well. =(

  14. Dave
    October 11th, 2009 at 20:53 | #15

    Or just paste the url into Spotify's search box.

  15. Michael
    October 18th, 2009 at 10:32 | #16

    Thanks Dave, I couldn't get it to work at all, but now I realise you can just do that, I don't need it to work.

  16. Marcos
    October 20th, 2009 at 12:06 | #17

    Thank you so much!!!
    It works perfectly!!
    After going crazy from site to site searching the right method (none of them worked) found yours :)

  17. HeK
    November 1st, 2009 at 10:44 | #18

    Adding network.protocol-handler.expose.spotify false works perfectly!! Finally i can use spotify links!

    Thanks!!!!

  18. sofazen
    November 8th, 2009 at 22:44 | #19

    Finally! this was the key for me:
    network.protocol-handler.expose.spotify set to false

  19. November 24th, 2009 at 13:46 | #20

    I've written a similar guide specifically for Ubuntu, but should work with any Linux distro using Firefox or other Gecko based browsers. See http://jordanhall.co.uk/ubuntu-linux/how-to-get-g...

  20. jimmyjabber
    February 5th, 2010 at 08:22 | #21

    I finally got this working after lots of hair pulling. I followed all steps above but I still got the unknown protocol error. However, the spotify links site I used was using javascript to link to the spotify:// links. When I tried a site that links normally to spotify:// links, it worked, then the javascript site started working. Hope this helps someone.

  21. March 10th, 2010 at 07:43 | #22

    Unfortunately I found no solution how to handle the protocol in Chromium. If anyone has an Idea, please share it ;-)

  22. max
    April 30th, 2010 at 15:24 | #23

    This made the play button on the spotify web page *open* spotify (so best result yet, thanks) but it didn't load the appropriate track, it just sat on the default welcome page.

  1. January 7th, 2009 at 17:34 | #1
  2. January 7th, 2009 at 17:38 | #2
  3. April 3rd, 2010 at 10:01 | #3
  4. April 27th, 2010 at 21:40 | #4
Comments are closed.
blog comments powered by Disqus