#!/bin/bash
#
#############################################
# #
# Teil 1/2 #
# #
# DVB-S Livestreaming per Internet #
# #
# http://www.i-have-a-dreambox.com #
# (c) by Tasman - 16.05.2008 - Version 0.01 #
# #
#############################################
#
# Verkleinerung des Streams der Dreambox 7020S auf
# DSL-taugliche groesse.
# Programmaenderung durch Zappen werden erkannt und
# der Stream neu aufgebaut.
#
# Dieses Script wird auf einem Linux-Rechner (nicht die
# Dreambox!) aufgerufen, das sich im gleichen LAN,
# wie eine Dreambox 7020S befindet.
# Auf dem benoetigten Linux-Recher (nicht die Dreambox!)
# wird VLC vorrausgesetzt.
#
# Zu diesem Programm geh?rt noch killdreamstream.sh, um
# das Programm dreamboxstream.sh zu stoppen.
#
# Aufrufbar unter WinXP im Windows-Media-Player:
# mms://adresse_des_linux_servers:8090
#
# Was wird benoetigt:
# - Dreambox 7020S im LAN
# - Linux-PC im LAN
# - vlc (Video Lan Client)
# - wget
# - html2text
# - Windows PC irgendwo im Internet
# - Windows-Media-Player
#
# ------------
# | Dreambox | (Quelle Basisstream)
# ------------
# |
# | per LAN
# V
# ------------
# | Linux-PC | (Umrechnung in Internetstream)
# ------------
# |
# | per Internet
# V
# ------------
# | Win-PC | (Abspielen im WMP)
# ------------
#
# Konfiguration der Dreambox-Parameter anpassen:
# DREAMIP: IP-Adresse der Dreambox
DREAMIP="1.1.1.1"
# DREAMUSER: Benutzername der Dreambox
DREAMUSER="root"
# DREAMPWD: Passwort f?r Benutzer der Dreambox
DREAMPWD="dreambox"
# Konfiguration zur Qualitaet des Streams anpassen:
# Moeglich unten in Zeile, die mit "vlc" beginnt.
# vb: Videobitrate
# ab: Audiobitrate
# url: Portnummer, die der Client kennen muss fuer mms://...-Adresse
# Hauptprogramm mit Kanal- und Endlosschleife
rm channelepg.html 1> /dev/null 2> /dev/null
rm channelepg.txt 1> /dev/null 2> /dev/null
rm channeleventneu.html 1> /dev/null 2> /dev/null
rm channelidneu.txt 1> /dev/null 2> /dev/null
rm channelid.txt 1> /dev/null 2> /dev/null
rm channelinfos.html 1> /dev/null 2> /dev/null
rm channelname.txt 1> /dev/null 2> /dev/null
CHANNELID=dummy
CHANNELIDNEU=""
CHANNELEVENT=dummy
CHANNELEVENTNEU=""
CHANNELNAME=""
CHANNELPROVIDER=""
CHANNELSATTELITE=""
CHANNELFREQUENCY=""
CHANNELPOLARISATION=""
CHANNELCRYPT=""
CHANNELEPGEVENT=""
CHANNELEPGTIME=""
CHANNELEPGDESC=""
CHANNELVIDEOPID=""
while [ 1 = 1 ]
do
while [ "$CHANNELID" = "$CHANNELIDNEU" -a "$CHANNELEVENT" = "$CHANNELEVENTNEU" ]
do
sleep 3
echo -n .
CHANNELIDNEU=`wget -q --http-user=$DREAMUSER --http-password=$DREAMPWD http://$DREAMIP/control/getonidsid -O channelidneu.txt; cat channelidneu.txt`
CHANNELEVENTNEU=`wget -q --http-user=$DREAMUSER --http-password=$DREAMPWD http://$DREAMIP/cgi-bin/channelinfo -O channeleventneu.html; cat channeleventneu.html | grep "time" -m1 | html2text`
done
echo
echo Programm-/Sendungwechsel erkannt...
kill -9 `pgrep vlc` 1> /dev/null 2> /dev/null
sleep 5
rm channelepg.html 1> /dev/null 2> /dev/null
rm channelepg.txt 1> /dev/null 2> /dev/null
rm channeleventneu.html 1> /dev/null 2> /dev/null
rm channelidneu.txt 1> /dev/null 2> /dev/null
rm channelid.txt 1> /dev/null 2> /dev/null
rm channelinfos.html 1> /dev/null 2> /dev/null
rm channelname.txt 1> /dev/null 2> /dev/null
CHANNELID=`wget -q --http-user=$DREAMUSER --http-password=$DREAMPWD http://$DREAMIP/control/getonidsid -O channelid.txt; cat channelid.txt`
CHANNELIDNEU=$CHANNELID
CHANNELEVENT=`wget -q --http-user=$DREAMUSER --http-password=$DREAMPWD http://$DREAMIP/cgi-bin/channelinfo -O channelevent.html; cat channelevent.html | grep "time" -m1 | html2text`
CHANNELEVENTNEU=$CHANNELEVENT
wget -q --http-user=$DREAMUSER --http-password=$DREAMPWD http://$DREAMIP/cgi-bin/channelinfo -O channelepg.html
wget -q --http-user=$DREAMUSER --http-password=$DREAMPWD http://$DREAMIP/xml/streaminfo -O channelinfos.html
CHANNELNAME=`cat channelinfos.html | grep "<name>" | html2text -ascii`
CHANNELPROVIDER=`cat channelinfos.html | grep provider | html2text -ascii`
CHANNELSATTELITE=`cat channelinfos.html | grep satellite | html2text -ascii`
CHANNELFREQUENCY=`cat channelinfos.html | grep frequency | html2text`
CHANNELPOLARISATION=`cat channelinfos.html | grep polarisation | html2text`
CHANNELCRYPT=`cat channelinfos.html | grep used_crypt_systems | html2text -ascii`
CHANNELEPGEVENT=`cat channelepg.html | grep "event" -m1 | html2text -ascii`
CHANNELEPGTIME=`cat channelepg.html | grep "time" -m1 | html2text`
CHANNELEPGDESC=`cat channelepg.html | grep "description" -m1 | html2text | uniconv -decode German -encode Latin`
CHANNELVIDEOPID=`cat channelinfos.html | grep vpid | html2text`
if [ "$CHANNELEPGTIME" != "" -a "$CHANNELEPGEVENT" != "" ]
then CHANNELFULLPROGRAM="$CHANNELNAME ($CHANNELEPGTIME $CHANNELEPGEVENT)"
else CHANNELFULLPROGRAM="$CHANNELNAME"
fi
if [ "$CHANNELEPGDESC" = "" ]
then CHANNELEPGDESC="(no detailed info)"
fi
echo " $CHANNELFULLPROGRAM"
# In Anhaengigkeit der Videoverfuegbarkeit verschiedene Streams bauen
if [ "$CHANNELVIDEOPID" = "ffffffffh (-1d)" ]
then vlc http://$DREAMUSER:$DREAMPWD@$DREAMIP/video.m3u --sout '#transcode{acodec=mp3,ab=196}:standard{access=mmsh,mux=asfh,url=:8090}' --sout-asf-title "$CHANNELFULLPROGRAM" --sout-asf-author "www.i-have-a-dreambox.com" --sout-asf-copyright "www.i-have-a-dreambox.com" --sout-asf-comment "Live DVB-S / Channel $CHANNELNAME of provider $CHANNELPROVIDER on $CHANNELSATTELITE at $CHANNELFREQUENCY MHz in $CHANNELPOLARISATION polarisation / Playing: $CHANNELEPGEVENT $CHANNELEPGDESC / Encryption in use: $CHANNELCRYPT" --intf telnet -d
else vlc http://$DREAMUSER:$DREAMPWD@$DREAMIP/video.m3u --sout '#transcode{vcodec=DIV3,vb=192,scale=0.5,acodec=mp3,ab=64,audio-sync}:standard{access=mmsh,mux=asfh,url=:8090}' --sout-asf-title "$CHANNELFULLPROGRAM" --sout-asf-author "www.i-have-a-dreambox.com" --sout-asf-copyright "www.i-have-a-dreambox.com" --sout-asf-comment "Live DVB-S / Channel $CHANNELNAME of provider $CHANNELPROVIDER on $CHANNELSATTELITE at $CHANNELFREQUENCY MHz in $CHANNELPOLARISATION polarisation / Playing: $CHANNELEPGEVENT $CHANNELEPGDESC / Encryption in use: $CHANNELCRYPT" --intf telnet -d
fi
echo -n Pruefe Programm-/Sendungwechsel... `date` .
done