#!/bin/bash # Usate, modificate, riscrivete questo script come vi pare. # se vi succede qualcosa di brutto a causa di questo script, # io non c'ero, e se c'ero dormivo, ergo: sono cavoli vostri. chiaro? ## CONFIGURAZIONE UTENTE tries=5 #tentativi di scaricare ogni file timeout=10 #tempo massimo di attesa risposta per lo scaricamento (secondi) player="vlc" #nome del player video. output="si" #mandare a video i messaggi del player? (si/no) background="no" #mandare il player in background, in modo da aver disponibile il terminale? #per salvare gli stream, usate il vostro player preferito. #per mplayer ad esempio, basta modificare la variabile "player" a: # player="mplayer -dumpfile stream.wmv -dumpstream" ############ PROGRAMMA REALE ################ ############ NON MODIFICARE! ################ NOTFOUND="" for command in wget sed grep awk tail head dialog; do if [ -z "`which $command 2>/dev/null`" ]; then NOTFOUND="`echo "$NOTFOUND $command"`" fi done if [ -n "$NOTFOUND" ]; then echo "Comandi non trovati:" echo $NOTFOUND exit 1 fi USERAGENT='Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.0.6) Gecko/2009011912 Firefox/3.0.11' PLAYERCMD="`echo $player|awk -F " " '{print $1}'`" if [ -z "`which $PLAYERCMD 2>/dev/null`" ]; then echo "Player $PLAYERCMD non trovato!" exit 1 fi unset PLAYERCMD case $output in [Ss][Ii]) ;; [Nn][Oo]) ;; *) echo "La variabile \"output\" ammette solo" echo "I valori \"si\" e \"no\"" exit 1 ;; esac case $background in [Ss][Ii]) ;; [Nn][Oo]) ;; *) echo "La variabile \"background\" ammette solo" echo "I valori \"si\" e \"no\"" exit 1 ;; esac help () { echo "Script per la visualizzazione dei canali presenti su rai.tv" echo "senza il plugin Silverlight di Microsoft o Moonlight di Novell" echo "Creato da Luke88 -- luke88 _at_ slacky.it" echo -e "\nUso:\t$0 chiave_ricerca\tcerca canale nella lista" echo -e "\t$0 tutti\t\tlista completa dei canali" echo "" echo "per configurare player e comportamenti del player" echo "cambiare le variabili all'inizio di questo scirpt" echo "con il vostro editor preferito" echo -e "\nlo script non porta con se garanzie di qualsiasi tipo" } update () { echo "scarico la lista dei canali...." rm ${0}.xml &>/dev/null wget -U "$USERAGENT" --tries=$tries --timeout=$timeout -O ${0}.xml --tries=$tries www.rai.tv/dl/RaiTV/videoWall/PublishingBlock-5566288c-3d21-48dc-b3e2-af7fbe3b2af8.xml &>/dev/null if [ ! -s ${0}.xml ]; then echo "Download fallito! controlla la connessione internet e rilancia il programma" exit 1 fi rm ${0}.tmp &>/dev/null grep -B 1 '' ${0}.xml|sed /--/d | sed s/^\ *// > ${0}.tmp rm ${0}.xml &>/dev/null sed -i s/\&apos\;/\'/g ${0}.tmp sed -i 's/\à\;/à/g' ${0}.tmp sed -i 's/\á\;/à/g' ${0}.tmp sed -i 's/\è\;/è/g' ${0}.tmp sed -i 's/\é\;/é/g' ${0}.tmp sed -i 's/\ì\;/ì/g' ${0}.tmp sed -i 's/\í\;/ì/g' ${0}.tmp sed -i 's/\ò\;/ò/g' ${0}.tmp sed -i 's/\ò\;/ò/g' ${0}.tmp sed -i 's/\ù\;/ù/g' ${0}.tmp sed -i s/\&\;/\\\&/g ${0}.tmp COUNTER=0 rm ${0}.canali &>/dev/null while read line ; do let "NUM=$COUNTER % 2" if [ $NUM -eq 0 ]; then let "NUM=$COUNTER % 20" #facciamo vedere qualcosa a schermo... if [ $NUM -eq 0 ]; then let "NUM=$COUNTER/2" #ogni 10 stream diciamo a quanti siamo... echo -n $NUM else echo -n "." fi echo -en $line|awk -F '"' '{print $2}' >> ${0}.canali #metti il nome dello stream in cache else echo -en $line|awk -F '' '{print $2}'|awk -F '' '{print $1}' >> ${0}.canali #metti l'indirizzo dello stream in cache echo "==" >> ${0}.canali #non è realmente necessario, ma se qualcuno si vuole vedere la lista selza usare lo script fi #fa comodo avere una lista leggibile let COUNTER++ done < ${0}.tmp echo "" rm ${0}.tmp &>/dev/null } check_dwn () { if [ ! -s ${0}.tmp ]; then echo "Download fallito! controlla la connessione internet e rilancia il programma" exit 1 fi } play () { if [ -z "`echo $STREAM|grep 'mms://'`" ]; then #uff... tiriamo fuori lo stream da incasinamenti vari.... rm ${0}.tmp &>/dev/null wget -U "$USERAGENT" --tries=$tries --timeout=$timeout --spider "$STREAM" -O /dev/null 1> /dev/null 2> ${0}.tmp #a volte il link è un file flv. check_dwn TMP="`tail -n 2 ${0}.tmp|grep 'flv'`" #che sembra essere solo un video.... rm ${0}.tmp if [ -z "$TMP" ]; then wget -U "$USERAGENT" --tries=$tries --timeout=$timeout -O ${0}.tmp "$STREAM" &>/dev/null check_dwn if [ -z "`grep 'http://' ${0}.tmp`" ]&&[ -z "`grep 'mms://' ${0}.tmp`" ]; then #mi è capitato che alcuni link portino nel vuoto echo "(muove la mano)--Tu *NON* vuoi vedere questo canale" rm ${0}.tmp exit 1 else if [ -n "`grep 'mms://' ${0}.tmp`" ]; then STREAM="`grep 'mms://' ${0}.tmp|awk -F '"' '{print $4}'`" elif [ -n "`grep wmv ${0}.tmp`" ]; then STREAM="`grep wmv ${0}.tmp |awk -F '"' '{print $2}'`" else STREAM="`grep 'http://' ${0}.tmp`" if [ -n "`echo $STREAM|grep 'HREF'`" ]; then STREAM="`echo $STREAM|awk -F 'HREF="' '{print $2}'|awk -F '"' '{print $1}'`" elif [ -n "`echo $STREAM|grep '"'`" ]; then STREAM="`echo $STREAM|awk -F '"' '{print $2}'`" fi rm ${0}.tmp wget -U "$USERAGENT" --tries=$tries --timeout=$timeout --spider "$STREAM" -O /dev/null 1>/dev/null 2>${0}.tmp check_dwn if [ -z "`tail -n 2 ${0}.tmp|grep 'flv'`" ]; then #se NON è un flv... wget -U "$USERAGENT" --tries=$tries --timeout=$timeout -O ${0}.tmp "$STREAM" &>/dev/null check_dwn if [ -n "`grep 'mms://' ${0}.tmp`" ]; then STREAM="`grep 'mms://' ${0}.tmp |awk -F '"' '{print $2}'`" elif [ -n "`grep '.flv' ${0}.tmp`" ]; then STREAM="`cat ${0}.tmp`" elif [ -n "`grep '.wmv' ${0}.tmp`" ]; then STREAM="`grep '.wmv' ${0}.tmp |awk -F '"' '{print $2}'`" fi fi fi rm ${0}.tmp fi fi fi case $output in [Nn][Oo]) case $background in [Nn][Oo]) $player "$STREAM" &>/dev/null ;; [Ss][Ii]) $player "$STREAM" &>/dev/null & ;; esac ;; [Ss][Ii]) case $background in [Nn][Oo]) $player "$STREAM" ;; [Ss][Ii]) $player "$STREAM" & ;; esac ;; esac } if [ "$1" == "-h" ]||[ "$1" == "--h" ]||[ "$1" == "-help" ]||[ "$1" == "--help" ]; then help exit 0 fi update COUNTER=1 #costruiamo la lista variabili per il dialog. #è una lista di elementi, del tipo #nome1 "" help1 nome2 "" help2 ... #il secondo elemento è volontariamente lasciato come lista vuota. rm ${0}.list &>/dev/null if [ "$1" == "tutti" ]||[ -z "$1" ]; then grep -v ^==$ ${0}.canali | \ while read line; do case "$COUNTER" in 1 ) echo \"$line\" >> ${0}.list #"# <--ripristino la colorazione per vim... COUNTER=2 ;; 2) echo -e \"\""\n"\"$line\" >> ${0}.list #"# <--ripristino la colorazione per vim... COUNTER=1 ;; esac done else grep -A 1 -i "$1" ${0}.canali | grep -v -- ^--$ | grep -v ^==$ |\ while read line ; do case "$COUNTER" in 0 ) COUNTER=1 #serve solo per 'saltare un turno' ;; 1 ) if [ -z "`echo $line|grep '://'`" ]; then # se non è un url echo \"$line\" >> ${0}.list #"# <--ripristino la colorazione per vim... COUNTER=2 else #abbiamo greppato l'indirizzo... non ce ne facciamo niente... COUNTER=0 fi ;; 2 ) echo \"\" >> ${0}.list #"# echo \"$line\" >> ${0}.list #"# <--ripristino la colorazione per vim... COUNTER=1 ;; esac done fi if [ ! -s ${0}.list ]; then echo "Canale non trovato..." exit 0 fi rm ${0}.reply &>/dev/null REPLY="" while [ -z "$REPLY" ]; do dialog --title "Stream disponibili" --help-button --item-help --menu "scegli lo stream da aprire" 20 70 12 --file ${0}.list 2> ${0}.reply REPLY="`tail -n 1 ${0}.reply`" rm ${0}.reply &>/dev/null if [ -n "`echo $REPLY|grep '^HELP '`" ]; then REPLY="`echo $REPLY|awk -F "HELP " '{print $2}'`" #"`"# <<-ripristino colorazione vim.... NAME="`grep -B 2 "$REPLY" ${0}.list|head -n 1`" dialog --title "$NAME" --msgbox "Lo stream è all'indirizzo:\n$REPLY" 20 70 REPLY="" elif [ -z "$REPLY" ]; then rm ${0}.list &>/dev/null break; fi done clear if [ "$REPLY" == "" ]; then echo "Nessuno stream trovato per questa ricerca" exit 0 fi STREAM="`grep -A 2 "$REPLY" ${0}.list|tail -n 1|awk -F '"' '{print $2}'`" rm ${0}.list &>/dev/null play echo ""