Spotify on the Raspberry Pi

EDIT 30/12/2013:

Hi Guys/Gals, it’s been awhile since I originally posted this quick guide and it looks like people have been running into problems getting this working. I suspect that there has been some changes to the Spotify API that’s meant Hexxeh’s original Python scripts no longer work properly. If you’re still looking to get Spotify running on the Raspberry Pi can I suggest you take a look at the Pi Music Box (it an SD Card image that allows Spotify and Google Play access). If your determined to get the original code working it might be best to file an issue on against Hexxeh’s Spotify WebSocket API here https://github.com/Hexxeh/spotify-websocket-api/issues.

So I heard that it’s possible to run a Spotify client on the Raspberry Pi. So I had a google, and had a good go at getting it running…

Despotify

If you google Spotify for Raspberry Pi, you’ll probably come across Despotify. This was a project to create a command line Linux Spotify client, it was popular and had matured over time. However due to some changes in the Spotify API and the Protocol it no longer works and it looks like no-one has decided to fix it… which is a shame.

Respotify

Bring on Respotify! Respotify is essentially a remake of Despotify, it’s Python based and hooks into the Music Player Daemon. The Respotify package is made by Hexxeh a guy who’s made a few awesome tools over the years most notably he’s maintained some experimental releases of the development version of Chrome OS.

So to get going you’ll want to:

  1. Install Git so you can pull down the source from github.
    1
    
    sudo apt-get update && sudo apt-get install git git-core
  2. Clone the Git Repo:
    1
    
    git clone https://github.com/Hexxeh/spotify-websocket-api.git
  3. Install Music Player Daemon (MPD)
    1
    
    sudo apt-get update && sudo apt-get install mpd ncmpc mpc
  4. Install Python and all it’s Dev Packages:
    1
    
    sudo apt-get update && sudo apt-get install python python-dev
  5. Install Python PIP:
    2
    3
    4
    
    sudo apt-get install python-pip
    cd spotify-websocket-api && sudo ./install-deps.sh
    sudo easy_install
  6. Installing Dependacies:
    • I had problems with lxml so I used apt-get:
      1
      
      sudo apt-get install python-lxml
    • The rest of the dependencies can be installed using the script in the git repo:
      1
      
      cd spotify-websocket-api && sudo ./install-deps.sh
  7. This can’t hurt but installing some of the libraries required by Despotify:
    1
    
    sudo apt-get update && sudo apt-get install libao-dev libtool libssl-dev libmpg123-dev libvorbis-dev libncursesw5-dev
  8. And finally…:
    1
    
    cd spotify-websocket-api/clients/respotify && python respotify.py <SPOTIFY_USERNAME> <SPOTIFY_PASSWORD>

Hopefully this’ll help someone install Respotify as there doesn’t seem to be much documentation out there for getting this running on a Raspberry Pi.

ED: Added missing step to get easy_install working. Please leave a comment if you uncover other issues with getting everything running.


Thanks
Adam.

29 thoughts on “Spotify on the Raspberry Pi

  1. Brad says:

    Very helpful in getting respotify set up on the Pi I also ran into several issues with lxml installing python-lxml got it working for me again.

    Didn’t find it necessary to install the old Despotify dependancies but as you said in your post it couldn’t hurt.

  2. Eben says:

    I was running out of memory compiling lxml too. Thanks for the post, never thought about a binary.

  3. J-Erik says:

    Thanks for the guide!
    Got the following error on point 5:

    pi@raspberrypi ~ $ sudo easy_install
    error: No urls, filenames, or requirements specified (see --help)

    • Adam says:

      if your system can’t find easy_install your probably missing the python-setuptools

      try

      $ sudo apt-get install python-setuptools

      • Oots says:

        No, that’s the error easy_install gives when you give it no arguments.
        When trying to run respotify.py I get the error “ImportError: No module named requests”. I’m assuming that’s related to the easy_install thing.
        However, I hate to leave a negative comment when you’ve put this out there for people, everything but that line works, so thank you.

        • rawdlite says:

          Did you try to run
          sudo ./install-deps.sh

          For me that installed requests

          + VER=
          + apt-get update -yqq
          + apt-get install -yqq python
          + pip install -q requests protobuf cherrypy ws4py python-mpd2 lxml web.py –upgrade

          easy_install complained about missing arguments for me also.
          But everything else worked fine, so i hab have not looked into it.
          My guess is you can skip the easy_install.

          HTH

          • Petros says:

            Whenever I run sudo ./install-deps.sh, I get this:

            + VER=
            + apt-get update -yqq
            + apt-get install -yqq python
            + pip install -q requests protobuf cherrypy ws4py python-mpd2 lxml web.py –upgrade
            Exception:
            Traceback (most recent call last):
            File “/usr/lib/python2.7/dist-packages/pip/basecommand.py”, line 104, in main
            status = self.run(options, args)
            File “/usr/lib/python2.7/dist-packages/pip/commands/install.py”, line 245, in run
            requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
            File “/usr/lib/python2.7/dist-packages/pip/req.py”, line 985, in prepare_files
            self.unpack_url(url, location, self.is_download)
            File “/usr/lib/python2.7/dist-packages/pip/req.py”, line 1109, in unpack_url
            retval = unpack_http_url(link, location, self.download_cache, self.download_dir)
            File “/usr/lib/python2.7/dist-packages/pip/download.py”, line 451, in unpack_http_url
            download_hash = _download_url(resp, link, temp_location)
            File “/usr/lib/python2.7/dist-packages/pip/download.py”, line 368, in _download_url
            chunk = resp.read(4096)
            File “/usr/lib/python2.7/socket.py”, line 380, in read
            data = self._sock.recv(left)
            File “/usr/lib/python2.7/httplib.py”, line 561, in read
            s = self.fp.read(amt)
            File “/usr/lib/python2.7/socket.py”, line 380, in read
            data = self._sock.recv(left)
            File “/usr/lib/python2.7/ssl.py”, line 241, in recv
            return self.read(buflen)
            File “/usr/lib/python2.7/ssl.py”, line 160, in read
            return self._sslobj.read(len)
            SSLError: The read operation timed out

            Do you have any idea what it is or how to fix it?
            Thanks!

  4. luca says:

    I have the same issue… when i launch easy_install i have this :
    sudo easy_install
    error: No urls, filenames, or requirements specified (see –help)

    and then :

    Traceback (most recent call last):
    File “respotify.py”, line 7, in
    from spotify_web.friendly import Spotify, SpotifyTrack, SpotifyUserlist
    File “../../spotify_web/friendly.py”, line 6, in
    from .spotify import SpotifyAPI, SpotifyUtil
    File “../../spotify_web/spotify.py”, line 10, in
    import requests
    ImportError: No module named requests

    please help me to sove the issue .

    thank u

  5. Jon says:

    Luca – I was having the exact same issue, but then realized I had forgotten to run this line:

    cd spotify-websocket-api && sudo ./install-deps.sh

    Then it worked like a charm!

  6. rawdlite says:

    Great, exactly what i was looking for.

    I had to edit line 283 in respotify.py to the ip, i had set in mpd.conf via bind_to_address earlier.

    client.connect(host=”192.168.0.10″, port=”6600″)

    HTH

  7. Adam says:

    Well done guys, I hadn’t had a chance to get back to this post and look at where everyone was stumbling on. I’ll update the original post to include the missing step for easy install.

    cd spotify-websocket-api && sudo ./install-deps.sh

  8. Josh says:

    For lxml, I found that I simply needed to:

    “`apt-get install libxml2-dev libxslt1-dev“`

    After that, the following completed successfully:

    “`pip install –upgrade lxml“`

  9. Emanuele says:

    I had issue with easy_install but i solved typing this:

    sudo easy_install .

    Despite all, I got this error with last command:

    Traceback (most recent call last):
    File “respotify.py”, line 277, in
    spotify = Spotify(args.username, args.password)
    File “/usr/local/lib/python2.7/dist-packages/SpotifyWebsocketAPI-0.2-py2.7.egg/spotify_web/friendly.py”, line 436, in __init__
    self.api.connect(username, password)
    File “/usr/local/lib/python2.7/dist-packages/SpotifyWebsocketAPI-0.2-py2.7.egg/spotify_web/spotify.py”, line 750, in connect
    Logging.notice(“Connecting to “+self.settings["aps"]["ws"][0])
    KeyError: ‘ws’

    any idea?

  10. Jocke says:

    Hey I’m having a problem login in. I get:

    [ERROR] Rate request error
    Traceback (most recent call last):
    File “respotify.py”, line 283, in
    client.connect(host=”localhost”, port=”6600″)
    File “/usr/local/lib/python2.7/dist-package/mpd.py”, line 491, in connect
    self._sock = self._connect_tcp(host, port)
    File “/usr/local/lib/python2.7/dist-package/mpd.py”, line 464, in _connect_tcp
    raise err
    socket.error: [Rrrno 111] Connection refused
    Exception in thread Thread-1 (most likely raised during interpreter shutdown):
    Traceback (most recent call last):

    I’m pretty new to these kind of things so any help with interpreting this or helping solving this would be really appreciated. I’m using a wireless dongle and have been configured /etc/network to make it work.

  11. Neil says:

    Hi Adam,
    Thanks for the great blog, it’s exactly what I’m looking for, but I’m having problems with the easy install… All runs great, no errors or anything and when I run easy_install, I get this error:

    error: No urls, filenames, or requirements specified (see –help)

    What did I miss out?

    Thank for your help
    Neil

  12. [...] Despotify & Respotify: un intento de crear un cliente para Spotify que no he probado, aunque parece una opción bastante interesante. [...]

  13. Luke says:

    Couldn’t managed to make sudo easy_install to work, but got no error in ./install-deps.sh
    Tried many times to login with respotify, but always “login failed”. I’m sure password and user are correct.

  14. Ephoras says:

    Hey, i followed your toturial and it kinda worked…
    the easy_install gives me an error, despite what i install :(

    when i try to run respotify (the last line)
    i just get an “Login failed” and thats it.
    I have not found any logs, so someone got an idea what’s the problem?

  15. Coillix says:

    I get this error while trying to login:

    Exception in thread WebSocketClient:
    Traceback (most recent call last):
    File “/usr/lib/python2.7/threading.py”, line 552, in __bootstrap_inner
    self.run()
    File “/usr/lib/python2.7/threading.py”, line 505, in run
    self.__target(*self.__args, **self.__kwargs)
    File “/usr/local/lib/python2.7/dist-packages/ws4py/websocket.py”, line 427, in run
    if not self.once():
    File “/usr/local/lib/python2.7/dist-packages/ws4py/websocket.py”, line 305, in once
    if not self.process(b):
    File “/usr/local/lib/python2.7/dist-packages/ws4py/websocket.py”, line 357, in process
    self.reading_buffer_size = s.parser.send(bytes) or DEFAULT_READING_SIZE
    File “usr/local/lib/python2.7/dist-packages/ws4py/streaming.py”, line 218, in receiver
    is_valid, end_on_code_point, _, _= utf8validator.validate(some_bytes)
    File “/usr/local/lib/python2.7/dist-packages/ws4py/utf8validator.py”, line 110, in validate
    state = DFA[256 + (state << 4) + DFA[b]]
    TypeError: list indices must be integers, not str
    Login failed

    Any idéa what to do about this error?

  16. Bryan says:

    I am still getting the easy_install error…

  17. James says:

    Having installed all the deps, when I try to run respotify I just get a syntax error. Do you know how I can fix this?
    (output)
    [james@jamespi respotify]$ python respotify.py
    File “respotify.py”, line 49
    “”"
    ^
    SyntaxError: invalid syntax

  18. Blackeyez says:

    For those who have trouble logging in due to authenticaion failure, you need to login without your facebook information. First, you need to find your spotify username:

    “This username, unattractive as it may seem, is still required for publicizing your Spotify profile. One way to find out your username is by clicking your name at the top-right of the Spotify window and then clicking Profile from the menu to access your public profile. Whatever appears in brackets next to your real name is your Spotify username.”

    source: http://www.dummies.com/how-to/content/how-to-share-your-spotify-username.html

    Then you need to set a device password. You do that at this page: https://www.spotify.com/us/account/set-device-password/

    Use your numerical spotify username along with your newly set device password and you’ll be able to login with despotify.

    Enjoy!

  19. Linefader says:

    Hi, I (think) I installed Respotify successfully (on my Linux Laptop running Fedora 20, not on a raspberry) but I have some problems using it:
    I can log in to my spotify account with respotify
    but when I execute the “play 1″ command, the program crashes with the following error:
    Traceback (most recent call last):
    File “respotify.py”, line 285, in
    command_loop()
    File “respotify.py”, line 251, in command_loop
    command_map[command_name][0](command[1:])
    File “respotify.py”, line 170, in command_play
    for track in current_playlist.getTracks():
    AttributeError: ‘NoneType’ object has no attribute ‘getTracks’
    and when I execute the “list” command, the program crashes with the following error:
    Playlists
    [1] Starred
    Traceback (most recent call last):
    File “respotify.py”, line 285, in
    command_loop()
    File “respotify.py”, line 251, in command_loop
    command_map[command_name][0](command[1:])
    File “respotify.py”, line 91, in command_list
    print ” ["+str(index)+"] “+playlist.getName()
    File “../../spotify_web/friendly.py”, line 254, in getName
    return “Starred” if self.getID() == “starred” else self.obj.attributes.name
    AttributeError: ‘bool’ object has no attribute ‘attributes’

    Can anybody explain these error messages?

    I also did not fully understand what the program can do:
    I can see that it is a command line client for Spotify
    But can I use this to play Spotify contents from my MPD server? (like local files)

    How does this work?

    Thanks and regards!

  20. Nico says:

    Hi,
    i got an error after 5.:

    pi@raspberrypi /tmp/spotify-websocket-api $ sudo ./install-deps.sh
    + VER=
    + apt-get update -yqq
    + apt-get install -yqq python
    + pip install -q requests protobuf cherrypy ws4py python-mpd2 lxml web.py –upgrade
    Command /usr/bin/python -c “import setuptools;__file__=’/tmp/spotify-websocket-api/build/lxml/setup.py’;exec(compile(open(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” install –single-version-externally-managed –record /tmp/pip-I0tWEJ-record/install-record.txt failed with error code 1 in /tmp/spotify-websocket-api/build/lxml
    Storing complete log in /root/.pip/pip.log
    pi@raspberrypi /tmp/spotify-websocket-api $ sudo easy_install
    error: No urls, filenames, or requirements specified (see –help)

    what can i do?

  21. Installing it on Banana Pi (Bananian), make sure you have gcc installed, because it isn’t by default.

    Just do sudo apt-get install gcc
    :D

  22. dan says:

    Getting the following error…

    pi@raspberrypi ~/spotify-websocket-api $ sudo ./install-deps.sh
    + VER=
    + apt-get update -yqq
    + apt-get install -yqq python
    + pip install -q requests protobuf cherrypy ws4py python-mpd2 lxml web.py –upgrade
    Command /usr/bin/python -c “import setuptools;__file__=’/home/pi/spotify-websocket-api/build/lxml/setup.py’;
    exec(compile(open(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” install –single-version-exter
    nally-managed –record /tmp/pip-tqIiym-record/install-record.txt failed with error code 1 in /home/pi/spotif
    y-websocket-api/build/lxml
    Storing complete log in /root/.pip/pip.log

  23. David says:

    Getting error on step one:

    Failed to fetch http://repository.spotify.com/dists/stable/InRelease Unable to find expected entry ‘non-free/binary-armhf/Packages’ in Release file (Wrong sources.list entry or malformed file)

    Any ideas?! Have Spotify removed this?

  24. Klode says:

    I have got this error on UbuntuMate 15.10, on raspberry Pi 2, during command install-deps.sh:

    Command “/usr/bin/python -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-c_tXqW/lxml/setup.py’;exec(compile(getattr(tokenize, ‘open’, open)(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” install –record /tmp/pip-JeOvEN-record/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-c_tXqW/lxml/

    I’ve tried to remove lxml from apt-get and from pip, same error. what’s wrong?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>