#!/bin/bash # This program 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. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. #Usage : changerChaine [ -z ] [ -c|-a ] chaine_tv|roulette #---initlistchan : création d'un tableau de chaînes (chaine 1,2..n) en fonction des entrées de ~/.mplayer/channels.conf # création de la liste des chaînes disponibles initlistchan() { i=1; while read chan do LIST_CHAN="$LIST_CHAN "${chan%%:*}"," TABCHAN[i]="${chan%%:*}" ((i++)) done < $HOME/.mplayer/channels.conf LIST_CHAN=$(echo "$LIST_CHAN" | sed 's/\(.*\),$/\1/') } initlistchan MSG_AIDE="Usage : $0 [ -z (zenity dialog) ] [-c (libcaca)| -a (ascii)] chaine|numéro chaine (p.e $(tail -1 < <(head -n $(($RANDOM%$(wc -l $HOME/.mplayer/channels.conf | cut -d' ' -f1))) $HOME/.mplayer/channels.conf) | cut -d':' -f1))|roulette \ \n\troulette ouvre une chaine de tv au hasard\ \nLa liste des chaines disponible est :"$LIST_CHAN"" OPTVID="xv" #---testrunning : teste si mplayer est déjà lancé, si oui, tuer le processus. # testrunning() { PID=$(pgrep mplayer) [ -n "$PID" ] && kill -9 "$PID" } #---randomchan : choisi une chaîne au hasard dans ~/.mplayer/channels.conf randomchan() { echo "$(tail -1 < <(head -n $(($RANDOM%$(wc -l $HOME/.mplayer/channels.conf | cut -d' ' -f1))) $HOME/.mplayer/channels.conf) | cut -d':' -f1)" } #---mplayerrun : lance mplayer avec les options choisies après avoir testé mplayerrun() { testrunning mplayer -vo "$OPTVID" dvb://"$1" > /dev/null 2>&1 } #---testchannel : teste en premier lieu si le paramètre en entrée est un nombre: - si oui, on test avec la valeur tableau à l'indice du paramètre en entrée # - sinon, avec le paramètre en entrée # ensuite, si cette châine est trouvée, on lance mplayer dessus, sinon, on afiche un message d'erreur testchannel() { expr "$1" + 1 > /dev/null 2>&1 [ $? -eq 0 ] && NUM=ok while read ligne do if [ -z "$NUM" ] ; then if [ "$1" = "${ligne%%:*}" ] ; then CHAN="$1" break fi else if [ "${TABCHAN[$1]}" = "${ligne%%:*}" ] ; then CHAN="${TABCHAN[$1]}" break fi fi done < $HOME/.mplayer/channels.conf if [ -n "$1" ] ; then mplayerrun "$CHAN" else if [ "$ZENITY" = active ] ; then zenity --error --title "Erreur chaîne" --text "$MSG_AIDE" && exit 3 else echo -e "$MSG_AIDE" && exit 3 fi fi } #--Main [ $# -lt 1 ] && echo -e "$MSG_AIDE" && exit 1 until [ "$#" -eq 0 ] ; do case "$1" in -z) ZENITY=active break;; -h|--help) echo -e "$MSG_AIDE" exit 2;; roulette) CHANNEL=randomchan mplayerrun "$CHANNEL";; -c) OPTVID="caca";; -a) OPTVID="aa";; *) testchannel "$1";; esac shift done if [ "$ZENITY" = "active" ] ; then OPTVID=$(zenity --entry --title "Options" --text "Choisir les options de mplayer (-c,-a)") case "$OPTVID" in -c) OPTVID="caca";; -a) OPTVID="aa";; *) OPTVID="xv";; esac CHANNEL=$(zenity --entry --title "Chaîne" --text "Veuillez choisir une chaîne (p.e $(randomchan)) ou un numéro de chaîne") echo "$CHANNEL" testchannel "$CHANNEL" fi