Spotify Bash Script for Improved Stability


spotify linux version given preview 0 300x199 Spotify Bash Script for Improved StabilitySo if you have used Spotify on Linux you will notice that there are often times where it will crash on start or act very broken after a launch and that seems to be primarily due to unwanted data being left in cache or config temps which seem to cause hangups.

Here is a special little bash script that makes Spotify work more smoothly and this especially makes the latest Beta with Spotify Apps work very nicely but can work in earlier versions as well:

#!/bin/bash
# Purge Spotify's ever horrible cache and temp config then run spotify
rm -Rf $HOME/.config/spotify && rm -Rf $HOME/.cache/spotify && spotify

For those who want to run this script as an application shortcut so it does tidying and then launches Spotify then simply do this from terminal:

1. nano spotify.sh

2. paste above code

3. chmod +x spotify.sh

4. Now sudo nano /usr/share/applications/spotify.desktop and paste this in but make sure to edit the “Exec” path to match the location of the Spotify.sh location on your system:

[Desktop Entry]
Name=Spotify
GenericName=Music Player
Comment=Listen to music using Spotify
Icon=spotify-linux-512×512
Exec=/home/bkerensa/bin/spotify.sh
TryExec=spotify
Terminal=false
Type=Application
Categories=Qt;Audio;Music;Player;AudioVideo
MimeType=x-scheme-handler/spotify

Now whenever you click the Spotify icon in the Unity launcher or whatever DE on Ubuntu you happen to be using it should execute the spotify.sh script which will tidy up and then run Spotify.

Hope this is useful for some!

 

 

 

  • MatthewAguirre

    But then you have to keep entering your credentials. I don’t have a problem if I leave the .config/spotify directory, only the .cache/spotify.

    Also, if you put a “spotify” script in your $HOME/bin directory which then executes /usr/bin/spotify, you don’t have to change any launchers since the $HOME/bin directory will be first in the PATH.

  • solancer_com

    I appreciate your effort in improving Spotify, keep up the good work.

  • bryandfleming

    I used the cleaning method that you placed but one problem that still keeps bothering me is the ‘adding’ a new song to an existing playlist.

    *sigh*

    I found another person with the same problem and will be placing additional information about it on this topic: https://getsatisfaction.com/spotify/topics/cant_add_song_to_playlist_on_spotify_0_8_0_ubuntu_11_10

    Thanks for the help!

  • whereisdarran

    I switched to RDIO! Runs in the browser and never crashes!

  • Roger Dean

    Many many thanks for this. I find that it works if I delete .cache/spotify but keep .config/spotify and then it remembers my login too…

  • Roger Dean

    Many many thanks for this. I find that it works if I delete .cache/spotify but keep .config/spotify and then it remembers my login too…