Rai.tv senza silverlight: differenze tra le versioni
(→Script) |
(→Script) |
||
| Riga 16: | Riga 16: | ||
se conoscete già il nome del canale che volete cercare, eseguitelo con ./script nome_canale_cercato. |
se conoscete già il nome del canale che volete cercare, eseguitelo con ./script nome_canale_cercato. |
||
= Script = |
= Script = |
||
| − | versione: 0.1.2 |
+ | versione: 0.1.3 |
| − | --update: corretto un errore nel cercare il canale passato da riga di comando |
+ | --update: |
| + | * corretto un errore nel cercare il canale passato da riga di comando |
||
| + | * possibilità di ignorare i messaggi a terminale del player. |
||
<pre> |
<pre> |
||
#!/bin/bash |
#!/bin/bash |
||
| Riga 29: | Riga 29: | ||
timeout=10 #tempo massimo di attesa risposta per lo scaricamento (secondi) |
timeout=10 #tempo massimo di attesa risposta per lo scaricamento (secondi) |
||
player="gmplayer" #nome del player video. |
player="gmplayer" #nome del player video. |
||
| + | output="si" #mandare a video i messaggi del player? (si/no) |
||
#per salvare gli stream, usate il vostro player preferito. |
#per salvare gli stream, usate il vostro player preferito. |
||
#per mplayer ad esempio, basta modificare la variabile "player" a: |
#per mplayer ad esempio, basta modificare la variabile "player" a: |
||
# player="mplayer -dumpfile stream.wmv -dumpstream" |
# player="mplayer -dumpfile stream.wmv -dumpstream" |
||
| − | |||
############ PROGRAMMA REALE ################ |
############ PROGRAMMA REALE ################ |
||
| Riga 54: | Riga 54: | ||
fi |
fi |
||
unset PLAYERCMD |
unset PLAYERCMD |
||
| + | case $output in |
||
| + | [Ss][Ii]) |
||
| + | ;; |
||
| + | [Nn][Oo]) |
||
| + | ;; |
||
| + | *) |
||
| + | echo "La variabile \"output\" ammette solo" |
||
| + | echo "I valori \"si\" e \"no\"" |
||
| + | exit 1 |
||
| + | ;; |
||
| + | esac |
||
help () { |
help () { |
||
echo "Script per la visualizzazione dei canali presenti su rai.tv" |
echo "Script per la visualizzazione dei canali presenti su rai.tv" |
||
| Riga 104: | Riga 115: | ||
else |
else |
||
echo -en $line|awk -F '<url>' '{print $2}'|awk -F '</url>' '{print $1}' >> ${0}.canali #metti l'indirizzo dello stream in cache |
echo -en $line|awk -F '<url>' '{print $2}'|awk -F '</url>' '{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 senza usare lo script |
+ | 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 |
fi #fa comodo avere una lista leggibile |
||
let COUNTER++ |
let COUNTER++ |
||
| Riga 110: | Riga 121: | ||
echo "" |
echo "" |
||
rm ${0}.tmp &>/dev/null |
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 () { |
play () { |
||
| − | if [ -n "`echo $STREAM|grep 'mms://'`" ]; then |
+ | if [ -z "`echo $STREAM|grep 'mms://'`" ]; then |
| − | #ok, siamo stati fortunati.... |
||
| − | $player "$STREAM" |
||
| − | else |
||
#uff... tiriamo fuori lo stream da incasinamenti vari.... |
#uff... tiriamo fuori lo stream da incasinamenti vari.... |
||
rm ${0}.tmp &>/dev/null |
rm ${0}.tmp &>/dev/null |
||
wget --spider --tries=$tries --timeout=$timeout "$STREAM" 1> /dev/null 2> ${0}.tmp #a volte il link è un file flv. |
wget --spider --tries=$tries --timeout=$timeout "$STREAM" 1> /dev/null 2> ${0}.tmp #a volte il link è un file flv. |
||
| − | if [ -n "`tail -n 2 ${0}.tmp|grep 'flv'`" ]; then #che sembra essere solo un video.... |
+ | check_dwn |
| − | rm ${0}.tmp |
+ | TMP="`tail -n 2 ${0}.tmp|grep 'flv'`" #che sembra essere solo un video.... |
| − | $player "$STREAM" |
+ | rm ${0}.tmp |
| − | else |
+ | if [ -z "$TMP" ]; then |
| − | rm ${0}.tmp |
||
wget -O ${0}.tmp --tries=$tries --timeout=$timeout "$STREAM" &>/dev/null |
wget -O ${0}.tmp --tries=$tries --timeout=$timeout "$STREAM" &>/dev/null |
||
| + | check_dwn |
||
if [ -z "`grep 'http://' ${0}.tmp`" ]&&[ -z "`grep 'mms://' ${0}.tmp`" ]; then |
if [ -z "`grep 'http://' ${0}.tmp`" ]&&[ -z "`grep 'mms://' ${0}.tmp`" ]; then |
||
#mi è capitato che alcuni link portino nel vuoto |
#mi è capitato che alcuni link portino nel vuoto |
||
echo "(muove la mano)--Tu *NON* vuoi vedere questo canale" |
echo "(muove la mano)--Tu *NON* vuoi vedere questo canale" |
||
| + | rm ${0}.tmp |
||
| + | exit 1 |
||
else |
else |
||
if [ -n "`grep 'mms://' ${0}.tmp`" ]; then |
if [ -n "`grep 'mms://' ${0}.tmp`" ]; then |
||
| Riga 134: | Riga 154: | ||
STREAM="`echo $STREAM|awk -F '"' '{print $2}'`" |
STREAM="`echo $STREAM|awk -F '"' '{print $2}'`" |
||
fi |
fi |
||
| − | rm ${0}.tmp &>/dev/null |
+ | rm ${0}.tmp |
wget --spider --tries=$tries --timeout=$timeout "$STREAM" 1>/dev/null 2>${0}.tmp |
wget --spider --tries=$tries --timeout=$timeout "$STREAM" 1>/dev/null 2>${0}.tmp |
||
| + | check_dwn |
||
if [ -z "`tail -n 2 ${0}.tmp|grep 'flv'`" ]; then #se NON è un flv... |
if [ -z "`tail -n 2 ${0}.tmp|grep 'flv'`" ]; then #se NON è un flv... |
||
wget -O ${0}.tmp --tries=$tries --timeout=$timeout "$STREAM" &>/dev/null |
wget -O ${0}.tmp --tries=$tries --timeout=$timeout "$STREAM" &>/dev/null |
||
| + | check_dwn |
||
if [ -n "`grep 'mms://' ${0}.tmp`" ]; then |
if [ -n "`grep 'mms://' ${0}.tmp`" ]; then |
||
STREAM="`grep 'mms://' ${0}.tmp |awk -F '"' '{print $2}'`" |
STREAM="`grep 'mms://' ${0}.tmp |awk -F '"' '{print $2}'`" |
||
| Riga 148: | Riga 170: | ||
fi |
fi |
||
rm ${0}.tmp |
rm ${0}.tmp |
||
| − | $player "$STREAM" |
||
fi |
fi |
||
fi |
fi |
||
fi |
fi |
||
| + | case $output in |
||
| + | [Nn][Oo]) |
||
| + | $player "$STREAM" &>/dev/null |
||
| + | ;; |
||
| + | [Ss][Ii]) |
||
| + | $player "$STREAM" |
||
| + | ;; |
||
| + | esac |
||
} |
} |
||
if [ "$1" == "-h" ]||[ "$1" == "--h" ]||[ "$1" == "-help" ]||[ "$1" == "--help" ]; then |
if [ "$1" == "-h" ]||[ "$1" == "--h" ]||[ "$1" == "-help" ]||[ "$1" == "--help" ]; then |
||
| Riga 165: | Riga 194: | ||
rm ${0}.list &>/dev/null |
rm ${0}.list &>/dev/null |
||
if [ "$1" == "tutti" ]||[ -z "$1" ]; then |
if [ "$1" == "tutti" ]||[ -z "$1" ]; then |
||
| − | grep -v '==' ${0}.canali | \ |
+ | grep -v ^==$ ${0}.canali | \ |
while read line; do |
while read line; do |
||
case "$COUNTER" in |
case "$COUNTER" in |
||
| Riga 186: | Riga 215: | ||
;; |
;; |
||
1 ) |
1 ) |
||
| − | if [ -z "`echo $line|grep '://'`" ]; then # se non è un url |
+ | if [ -z "`echo $line|grep '://'`" ]; then # se non è un url |
echo \"$line\" >> ${0}.list #"# <--ripristino la colorazione per vim... |
echo \"$line\" >> ${0}.list #"# <--ripristino la colorazione per vim... |
||
COUNTER=2 |
COUNTER=2 |
||
Versione delle 19:09, 19 feb 2009
Descrizione
Recentemente il portale rai.tv è stato riscritto in modo da usare il player microsoft silverlight per i contenuti streaming. Per GNU/Linux esiste il plugin Moonlight, sviluppato dalla Novell, ma quest'ultimo deve comunque usare codec proprietari, e sembra essere un grosso mangiarisorse (almeno allo stato attuale).
Questo script si scarica l'intera lista degli stream direttamente dal sito della rai, e vi fa scegliere da menu (stile pkgtool) il canale desiderato e infine lancia il vostro player preferito su quello stream.
Sono così visualizzabili non solo raiuno, raidue, raitre, rainews, raistoria, raiedu, ma anche spezzoni (o intere trasmissioni) di alcune trasmissioni dell'ultima settimana o giù di li.
Uso
Basta salvare questo script con il nome che preferite, renderlo eseguibile ( chmod +x nome_script ) ed eseguirlo. per cambiare il player usato basta cambiare la variabile player con player="comando_vostro_player" all'inizio dello script
se conoscete già il nome del canale che volete cercare, eseguitelo con ./script nome_canale_cercato.
Script
versione: 0.1.3
--update:
- corretto un errore nel cercare il canale passato da riga di comando
- possibilità di ignorare i messaggi a terminale del player.
#!/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="gmplayer" #nome del player video.
output="si" #mandare a video i messaggi del player? (si/no)
#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
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
help () {
echo "Script per la visualizzazione dei canali presenti su rai.tv"
echo "senza il plugin Silverlight di Microsoft"
echo "Creato da Luke88 -- luke88 _at_ slacky.it"
echo "Scrivetemi pure per dettagli"
echo -e "\nUso:\t$0 chiave_ricerca\tcerca canale nella lista"
echo -e "\t$0 tutti\t\tlista completa dei canali"
echo "Per cambiare il player video basta cambiare la variabile \"player\""
echo "in questo script."
echo -e "\nlo script non porta con se garanzie di qualsiasi tipo"
echo "quindi se diventa senziente e tiene in ostaggio la vostra famiglia,"
echo "o vi da qualsiasi altro problema, non sono problemi miei."
}
update () {
echo "scarico la lista dei canali...."
rm ${0}.xml &>/dev/null
wget -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 '<url>' ${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 '<url>' '{print $2}'|awk -F '</url>' '{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 --spider --tries=$tries --timeout=$timeout "$STREAM" 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 -O ${0}.tmp --tries=$tries --timeout=$timeout "$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 '"'`" ]; then
STREAM="`echo $STREAM|awk -F '"' '{print $2}'`"
fi
rm ${0}.tmp
wget --spider --tries=$tries --timeout=$timeout "$STREAM" 1>/dev/null 2>${0}.tmp
check_dwn
if [ -z "`tail -n 2 ${0}.tmp|grep 'flv'`" ]; then #se NON è un flv...
wget -O ${0}.tmp --tries=$tries --timeout=$timeout "$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`"
else
STREAM="`grep '.wmv' ${0}.tmp |awk -F '"' '{print $2}'`"
fi
fi
fi
rm ${0}.tmp
fi
fi
fi
case $output in
[Nn][Oo])
$player "$STREAM" &>/dev/null
;;
[Ss][Ii])
$player "$STREAM"
;;
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 ""