PVR-250(350?) Recorder Script

Quick and dirty script to record shows via hauppauge PVR-250.
Useful when using freevo since I cannot get mencoder nor ffmpeg
to work well enough. 



#!/usr/local/bin/bash

# $1 filename
# $2 channel
# $3 runtime

LOGFILE="/mnt/raid/av/video/record/record.log"
RUNTIME=$3
CHANNEL=$2
FILENAME=$1
DATE=`date +"%Y-%m-%d %H:%M:%S"`
LOCKFILE="/mnt/raid/av/video/record/record.lck"

# the theory of the lock file is that given back to back recordings it
# it is possible to have the second program to start before the first
# program has completed. Since the app should exit shortly we just
# wait until the lockfile is removed and then continue with the record.
# yet there might be a case where the initial kill didnt work properly
# but lets not code that quite yet.

# we also have a potential issue that during the time the 2nd recording
# is sleeping. When it is able to record it will record the full runtime
# but we really need the runtime to be reduced by the amount of time spent
# in the sleep. 

if [ -f $LOCKFILE ]; then
 echo "$DATE :: ERROR recording $1 :: LOCKFILE found, sleeping" >> $LOGFILE
while [ -f $LOCKFILE ]
do
 sleep 1
 RUNTIME=$(( $RUNTIME - 1 ))
done
fi

echo " " >> ${LOGFILE}
echo " " >> ${LOGFILE}
echo "$DATE :: setting size to 720 480" >> ${LOGFILE}
/usr/local/bin/pvr250-setsize 720 480 > /dev/null

echo "$DATE :: setting channel to $2" >> ${LOGFILE}
/usr/local/bin/pvr250-setchannel $2 > /dev/null

echo "$DATE :: runtime is $RUNTIME seconds" >> ${LOGFILE}
echo "$DATE :: begin recording of $1" >> ${LOGFILE}

# create a file we use to track recording status
touch $LOCKFILE
echo "$DATE :: $1" >> $LOCKFILE

/usr/local/bin/buffer < /dev/cxm0 > $1 &

# /bin/cat /dev/cxm0 > $1 &

while [ "$RUNTIME" -gt "0" ]
do
sleep 1
RUNTIME=`expr $RUNTIME - 1`
done

# we are done recording so lets clean up

# write to logfile
echo "$DATE :: recording of $1 done" >> ${LOGFILE}

# kill all processes
/usr/bin/killall buffer

# write to logfile 
echo "$DATE :: stop record called for $1" >> ${LOGFILE}

# remove lockfile
/bin/rm $LOCKFILE
# send notification
echo "$DATE :: finished recording of $1" | \
/usr/bin/mail -s "show recorded" YOU@YOURHOST

echo "$DATE :: mail sent and we are done." >> ${LOGFILE}

exit




Copyright © 2003,2004 - Steven St.Laurent - steven@403forbidden.net