I wrote the following scripts to help me control my HDHomeRun during my “I don't have an HTPC yet” phase. I got my inspiration from Many and Rusty over at nerdlogger.com.

Channel Scan

First, I needed to grab a listing of all the available channels using the scan function of the hdhomerun_config program. I spit it out to a file named scanoutput.

$ hdhomerun_config FFFFFFFF scan /tuner0 | grep -B 2 PROGRAM > scanoutput

Then, I used the following code to spit out a channel guide lookup table, with the channel number, name, and HDHomeRun specific program information. Example usage

$ cat scannoutput | ./parseoutput.pl > channels
#!/usr/bin/perl
 
while(<>) {
  if($_ =~ m/--/) {
    $channel = "";
    $program = "";
    $name = "";
  }
  if($_ =~ m/SCANNING: [0-9]+ \(.*us-(bcast|irc):([0-9]+)/) {
    $channel = $2;
  }
  if($_ =~ m/PROGRAM ([0-9]+): ([^\s]+) ([^\s]+)/) {
    $program = $1;
    $number = $2;
    $name = $3;
  }
  if($program != "") {
    print $number."\t".$name."\t".$channel."\t".$program."\n";
  }
}

Channel Set

With my nice channel lookup table, I use the following script to easily tune into whatever channel I want. Example usage:

$ ./setchannel.pl 2.2
#!/usr/bin/perl
 
$user = $ARGV[0];
 
if($user =~ m/\./) {} else {
	$user = $user.".1";
}
 
$chanstr = "gawk '{if(\$1 == \"$user\"){print \$3}}' channels";
$chan=`$chanstr`;
chomp($chan);
 
$progstr = "gawk '{if(\$1 == \"$user\"){print \$4}}' channels";
$prog=`$progstr`;
chomp($prog);
 
$result = `hdhomerun_config FFFFFFFF set /tuner0/channel 8vsb:$chan`;
$result = `hdhomerun_config FFFFFFFF set /tuner0/program $prog`;
$result = `hdhomerun_config FFFFFFFF set /tuner0/target 192.168.1.101:1234`;
sleep 1;
$result = `hdhomerun_config FFFFFFFF get /tuner0/status`;
print $result;

Be sure to adjust ip:port accordingly.

hdhomerun_scripts.txt · Last modified: 2008/08/31 01:03 UTC by dustin