Difference between revisions of "Spotify"

From ArchWiki
Jump to: navigation, search
m (D-Bus: Added suggestion to install Xbindkeys, needed for xbindkeysrc to work.)
(29 intermediate revisions by 13 users not shown)
Line 1: Line 1:
[[Category:Audio/Video (English)]]
+
[[Category:Audio/Video]]
 +
[[Category:Wine]]
 
[http://www.spotify.com/ Spotify] is a digital music service that gives you access to millions of songs.
 
[http://www.spotify.com/ Spotify] is a digital music service that gives you access to millions of songs.
  
This Internet music service allows you to select any song in it's database and stream for free. This service was recently only open in areas of Europe, and has recently (07/17/2011) been opened up to the United States area. The only client currently available on linux is supported on Debian and Fedora distributions, while they do recommend use under wine. The only catch to using this application as a free user is the inability to go mobile without a premium subscription. Their are also the occasional voice ads in between songs for users who do not wish to subscribe.
+
This Internet music service allows you to select any song in its database and stream for free. The service was recently introduced to the United States after previously being exclusive to Europe. The Linux client is only officially packaged for Debian and Fedora distributions, but is also available in the AUR: {{AUR|spotify}}. Officially, they recommend that Linux users run the windows client under Wine. The only catch to using this application as a free user is the inability to go mobile without a premium subscription. There are also the occasional voice ads in between songs for users who do not wish to subscribe.
  
== Installation ==
+
Spotify also offers free users the ability to create playlist which can be shuffled, and set to repeat tracks. Content provided by Spotify comes in explicit versions as well as censored.
  
If you are interested in using Spotify under Archlinux, you must ensure that you have [[Wine]] installed on your system. In addition to installing wine you will need to take a moment to configure it for the user who will be running the application.
 
  
Depending on your choice of architecture it may be necessary for you to enable the multilib repositories, to do so you will need to edit your pacman configuration file (as root).
+
== Installing The Client ==
 +
Choose which client you would prefer. The Linux client is receiving good reviews. However, if you are comfortable with wine and it's configuration, you might want to choose the windows client. Please note that you do NOT need to install both.  
  
# nano /etc/pacman.conf
+
=== Installation of Linux Client ===
 +
Follow the instructions for installing packages from the AUR: https://wiki.archlinux.org/index.php/AUR#Installing_packages and install the AUR package here: {{AUR|spotify}}. The pkgbuild will automatically download the software. It would be a good use of time to go to the spotify website and create your user account while it's building.
 +
If you wish to play local files you will need to install {{AUR|ffmpeg-spotify}} as well.
 +
You can also install {{AUR|spotify-gnome-git}} to control spotify with gnome's media keys.
  
Once you have the file opened you will be editing line 82 and 83, removing the pound sign from the start of both lines. After you enable the multilib repository you will need to install wine.
+
=== Installation of Windows Client using Wine===
 +
 
 +
==== Install Wine ====
 +
First, you must ensure that you have [[Wine]] installed on your system. In addition to installing Wine you will need to take a moment to configure it for the user who will be running the application.
 +
 
 +
Depending on your choice of architecture it may be necessary for you to enable the [[Official_Repositories#.5Bmultilib.5D|multilib]] repositories. This is necessary to install Wine on x86_64 systems, if not enabled [[pacman]] will inform you that the package was not found.
  
 
  # pacman -Syy
 
  # pacman -Syy
  # pacman -S wine
+
  # pacman -S wine wine_gecko
  
=== Configure wine ===
+
==== Configure Wine ====
  
 
When wine is installed you will need to change some configuration settings using the winecfg application on your every day user account (not root).
 
When wine is installed you will need to change some configuration settings using the winecfg application on your every day user account (not root).
  
  # winecfg
+
  $ winecfg
  
 
After launching the winecfg application you will be presented with multiple tabs that can assist you in tweaking the performance of the emulator. However for this purpose your main focus will be the Audio tab.
 
After launching the winecfg application you will be presented with multiple tabs that can assist you in tweaking the performance of the emulator. However for this purpose your main focus will be the Audio tab.
Line 29: Line 38:
 
Failure to perform the above task will result in the inability to hear playback.
 
Failure to perform the above task will result in the inability to hear playback.
  
=== Get Spotify ===
+
==== Run Installer ====
  
 
Obtaining Spotify can be done by registering for an account on their Website, the application does not offer in-app registration.
 
Obtaining Spotify can be done by registering for an account on their Website, the application does not offer in-app registration.
Line 35: Line 44:
 
However you can obtain the application prior to registering by using the following URL. [http://download.spotify.com/Spotify%20Installer.exe]
 
However you can obtain the application prior to registering by using the following URL. [http://download.spotify.com/Spotify%20Installer.exe]
  
After you have registered and downloaded your copy of the installer you will need to run the application through wine, depending on your setup you may be able to run the application by right clicking the file. If not terminal will work just fine, as long as you run the below command in the directory of your download.
+
After you have registered and downloaded your copy of the installer you will need to run the application through Wine, depending on your setup you may be able to run the application by right clicking the file. If not terminal will work just fine, as long as you run the below command in the directory of your download.
  
  # wine Spotify\ Installer.exe
+
  $ wine Spotify\ Installer.exe
  
 
Once the application is successfully installed you may run Spotify by using one of the following commands in terminal, or in the ALT+F2 launcher:
 
Once the application is successfully installed you may run Spotify by using one of the following commands in terminal, or in the ALT+F2 launcher:
Line 43: Line 52:
 
If you use a x86_64 copy of ArchLinux, you'll have to run it like this:
 
If you use a x86_64 copy of ArchLinux, you'll have to run it like this:
  
  # wine "/home/username/.wine/drive_c/Program Files (x86)/Spotify/spotify.exe"
+
  $ wine "/home/username/.wine/drive_c/Program Files (x86)/Spotify/spotify.exe"
  
 
If you use a x86 copy of ArchLinux, you can use this command just fine:
 
If you use a x86 copy of ArchLinux, you can use this command just fine:
  
  # wine ~/.wine/drive_c/Program\ Files/Spotify/spotify.exe
+
  $ wine ~/.wine/drive_c/Program\ Files/Spotify/spotify.exe
  
 
If you have any additional problems, I recommend setting the winecfg to Windows XP or Windows 7 emulation.
 
If you have any additional problems, I recommend setting the winecfg to Windows XP or Windows 7 emulation.
  
=== Get Spotify from the AUR ===
+
==Global Media Hotkeys==
There is also a copy of Spotify available in the Archlinux AUR, and you can download this application by using [[Yaourt]]
+
 
 +
Spotify has support for media keys like {{ic|XF86AudioPlay}}, but out of the box they only work inside Spotify. We can use for example [[xbindkeys]] to catch the global media keypresses, and then forward them to Spotify using one of the methods below.
 +
 
 +
===Using a bash-script and xdotool===
 +
With the help of {{ic|xdotool}} it is possible to send your hotkeys to the application. The following script is an example of how to control Spotify from the outside:
 +
#!/bin/sh
 +
 +
case $1 in
 +
    "play")
 +
        key="XF86AudioPlay"
 +
        ;;
 +
    "next")
 +
        key="XF86AudioNext"
 +
        ;;
 +
    "prev")
 +
        key="XF86AudioPrev"
 +
        ;;
 +
    *)
 +
        echo "Usage: $0 play|next|prev"
 +
        exit 1
 +
        ;;
 +
esac
 +
xdotool key --window $(xdotool search --name "Spotify (Premium )?- Linux Preview"|head -n1) $key
 +
exit 0
 +
 
 +
Let's call it {{ic|musickeys.sh}}. Make the script executable:
 +
$ chmod +x musickeys.sh
 +
By executing {{ic|./musickeys.sh play}} you can now toggle playing a song. Now you can bind this script to any tool that catches keypresses, such as [[xbindkeys]]. For [[Openbox]] you can use the following example (see [[Openbox#Configuration]] for help):
 +
<keybind key="XF86AudioPlay">
 +
  <action name="Execute">
 +
      <execute>~/bin/musickeys.sh play</execute>
 +
  </action>
 +
</keybind>
 +
<keybind key="XF86AudioNext">
 +
  <action name="Execute">
 +
      <execute>~/bin/musickeys.sh next</execute>
 +
  </action>
 +
</keybind>
 +
<keybind key="XF86AudioPrev">
 +
  <action name="Execute">
 +
      <execute>~/bin/musickeys.sh prev</execute>
 +
  </action>
 +
</keybind>
 +
 
 +
===D-Bus===
 +
 
 +
An alternative to the above is [[D-Bus]], which should be available by default as it is a dependency of [[systemd]]. With D-Bus we have a consistent and reliable way to communicate with other processes, such as Spotify.
 +
To play or pause the current song in Spotify:
 +
$ dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
  
  # yaourt -S spotify
+
In order to bind this and the other commands to the media keys you need to install [[Xbindkeys]] and edit your .xbindkeysrc and add the following lines:
 +
  # Play/Pause
 +
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
 +
XF86AudioPlay
 +
 +
# Next
 +
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
 +
XF86AudioNext
 +
 +
# Previous
 +
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous"
 +
XF86AudioPrev
 +
 +
# Stop
 +
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"
 +
XF86AudioStop
  
 
==See also==
 
==See also==
 +
*[[SpotCommander]]: A web based remote control for Spotify
 
*http://www.spotify.com/int/help/faq/wine/
 
*http://www.spotify.com/int/help/faq/wine/
 
*http://www.spotify.com/int/download/previews/
 
*http://www.spotify.com/int/download/previews/

Revision as of 17:56, 13 October 2013

Spotify is a digital music service that gives you access to millions of songs.

This Internet music service allows you to select any song in its database and stream for free. The service was recently introduced to the United States after previously being exclusive to Europe. The Linux client is only officially packaged for Debian and Fedora distributions, but is also available in the AUR: spotifyAUR. Officially, they recommend that Linux users run the windows client under Wine. The only catch to using this application as a free user is the inability to go mobile without a premium subscription. There are also the occasional voice ads in between songs for users who do not wish to subscribe.

Spotify also offers free users the ability to create playlist which can be shuffled, and set to repeat tracks. Content provided by Spotify comes in explicit versions as well as censored.


Installing The Client

Choose which client you would prefer. The Linux client is receiving good reviews. However, if you are comfortable with wine and it's configuration, you might want to choose the windows client. Please note that you do NOT need to install both.

Installation of Linux Client

Follow the instructions for installing packages from the AUR: https://wiki.archlinux.org/index.php/AUR#Installing_packages and install the AUR package here: spotifyAUR. The pkgbuild will automatically download the software. It would be a good use of time to go to the spotify website and create your user account while it's building. If you wish to play local files you will need to install ffmpeg-spotifyAUR as well. You can also install spotify-gnome-gitAUR to control spotify with gnome's media keys.

Installation of Windows Client using Wine

Install Wine

First, you must ensure that you have Wine installed on your system. In addition to installing Wine you will need to take a moment to configure it for the user who will be running the application.

Depending on your choice of architecture it may be necessary for you to enable the multilib repositories. This is necessary to install Wine on x86_64 systems, if not enabled pacman will inform you that the package was not found.

# pacman -Syy
# pacman -S wine wine_gecko

Configure Wine

When wine is installed you will need to change some configuration settings using the winecfg application on your every day user account (not root).

$ winecfg

After launching the winecfg application you will be presented with multiple tabs that can assist you in tweaking the performance of the emulator. However for this purpose your main focus will be the Audio tab.

While under the audio tab, you will enable either the ALSA or OSS driver by clicking the check box next to them, depending on what software you prefer to use. Also note that the hardware acceleration will need to be changed from Full to Emulation. When done you may exit the winecfg application.

Failure to perform the above task will result in the inability to hear playback.

Run Installer

Obtaining Spotify can be done by registering for an account on their Website, the application does not offer in-app registration.

However you can obtain the application prior to registering by using the following URL. [1]

After you have registered and downloaded your copy of the installer you will need to run the application through Wine, depending on your setup you may be able to run the application by right clicking the file. If not terminal will work just fine, as long as you run the below command in the directory of your download.

$ wine Spotify\ Installer.exe

Once the application is successfully installed you may run Spotify by using one of the following commands in terminal, or in the ALT+F2 launcher:

If you use a x86_64 copy of ArchLinux, you'll have to run it like this:

$ wine "/home/username/.wine/drive_c/Program Files (x86)/Spotify/spotify.exe"

If you use a x86 copy of ArchLinux, you can use this command just fine:

$ wine ~/.wine/drive_c/Program\ Files/Spotify/spotify.exe

If you have any additional problems, I recommend setting the winecfg to Windows XP or Windows 7 emulation.

Global Media Hotkeys

Spotify has support for media keys like XF86AudioPlay, but out of the box they only work inside Spotify. We can use for example xbindkeys to catch the global media keypresses, and then forward them to Spotify using one of the methods below.

Using a bash-script and xdotool

With the help of xdotool it is possible to send your hotkeys to the application. The following script is an example of how to control Spotify from the outside:

#!/bin/sh

case $1 in
   "play")
       key="XF86AudioPlay"
       ;;
   "next")
       key="XF86AudioNext"
       ;;
   "prev")
       key="XF86AudioPrev"
       ;;
   *)
       echo "Usage: $0 play|next|prev"
       exit 1
        ;;
esac
xdotool key --window $(xdotool search --name "Spotify (Premium )?- Linux Preview"|head -n1) $key
exit 0

Let's call it musickeys.sh. Make the script executable:

$ chmod +x musickeys.sh

By executing ./musickeys.sh play you can now toggle playing a song. Now you can bind this script to any tool that catches keypresses, such as xbindkeys. For Openbox you can use the following example (see Openbox#Configuration for help):

<keybind key="XF86AudioPlay">
  <action name="Execute">
      <execute>~/bin/musickeys.sh play</execute>
  </action>
</keybind>
<keybind key="XF86AudioNext">
  <action name="Execute">
      <execute>~/bin/musickeys.sh next</execute>
  </action>
</keybind>
<keybind key="XF86AudioPrev">
  <action name="Execute">
      <execute>~/bin/musickeys.sh prev</execute>
  </action>
</keybind>

D-Bus

An alternative to the above is D-Bus, which should be available by default as it is a dependency of systemd. With D-Bus we have a consistent and reliable way to communicate with other processes, such as Spotify. To play or pause the current song in Spotify:

$ dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

In order to bind this and the other commands to the media keys you need to install Xbindkeys and edit your .xbindkeysrc and add the following lines:

# Play/Pause
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
XF86AudioPlay

# Next
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
XF86AudioNext

# Previous
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous"
XF86AudioPrev

# Stop
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"
XF86AudioStop

See also