Skip to content

Instantly share code, notes, and snippets.

@alierkan
Forked from danelowe/README.markdown
Last active March 14, 2024 22:26
Show Gist options
  • Save alierkan/790dd0edb73ef197827b3e6c9e978828 to your computer and use it in GitHub Desktop.
Save alierkan/790dd0edb73ef197827b3e6c9e978828 to your computer and use it in GitHub Desktop.
Mopidy and librespot (spotify connect)
#!/bin/bash
if [ "$PLAYER_EVENT" == "start" -o "$PLAYER_EVENT" == "stop" ]
then
/usr/bin/mpc -q stop
fi
# /etc/default/raspotify -- Arguments/configuration for librespot
# Device name on Spotify Connect
DEVICE_NAME="Lounge"
# Bitrate, one of 96 (low quality), 160 (default quality), or 320 (high quality)
BITRATE="320"
# Additional command line arguments for librespot can be set below.
# See `librespot -h` for more info. Make sure whatever arguments you specify
# aren't already covered by other variables in this file. (See the daemon's
# config at `/lib/systemd/system/raspotify.service` for more technical details.)
#
# To make your device visible on Spotify Connect across the Internet add your
# username and password which can be set via "Set device password", on your
# account settings, use `--username` and `--password`.
#
# To choose a different output device (ie a USB audio dongle or HDMI audio out),
# use `--device` with something like `--device hw:0,1`. Your mileage may vary.
#
#OPTIONS="--username <USERNAME> --password <PASSWORD>"
OPTIONS="--onevent /opt/mpc_stop.sh"
# Uncomment to use a cache for downloaded audio files. Cache is disabled by
# default. It's best to leave this as-is if you want to use it, since
# permissions are properly set on the directory `/var/cache/raspotify'.
#CACHE_ARGS="--cache /var/cache/raspotify"
# By default, the volume normalization is enabled, add alternative volume
# arguments here if you'd like, but these should be fine.
#VOLUME_ARGS="--enable-volume-normalisation --linear-volume --initial-volume=100"
# Backend could be set to pipe here, but it's for very advanced use cases of
# librespot, so you shouldn't need to change this under normal circumstances.
#BACKEND_ARGS="--backend alsa"

Method taken from https://github.com/pimusicbox/pimusicbox

Assuming mopidy and Iris etc are already installed, we need to install mpc, so that we can stop playback on mopidy when we use spotify connect

sudo apt-get install mpc 

Then we install the easiest librespot spotify connect system

curl -sL https://dtcooper.github.io/raspotify/install.sh | sh

Then we just need to create a script to stop mpd playback, and customise raspotify to call this script when we start playback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment