#!/bin/sh
title="Sopcast Firefox"
# sopcast staff
conf_file=~/.qt/sopcastrc
### FUNCTIONS ###
message () {
if [ ! -x $(which g-message) ]; then
echo "g-message not found, get it at http://idefix.eup.uva.es/paquetes/g-message_XXXXX.deb"
echo " MESSAGE: $4"
else
gxmessage -p $2 "$title" "$4"
fi
}
install_sopcast() {
# firefox staff
# check if sopcast-firefox is installed in user.js
# based on klik installer
PROFILES=$(find $HOME/.mozilla/ | grep prefs.js$ |grep -v extensions)
if [ -z "$PROFILES" ] ; then
message -p critical "$title" "No se ha encontrado ninguna instancia \
de firefox o mozilla en su $HOME. Arranque firefox al menos una vez"
else
for i in $PROFILES; do
USERJS="$(dirname "$i")/user.js"
if [ $(grep -c "sopcast-firefox" $USERJS 2> /dev/null) = 0 ] ; then
echo "user_pref(\"network.protocol-handler.app.sop\", \"sopcast-firefox\");" >> $USERJS
message -p normal "$title" "Sopcast Firefox instalado correctamente en $i"
fi
done
fi
}
get_sopvalue (){
value=$(grep $1"=" $conf_file | awk -F "=" '{print $2}')
if [ -z $value ]; then
message -p normal "$title" "No se pudo leer la configuración de la variable $1."
else
echo $value
fi
}
######################################################
# call install_sopcast (if needed)
install_sopcast
if [ -z $1 ]; then
message -p normal "$title" "No ha pasado una URL del tipo sop://"
exit 0
fi
if [ ! -f $conf_file ]; then
message -p critical "$title" "Archivo de configuración no encontrado, \
configure la aplicación, guarde y cierre la siguiente ventana."
sleep 2
sopgui
fi
# get var values
LocalPort=$(get_sopvalue LocalPort)
PlayerPort=$(get_sopvalue PlayerPort)
Player=$(get_sopvalue Player)
message -u normal "$title" "Arrancando streaming $@"
cd /usr/share/sopgui
./sp-sc $@ $LocalPort $PlayerPort > ~/.sp-sc.log 2>&1 &
sleep 15
message -u normal "$title" "Espere mientras se cachea durante 40 segundos. \
Al cerrar el reproductor se parara el stream."
sleep 25
$Player http://localhost:$PlayerPort >/dev/null 2>&1
message -u normal "$title" "Parando streaming..."
killall sp-sc
exit 0