Tuesday, June 16, 2009

ZephIR & EyeTV

Comcast recently switched the majority of their analog cable over to digital, forcing me to get a little digital converter box to sit between the cable and my EyeTV. It also killed my ability to change channel thru EyeTV (I have the first gen of the 250+, which doesn't have built in QCAM) so I bought a ZephIR.

It works pretty well, but when quickly flipping through channels, it just doesn't keep up. Often I'd land on a channel (say 42) but since I'd been using just the up/down buttons, it would stop somewhere between (like 55).

So I wrote a little perl script to fix the problem.

In order for it to work you have to make sure that the components are named DIFFERENTLY in EyeTV and ZephIR. (Severing the connection between them.)

Here's the code:

#!/usr/bin/perl

# Declare the subroutines
sub trim($);
sub currentChannel();
sub blast($);
sub blastUp();
sub blastDown();

# Declare channel variable
my $curChan;

$curChan = currentChannel();

while(1) {
my $chanNow = currentChannel();
if(!($curChan == $chanNow))
{
$diff = $chanNow-$curChan;
if($diff==1) { blastUp(); }
elsif($diff==-1) { blastDown(); }
else {
blast($chanNow);
}
$curChan = $chanNow;
}
}

sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

sub currentChannel()
{
$result = `osascript -e 'tell application "EyeTV" to get current channel'`;
return trim($result);
}

sub blast($)
{
my $in = shift;
my $command = "tell application \"ZephIR\" \n";
foreach (split(//, $in)) {
$command .= "fire zephir command \"$_\" of component \"ComcastDTA_\"\n";
}
$command .= "fire zephir command \"enter\" of component \"ComcastDTA_\"\n";
$command .= "end tell\n";
system("osascript -e '$command'");
}

sub blastUp()
{
system("osascript -e 'tell application \"ZephIR\" to fire zephir command \"Channel_Up\" of component \"ComcastDTA_\"'");
}

sub blastDown()
{
system("osascript -e 'tell application \"ZephIR\" to fire zephir command \"Channel_Down\" of component \"ComcastDTA_\"'");
}

1 comment:

lindsay said...

seriously?

your genius never fails to impress me...

word verification:
hyminsr