Skip to content

Commit

Permalink
migrate to librespot and s6-overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
meiser79 committed Nov 24, 2024
1 parent 3f57b8a commit 6946924
Show file tree
Hide file tree
Showing 44 changed files with 206 additions and 86 deletions.
36 changes: 21 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
FROM ubuntu:latest

# set version for s6 overlay
ARG S6_OVERLAY_VERSION="3.2.0.2"
ARG S6_OVERLAY_ARCH="x86_64"

RUN usermod -aG audio ubuntu

RUN apt update && apt upgrade -y \
&& apt install -y \
darkice \
icecast2 \
iproute2 \
pulseaudio \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.cache /root/.cache

COPY darkice.cfg /etc/darkice.cfg

COPY spotifyd.conf /etc/spotifyd.conf
wget \
xz-utils \
&& apt clean

COPY spotifyd /usr/local/bin/spotifyd
RUN chmod +x /usr/local/bin/spotifyd
# add s6 overlay
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz

COPY configure.sh /usr/local/bin/configure.sh
RUN chmod +x /usr/local/bin/configure.sh
# add s6 optional symlinks
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-arch.tar.xz

COPY start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.cache /root/.cache

COPY entry.sh /usr/local/bin/entry.sh
RUN chmod +x /usr/local/bin/entry.sh
ADD rootfs /

EXPOSE 8000

ENTRYPOINT ["/usr/local/bin/entry.sh"]
ENTRYPOINT ["/init"]
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Stream your Spotify collection

A docker image that creates a new device on Spotify (called "Daemon"), which streams what you're listening to Icecast.

It uses the excellent [spotifyd](https://github.com/Spotifyd/spotifyd).
It uses the excellent [librespot](https://github.com/librespot-org/librespot).

## How?

Expand All @@ -16,11 +16,15 @@ services:
spotify-stream:
container_name: spotify-stream
environment:
- SPOTIFY_DEVICE_NAME=Daemon
- LIBRESPOT_DEVICE_NAME=Daemon
# possible values: audiodongle, avr, computer, smartphone, speaker, stb, tablet, tv
- SPOTIFY_DEVICE_TYPE=computer
- SPOTIFY_INITIAL_VOLUME=90
- SPOTIFY_ZEROCONF_PORT=1234
- LIBRESPOT_DEVICE_TYPE=computer
- LIBRESPOT_CACHE=/spotify-stream/cache
- LIBRESPOT_INITIAL_VOLUME=90
- LIBRESPOT_ZEROCONF_PORT=1234
- [email protected]
- ICECAST_HOSTNAME=my.ip.address
- ICECAST_LOCATION=New\ York
- ICECAST_USERNAME=admin
- ICECAST_PASSWORD=spotify
- DARKICE_MOUNT_POINT=spotify
Expand All @@ -29,15 +33,17 @@ services:
image: meiser79/spotify-stream:latest
network_mode: host
restart: unless-stopped
volumes:
- ./cache:/spotify-stream/cache
```

Then connect to the stream via `http://my.ip.address:8000/spotify`.

## Disclaimer

[spotifyd](https://github.com/Spotifyd/spotifyd) binary was compiled via `cargo build --release --features pulseaudio_backend` and was included here to accelerate building time. You should compile it by yourself.
[librespot](https://github.com/librespot-org/librespot) binary was compiled via `cargo build --release --no-default-features --features "pulseaudio-backend with-libmdns"` and was included here to accelerate building time. You should compile it by yourself.

## Legal
Spotify Stream is licensed under MIT.
Spotify Stream is licensed under MIT, it's based on [Trugamr's project](https://github.com/Trugamr/spotify-stream).

SPOTIFY is a trademark of Spotify AB.
29 changes: 0 additions & 29 deletions configure.sh

This file was deleted.

4 changes: 0 additions & 4 deletions entry.sh

This file was deleted.

File renamed without changes.
109 changes: 109 additions & 0 deletions rootfs/etc/librespot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Please see https://github.com/librespot-org/librespot/wiki/Options
# for configuration details and a full list of options and flags.

# You can also find a full list with `librespot -h`.

# To avoid name collisions environment variables must be prepended with
# `LIBRESPOT_`, so option/flag `foo-bar` becomes `LIBRESPOT_FOO_BAR`.

# Invalid environment variables will be ignored.

# default values may vary from librespot defaults.
# Commenting out the environment variable will fallback to librespot's default
# unless otherwise noted.

# Flags can be set to either "on" or "off".
# Empty values may cause errors.

# Only log warning and error messages.
LIBRESPOT_QUIET=off

# Automatically play similar songs when your music ends.
# Respects client autoplay setting if commented out. Forces autoplay on or off when active.
# This value is either "on" or "off".
LIBRESPOT_AUTOPLAY=off

# Disable caching of the audio data.
# Enabling audio data caching can take up a lot of space
# if you don't limit the cache size with LIBRESPOT_CACHE_SIZE_LIMIT.
# It can also wear out your Micro SD card. You have been warned.
LIBRESPOT_DISABLE_AUDIO_CACHE=on

# Disable caching of credentials.
# Caching of credentials is not necessary so long as
# LIBRESPOT_DISABLE_DISCOVERY is not set.
LIBRESPOT_DISABLE_CREDENTIAL_CACHE=off

# Play all tracks at approximately the same apparent volume.
LIBRESPOT_ENABLE_VOLUME_NORMALISATION=on

# Enable verbose log output.
#LIBRESPOT_VERBOSE=off

# Disable zeroconf discovery mode.
#LIBRESPOT_DISABLE_DISCOVERY=off

# Options will fallback to their defaults if commented out,
# otherwise they must have a valid value.

# Device name.
# Librespot defaults to "Librespot".
LIBRESPOT_DEVICE_NAME="Deamon"

# Bitrate (kbps) {96|160|320}. Defaults to 160.
LIBRESPOT_BITRATE="320"

# Output format {F64|F32|S32|S24|S24_3|S16}. Defaults to S16.
#LIBRESPOT_FORMAT="S16"

# Displayed device type. Defaults to speaker.
LIBRESPOT_DEVICE_TYPE="computer"

# Limits the size of the cache for audio files.
# It's possible to use suffixes like K, M or G, e.g. 16G for example.
# Highly advised if audio caching isn't disabled. Otherwise the cache
# size is only limited by disk space.
#LIBRESPOT_CACHE_SIZE_LIMIT=""

# Audio backend to use, alsa or pulseaudio. Defaults to alsa.
LIBRESPOT_BACKEND="pulseaudio"

# Username used to sign in with.
# Credentials are not required if LIBRESPOT_DISABLE_DISCOVERY is not set.
#LIBRESPOT_USERNAME=""

# Password used to sign in with.
#LIBRESPOT_PASSWORD=""

# Audio device to use, use `librespot --device ?` to list options.
# Defaults to the system's default.
#LIBRESPOT_DEVICE="default"

# Initial volume in % from 0 - 100.
# Defaults to 50 For the alsa mixer: the current volume.
LIBRESPOT_INITIAL_VOLUME="90"

# Volume control scale type {cubic|fixed|linear|log}.
# Defaults to log.
#LIBRESPOT_VOLUME_CTRL="log"

# Range of the volume control (dB) from 0.0 to 100.0.
# Default for softvol: 60.0.
# For the alsa mixer: what the control supports.
#LIBRESPOT_VOLUME_RANGE="60.0"

# Pregain (dB) applied by volume normalisation from -10.0 to 10.0.
# Defaults to 0.0.
#LIBRESPOT_NORMALISATION_PREGAIN="0.0"

# Threshold (dBFS) at which point the dynamic limiter engages
# to prevent clipping from 0.0 to -10.0.
# Defaults to -2.0.
#LIBRESPOT_NORMALISATION_THRESHOLD="-2.0"

# The port the internal server advertises over zeroconf 1 - 65535.
# Ports <= 1024 may require root privileges.
LIBRESPOT_ZEROCONF_PORT="1234"

# HTTP proxy to use when connecting.
#LIBRESPOT_PROXY=""
Empty file.
9 changes: 9 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-darkice/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/with-contenv bash

echo "🔑 updating darkice credentials"
sed -i -r "s/^password.*$/password = $ICECAST_PASSWORD/" /etc/darkice.cfg

echo "🔨 updating darkice config"
sed -i -r "s/^mountPoint.*$/mountPoint = $DARKICE_MOUNT_POINT/" /etc/darkice.cfg
sed -i -r "s/^name.*$/name = $DARKICE_NAME/" /etc/darkice.cfg
sed -i -r "s/^description.*$/description = $DARKICE_DESCRIPTION/" /etc/darkice.cfg
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-darkice/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-darkice/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-darkice/run
Empty file.
22 changes: 22 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-icecast/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/with-contenv bash

echo "🔑 updating icecast config"

sed -i -r "s/(<admin>).*(<\\/admin>)/\1$ICECAST_ADMIN\2/ig" /etc/icecast2/icecast.xml
sed -i -r "s/(<hostname>).*(<\\/hostname>)/\1$ICECAST_HOSTNAME\2/ig" /etc/icecast2/icecast.xml
sed -i -r "s/(<location>).*(<\\/location>)/\1$ICECAST_LOCATION\2/ig" /etc/icecast2/icecast.xml
sed -i -r "s/(<burst-on-connect>).*(<\\/burst-on-connect>)/\10\2/ig" /etc/icecast2/icecast.xml

echo "🔑 updating icecast credentials"

# update username
sed -i -r "s/(<admin-user>).*(<\\/admin-user>)/\1$ICECAST_USERNAME\2/ig" /etc/icecast2/icecast.xml

# update passwords
for tag in source-password relay-password admin-password password
do
sed -i -r "s/(<$tag>).*(<\\/$tag>)/\1$ICECAST_PASSWORD\2/ig" /etc/icecast2/icecast.xml
done

echo "🔨 updating icecast's metadata"
wget -q -O - --user $ICECAST_USERNAME --password $ICECAST_PASSWORD http://localhost:8000/admin/metadata?mount=/$DARKICE_MOUNT_POINT\&mode=updinfo\&song="${DARKICE_NAME/\\/}"
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-icecast/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-icecast/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-icecast/run
Empty file.
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-darkice/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash

export HOME="$( getent passwd ubuntu | cut -d: -f6 )"
exec s6-setuidgid ubuntu darkice -c /etc/darkice.cfg
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-darkice/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-darkice/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-darkice/run
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-dbus/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

exec dbus-daemon --system --nofork
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-dbus/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-dbus/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-dbus/run
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-icecast/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

exec s6-setuidgid icecast2 icecast2 -c /etc/icecast2/icecast.xml
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-icecast/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-icecast/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-icecast/run
Empty file.
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-librespot/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash

export HOME="$( getent passwd ubuntu | cut -d: -f6 )"
exec s6-setuidgid ubuntu librespot --name $LIBRESPOT_DEVICE_NAME --device-type $LIBRESPOT_DEVICE_TYPE --backend pulseaudio --bitrate 320 --cache $LIBRESPOT_CACHE --disable-audio-cache --enable-volume-normalisation --initial-volume $LIBRESPOT_INITIAL_VOLUME --zeroconf-port $LIBRESPOT_ZEROCONF_PORT --autoplay off
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-librespot/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-librespot/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-librespot/run
Empty file.
4 changes: 4 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-pulseaudio/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv bash

export HOME="$( getent passwd ubuntu | cut -d: -f6 )"
exec s6-setuidgid ubuntu pulseaudio
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-pulseaudio/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-pulseaudio/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-pulseaudio/run
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file added rootfs/usr/local/bin/librespot
Binary file not shown.
Binary file removed spotifyd
Binary file not shown.
10 changes: 0 additions & 10 deletions spotifyd.conf

This file was deleted.

21 changes: 0 additions & 21 deletions start.sh

This file was deleted.

0 comments on commit 6946924

Please sign in to comment.