#/bin/bash## Very very simple way of creating a channels.conf file that contains only# non-encrypted channels coming in over cable. The first lines of this file # (lines 23, 26, 29, and 32) need to be adjusted to run on each computer. You # will also need a ~/.azap folder. This script must be run directly from the # computer that contains the tuner. If you ssh into the computer and try to # run this script, the mplayer timings will be off and it will probably not # function correctly. This script takes a while to run and should be run # while the computer is not being used. This script will probably not function# if it finds more that 999 total channels (encrypted and non-encrypted) or # more than 99 non-encrypted channels. These limitations can be easily# fixed by someone who knows what they are doing. The end of the script # contains a section to automatically update the mysql database. What's # written seems to work for me however I don't know if it will work elsewhere # so uncomment at your own risk.## Script by Dylan R. Semler##Path to the dvb-apps scan subdirectorypathtoscan=/usr/bin#Path to the dvb-apps azap subdirectorypathtoazap=/usr/bin#Path to store temp filestempdir=/tmp#Path to DVB device:dvbdevice=/dev/dvb/adapter0/dvr0#Backup current channels.conf filemv ~/.azap/channels.conf ~/.azap/channels.conf.back >& /dev/null#run atscscan to generate channels.conf file in ~/.azap/$pathtoscan/dvbscan /usr/share/dvb/atsc/us-Cable-HRC-center-frequencies-QAM256 > ~/.azap/channels.conf#Replace the ugly-looking first entries of channels.conf with try###for (( i = 999 ; i >= 1 ; i-- )); do sed -i "$[i]s/^.*\]/try$i/" ~/.azap/channels.confdone#Get number of lines in channels.conftotal=`cat -n ~/.azap/channels.conf | awk '{ print $1 }' | tail -1`channum=0#Test channels for video footage:for (( i = 1 ; i <= $total ; i++ )); do mencoder dvb://try$1 -nosound -frames 10 -ovc lavc -o /tmp/try$1.avi & sleep 20 killall mencoder sleep 1 killall -9 mencode #Try to tune channel #$pathtoazap/azap -r try$i >& /dev/null & #azapid=$! #sleep 2 #Create 5 second long test video #cat $dvbdevice > $tempdir/test.mpg & #catid=$! #sleep 5 #kill $catid >& /dev/null #kill $azapid >& /dev/null #Time how long it takes mplayer to play the video. If it is less than #2.5 seconds, then the channel is assumed to be encrypted or a music #channel #echo | time -o $tempdir/time.dat mplayer $tempdir/test.mpg >& /dev/null #length=`sed -e 's/^.*system 0:0//' -e 's/elapsed.*$//' -e /outputs/d -e s/\\\.// $tempdir/time.dat` #Adjust channels.conf if no video was played #if [ $[10#$length] -lt 250 ]; then #sed -i /try$i:/d ~/.azap/channels.conf #length= #else #channum=$((channum+1)) #fidone#if [ $channum = 1 ]; then #echo "found $channum channel"#else #echo "found $channum channels"#fi#Re-number channels.conf file in order#for (( i = 999 ; i >= 1 ; i-- )); do #sed -i "$[i]s/try[0-9]\{1,3\}/try$i/" ~/.azap/channels.conf#done#Remove temp files#rm $tempdir/test.mpg#rm $tempdir/time.dat# Auto update mythtv's mysql database--not complete, but seems to work for me.#rm channelinput.sql#for (( i = $channum ; i >= 1 ; i-- )); do# echo $i# serviceid=`sed -n $[i]s/^.*://p ~/.azap/channels.conf`# frequency=`sed -n $[i]s/try[0-9]*\://p ~/.azap/channels.conf| sed s/\:QAM.*//`# mplexid=`grep $frequency mplexid.dat | awk '{ print $1 }'`# if [ $i -lt 10 ]; then# j=0$i# else# j=$i# fi# echo "INSERT INTO channel VALUES ('31$j','1$j','NULL','3','try$i','try$i','none','NULL','','','0','32768','32768','32768','32768','Default','0','1','','1','$mplexid','$serviceid','1');" >> channelinput.sql#done#echo flush privileges\; >> channelinput.sql#mysql -u root -p mythconverg < channelinput.sqlfind /tmp -name '*.avi' | sed 's/\.\///; s/\..*//' > ~/.azap/list.of.working.channelsecho "DONE!"