Spotify under Linux / Ubuntu

#!/bin/bash

# add spotify repository key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 931FF8E79F0876134EDDBDCCA87FF9DF48BF1C90

# add spotify repository
echo deb http://repository.spotify.com stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list

# update repository list
sudo apt-get update -qq

# install spotify
sudo apt-get install -y spotify-client
>

Install from snap

sudo snap install spotify
 
cat <<EOF> /usr/share/applications/spotify.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/snap/bin/spotify
Name=Spotify
Icon=/snap/spotify/current/usr/share/spotify/icons/spotify-linux-24.png
EOF

Fix "GLIBC_2.14 not found"on Debian Wheezy
http://www.random-dev.de/fix-version-glibc_2-14-found-error/

Record stream

SPOTIFY=$(pacmd list-sink-inputs | while read line; do
  [[ -n $(echo $line | grep "index:") ]] && index=$line
  [[ -n $(echo $line | grep Spotify) ]] && echo $index && exit
done | cut -d: -f2)
echo ${SPOTIFY}
 
# muted
pactl load-module module-null-sink 'sink_name=spotify'
pactl move-sink-input ${SPOTIFY} spotify
parec -d spotify.monitor | oggenc -b 320 -o /tmp/spotify.ogg --raw -
parec --verbose --monitor-stream=${SPOTIFY} | oggenc -b 320 -o /tmp/spotify.ogg --raw -
 
# v2
# unmuted
#parec --verbose --monitor-stream=${SPOTIFY} | oggencode -b 320 -o /tmp/spotify.ogg --raw -
parec --verbose --monitor-stream=0 --file-format=wav /tmp/recording.wav 
#parec --verbose --monitor-stream=${SPOTIFY} | lame -r --quiet -q 3 --lowpass 17 --abr 192 - /tmp/spotify.mp3
parec -d record-n-play.monitor 
 
# cleanup
systemctl --user restart pulseaudio.service

Spotify ripper
https://github.com/panticz/spotifyripper