Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 2.92 KB

2018-01-11-spotify-i3.md

File metadata and controls

84 lines (62 loc) · 2.92 KB
layout title date description comments tags
post
Spotify integration with i3
2018-01-11 20:10
Spotify has a good Linux client. But it doesn't support MPD, so it is problematic to create a blocklet in i3 statusbar or interact with Spotify using shortcuts. Here I'd like to show how it could be achieved.
true
i3wm

Spotify has a good Linux client. But it doesn't support MPD, so it is problematic to interact with Spotify using shortcuts or create a blocklet in i3 statusbar. Here I'd like to show how it could be achieved. At end we'll have following blocklet:

screenshot{:.center-image}

Spotify CLI

First of all let's see how we can control Spotify from the command line. Luckily Spotify app supports MPRIS2 DBus specification, which basically means that you can send dbus messages to Spotify with actions, like play/pause, next, etc. To simplify this process here is the bash script which wraps it in handy functions: gist.github.com/streetturtle/fa6258f3ff7b17747ee3.

Let's install it:

{% highlight bash %} git clone https://gist.github.com/fa6258f3ff7b17747ee3.git cd ./fa6258f3ff7b17747ee3 chmod +x sudo ln -s ./sp /usr/local/bin/ {% endhighlight %}

Test it by running sp help.

i3 shortcuts

With sp installed it's pretty simple to create keyboard shortcut, I'm using following combinations:

  • mod{:.key}+.{:.key} - next track
  • mod{:.key}+,{:.key} - previous
  • mod{:.key}+/{:.key} - play/pause

Add following snipped to your i3 config:

~/.config/i3/config {:.filename} {% highlight config %} ... bindsym $mod+greater exec "sp next" bindsym $mod+less exec "sp prev" bindsym $mod+slash exec "sp play" ... {% endhighlight %}

i3 blocklet

Here is also nothing special. sp has two methods which is used in this blocklet - sp current-oneline to get the current artist and song name and sp status which tells if music is currently playing or not. This blocklet also supports mouse controls. Please note that you will need to install Font Awesome to have a play/pause icon.

Create spotify_blocklet file under ~/.config/i3/ with following content:

~/.config/i3/spotify_blocklet {:.filename} {% highlight bash %} #!/bin/bash

case $BLOCK_BUTTON in 1) sp play ;; # left click 4) sp next ;; # scroll up 5) sp prev ;; # scroll down esac

if sp status | grep 'Paused' > /dev/null; then printf '\xef\x81\x8c ' # fa-pause else printf '\xef\x81\x8b ' # fa-play fi sp current-oneline {% endhighlight %}

Make it executable (chmod +x ./spotify_blocklet) and test it by executing. Finally in .i3blocks.conf add blocklet definition:

{% highlight conf %}

[spotify] command=$HOME/.config/i3/spotify_blocklet interval=1 color=#74AEAB {% endhighlight %}