mirror of
https://github.com/LibreELEC/LibreELEC.tv
synced 2025-09-24 19:46:01 +07:00
120 lines
3.0 KiB
Bash
Executable File
120 lines
3.0 KiB
Bash
Executable File
#!/bin/sh
|
|
################################################################################
|
|
# This file is part of LibreELEC - https://libreelec.tv
|
|
# Copyright (C) 2016 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/>.
|
|
################################################################################
|
|
|
|
. /etc/os-release
|
|
. /etc/profile
|
|
oe_setup_addon service.spotify-connect-web
|
|
|
|
chmod +x "$ADDON_DIR/spotify-connect-web"
|
|
mkdir -p "$ADDON_HOME"
|
|
|
|
activate_card() {
|
|
if [ -e "/proc/asound/$1" ]
|
|
then
|
|
return
|
|
fi
|
|
if [ "$LIBREELEC_ARCH" == "RPi2.arm" -a "$1" == "ALSA" ]
|
|
then
|
|
dtparam audio=on
|
|
sleep 1
|
|
else
|
|
echo "Do not know how to activate card $1 on $LIBREELEC_ARCH"
|
|
exit
|
|
fi
|
|
}
|
|
|
|
if [ ! "$(cat /proc/asound/pcm 2> /dev/null)" ]
|
|
then
|
|
if [ "$LIBREELEC_ARCH" == "RPi2.arm" ]
|
|
then
|
|
activate_card "ALSA"
|
|
else
|
|
echo "Do not how how to activate an audio interface on $LIBREELEC_ARCH"
|
|
ko="ko"
|
|
fi
|
|
fi
|
|
|
|
if [ ! -f "$ADDON_HOME/spotify_appkey.key" ]
|
|
then
|
|
echo "Key not found"
|
|
ko="ko"
|
|
fi
|
|
|
|
if [ ! "$scw_o" ]
|
|
then
|
|
echo "Playback device not set"
|
|
ko="ko"
|
|
fi
|
|
|
|
if [ "$ko" ]
|
|
then
|
|
exit
|
|
fi
|
|
|
|
case "$scw_o" in
|
|
|
|
*:CARD=*)
|
|
card="${scw_o##*: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="${scw_o##hw:}"
|
|
index="${index%%,*}"
|
|
card="card$index"
|
|
activate_card "$card"
|
|
;;
|
|
|
|
*)
|
|
echo "Unknown playback device specification $swc_o"
|
|
exit
|
|
;;
|
|
|
|
esac
|
|
|
|
[ "$scw_m" ] && [ "$vol_0" ] && amixer -c "$index" set "$scw_m" "$vol_0%"
|
|
|
|
if [ "$LIBREELEC_ARCH" == "RPi2.arm" -a \
|
|
"$(readlink /proc/asound/ALSA)" == "card$index" ]
|
|
then
|
|
[ "$pcm_3" ] && amixer -c "$index" cset name="PCM Playback Route" "$pcm_3"
|
|
fi
|
|
|
|
avahi-publish -s \
|
|
TestConnect _spotify-connect._tcp 4000 VERSION=1.0 CPath=/login/_zeroconf &
|
|
|
|
[ "$scw_b" == "-" ] && scw_b=""
|
|
[ "$scw_b" ] && scw_b="-b $scw_b"
|
|
[ "$scw_m" ] && scw_m="-m $scw_m"
|
|
[ "$scw_p" ] && [ "$scw_u" ] && scw_p="-p $scw_p" && scw_u="-u $scw_u"
|
|
|
|
cd "$ADDON_DIR"
|
|
./spotify-connect-web $scw_b \
|
|
-c "$ADDON_HOME/credentials.json" \
|
|
-k "$ADDON_HOME/spotify_appkey.key" \
|
|
$scw_m \
|
|
-n "$HOSTNAME" \
|
|
-o "$scw_o" \
|
|
$scw_p \
|
|
$scw_u \
|
|
--mixer_device_index "$index"
|