#!/bin/bash # set -x # $1 action $2=channel, $3=start time, $4=end time $5 additional options to 'at' # ln -s dvbradiorecord dvbtvrecord # simple script to record dvb radio live # hacked yet again for dvb #TODO: ?Use replex. use new tzap #TODO: implement function for checking .tzap/channels.conf ?return correct channel? #TODO: autocheck .tzap/channels.conf for radio/tv #HACK!! cd $HOME TZAP="/home/nyk/dvbutils/tzap" #use local build RDIRECTORY="/srv/temp/" TS2ES="/home/nyk/dvbutils/ts2es" FILENAME="$RDIRECTORY$(echo $2|tr [:blank:] _)_$(date +%Y%m%d_%H:%M)" MPLAYER="mplayer -vo x11" #eg "sudo mplayer" for vesa MPLAYERARGS="-autosync 30" MPLAYERXARGS="" #" -xy 0.5" #ickle window... case "$1" in timer) #ultra-simple timer function # check channel if ! grep "^$2:" $HOME/.tzap/channels.conf >/dev/null ; then echo "Could not find channel $2" exit 1 fi echo "$0 start \"${2}\""|at $3 $5 echo "$0 stop"|at $4 $5 atq exit 0 ;; listen|watch) if ! grep "^$2:" $HOME/.tzap/channels.conf >/dev/null ; then echo "Could not find channel $2" exit 1 fi # Kill any current users of the frontend $0 stop #just call ourself recursively #check console or X and set sound accordingly if [ "$TERM" = "LINUX" ] || [ "$TERM" = "linux" ] ; then MPLAYERARGS="$MPLAYERARGS $MPLAYERCONSOLEARGS" else MPLAYERARGS="$MPLAYERARGS $MPLAYERXARGS" fi #FIXME--- hack - mplayer doesn't tune quite right... $TZAP -t 1 "${2}" case $0 in *dvbtvrecord) $MPLAYER $MPLAYERARGS -cache 4096 dvb://"${2}" ;; *dvbradiorecord) $MPLAYER $MPLAYERARGS -cache 256 -novideo dvb://"${2}" ;; esac ;; start) # check channel if ! grep "^$2:" $HOME/.tzap/channels.conf > /dev/null 2>&1; then echo "Could not find channel $2" exit 1 fi # Kill any current users of the frontend $0 stop #just call ourself recursively case "$0" in *dvbtvrecord) ############### TV ################## #tzap -r "${2}" >/dev/null & #cat /dev/dvb/adapter0/dvr0 >"${FILENAME}.mpg"& #records the whole ts # new tzap - it's still easier to use `at` than -t (timeout): $TZAP -S -o "${FILENAME}.mpg" "${2}" & ##################################################################### ;; *dvbradiorecord) ########### RADIO ################ # ATM still easier to do this than arse about with tzap -o APID=$(grep "^$2" .tzap/channels.conf|awk ' BEGIN { FS=":" } { print $12 }') $TZAP -S -r "${2}" & $TS2ES /dev/dvb/adapter0/dvr0 $APID >"${FILENAME}.mp2"& ##################################################################### ;; esac ;; stop) # this is a bit of a hack, but I've only got one dvb, so it should work fuser -k /dev/dvb/adapter0/* ;; *) echo "$0 start channel|stop|listen channel|timer channel start stop [day]" ;; esac