Files
LibreELEC.tv/packages/addons/service/librespot/source/bin/librespot.start
2017-09-13 21:22:50 +02:00

125 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
################################################################################
# This file is part of LibreELEC - https://libreelec.tv
# Copyright (C) 2017-present Team LibreELEC
#
# LibreELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# LibreELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
activate_card() {
if [ -e "/proc/asound/$1" ]; then
return
fi
case "$LIBREELEC_ARCH" in
RPi*.arm)
if [ "$1" = "ALSA" ]; then
dtparam audio=on
sleep 1
fi
;;
*)
echo "Unable to activate card $1 on $LIBREELEC_ARCH"
exit
;;
esac
}
init_alsa() {
. /etc/os-release
if [ ! "$(cat /proc/asound/pcm 2> /dev/null)" ]; then
case "$LIBREELEC_ARCH" in
RPi*.arm)
activate_card "ALSA"
;;
*)
echo "Unable to activate an audio interface on $LIBREELEC_ARCH"
exit
;;
esac
fi
case "$ls_o" in
*:CARD=*)
card="${ls_o##*:CARD=}"
card="${card%%,*}"
activate_card "$card"
index="$(readlink /proc/asound/$card)"
index="${index##*card}"
;;
hw:*,*)
echo "The hw:d,s specification is unreliable, use device:CARD=card instead"
index="${ls_o##hw:}"
index="${index%%,*}"
card="card$index"
activate_card "$card"
;;
*)
if [ -n "$ls_o" ]; then
echo "Unknown playback device specification $ls_o"
fi
;;
esac
case "$LIBREELEC_ARCH" in
RPi*.arm)
[ "$(readlink /proc/asound/ALSA)" == "card$index" ] && [ "$pcm_3" ] &&
amixer -c "$index" cset name="PCM Playback Route" "$pcm_3"
;;
esac
}
. /etc/profile
oe_setup_addon service.librespot
LIBRESPOT="librespot --cache \"$ADDON_HOME/cache\" \
--disable-audio-cache \
--name \"Librespot@$HOSTNAME\" \
--onstart librespot.onstart \
--onstop librespot.onstop"
if [ -n "$ls_b" -a "$ls_b" != "-" ]; then
LIBRESPOT="$LIBRESPOT --bitrate $ls_b"
fi
if [ -n "$ls_p" -a -n "$ls_u" ]; then
LIBRESPOT="$LIBRESPOT --disable-discovery \
--password \"$ls_p\" \
--username \"$ls_u\""
fi
if [ "$ls_O" == "Kodi" ]; then
LIBRESPOT="$LIBRESPOT --backend pulseaudio --device-type TV"
else
init_alsa
if [ -n "$ls_o" ]; then
LIBRESPOT="$LIBRESPOT --device \"$ls_o\""
fi
LIBRESPOT="$LIBRESPOT --device-type Speaker"
fi
if [ -z "$(pactl list short modules | grep sink_name=$LS_SINK)" ]; then
pactl load-module module-null-sink sink_name="$LS_SINK" > /dev/null
fi
pactl suspend-sink "$LS_SINK" 1
if [ -z "$(pactl list short modules | grep source=$LS_SINK.monitor)" ]; then
pactl load-module module-rtp-send source="$LS_SINK.monitor" \
destination_ip=127.0.0.1 port="$LS_PORT" source_ip=127.0.0.1 > /dev/null
fi
export LS_FIFO="$ADDON_DIR/rc"
eval $LIBRESPOT