Last active
October 1, 2024 20:51
-
-
Save mxschmitt/e2ab50b9d68f983a6a48e56e0c5ba330 to your computer and use it in GitHub Desktop.
Librespot -> ffmpeg -> vlc http streaming -> Spotify connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Using the Librespot client libary for streaming the Spotfiy connect sound via http | |
# Instruction: | |
# 1. Drop this script into the root directory of the librespot repository => https://github.com/plietar/librespot | |
# 2. Install the dependencies => "sudo apt-get install vlc ffmpeg" | |
# 3. Set the correct privileges => "chmod +x start.sh" | |
# 4. Set the librespot directory owner to a non-root user | |
# 5. Switch to this user | |
# 6. Change the variables under this instruction for your needs | |
# 7. Start it by executing it => "./start.sh" or "bash start.sh" whatever :) | |
LIBR_DEVICE_NAME="Server" | |
LIBR_USERNAME="yourUsername" | |
LIBR_CACHE_DIR="cache" | |
LIBR_PORT="8081" | |
LIBR_STREAMING_PATH="/stream.mp3" | |
LIBR_LIBRESPOT_TYPE="release" | |
#Functions | |
function redMessage { | |
echo -e "\\033[31;1m${@}\033[0m" | |
} | |
function magentaMessage { | |
echo -e "\\033[35;1m${@}\033[0m" | |
} | |
# Main progress | |
function startMainProgress { | |
magentaMessage "Using username ${LIBR_USERNAME} with device name ${LIBR_DEVICE_NAME}" | |
magentaMessage "Using 0.0.0.0:portpath :${LIBR_PORT}${LIBR_STREAMING_PATH}" | |
target/${LIBR_LIBRESPOT_TYPE}/librespot --cache ${LIBR_CACHE_DIR} --name ${LIBR_DEVICE_NAME} --username ${LIBR_USERNAME} --backend pipe | ffmpeg -f s16le -ar 44.1k -ac 2 -i pipe:0 -f mp3 - | cvlc - vvv input_stream --sout "#standard{access=http,mux=mp3,dst=:${LIBR_PORT}${LIBR_STREAMING_PATH}}" | |
} | |
# Make sure the script can only be run as non-root | |
if [[ $EUID == 0 ]]; then | |
redMessage "This script must be run as non-root (because of vlc)" | |
exit 1 | |
fi | |
# Check if the credentials exits -> start normally if not let the user input the password | |
if [ ! -f "$LIBR_CACHE_DIR/credentials.json" ]; then | |
redMessage "At the first start you need to start librespot manually to enter the password." | |
magentaMessage "After you entered the password wait until librespot finished starting up and then exit it by using ctrl+c" | |
trap startMainProgress INT | |
target/${LIBR_LIBRESPOT_TYPE}/librespot --cache $LIBR_CACHE_DIR --name $LIBR_DEVICE_NAME --username $LIBR_USERNAME | |
else | |
startMainProgress | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
typo in l.36fixed