#!/usr/bin/perl # This script controls my DirecTV Genie (hr44) STB. Just update the IP addess # below and you should be good to go. You can also turn off debug if you don't # want the script to write to a log file. You can get a list of mini's with the # get_clients argument. Set your genie's IP below and run "tune.pl get_clients" # to list the address if your clients. use strict; # List your STB's and IP addresses below. Use 'xxx.xxx.xxx.xxx|MacAddrOfClient' # for mini's. Feel free to comment out and tuners that you don't need. my %stbs = ( 'DirecTV-Tuner-1' => '192.168.2.243', 'DirecTV-Tuner-2' => '192.168.2.243|2C088C089B22', # 'DirecTV-Tuner-3' => '192.168.1.79', ); my $log = 'c:\TuneChannel\tune.log'; # Location of logfile. my $debug = 1; # Set to 1 to turn logging on. # Set to 0 to turn logging off. my $micro_send = 0; # Set to 1 to send one digit at a time # to the STB instead of the whole channel. # Set to 0 to send the whole channel number. my $command = $ARGV[0]; my $remote = $ARGV[1]; my $channel = $ARGV[2]; &logit( "Received COMMAND = $command | REMOTE = $remote | CHANNEL = $channel" ); &get_clients if ( $command eq "get_clients" ); &list_keys if ( $command eq "KEYS" ); &send_keys( $channel ) if ( $command eq "TUNE" ); &list_tuners if ( $command eq "REMOTES" ); print "OK\n" if ( $command eq "CAN_TUNE" ); sub list_tuners() { foreach my $tuner ( keys %stbs ) { print $tuner . "\n"; } } sub get_clients() { my ( $ip_addr, $client_addr ); foreach my $key ( keys %stbs ) { ( $ip_addr, $client_addr ) = split ( /\|/, $stbs{$key} ); if ( $client_addr eq '' ) { open ( CURL, "curl -s $ip_addr:8080/info/getLocations |" ); while () { my $output = $_; print $output; chomp $output; &logit( $output ); } close CURL; } } } sub list_keys() { my @keys = ( '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'OK' ); foreach ( @keys ) { print "$_\n"; } } sub send_keys() { my ( $ip_addr, $client_addr ); my $keys = shift; chomp $keys; &logit( "$keys" ); ( $ip_addr, $client_addr ) = split ( /\|/, $stbs{$remote} ); $client_addr = '&clientAddr=' . $client_addr if ( $client_addr ne '' ); open ( CURL, "curl -s $ip_addr:8080/remote/processKey?key=poweron$client_addr |" ); while () { my $output = $_; chomp $output; &logit( $output ); } if ( $micro_send ) { foreach my $char ( split //, $keys ) { if ( $char =~ /\d/ ) { open ( CURL, "curl -s $ip_addr:8080/remote/processKey?key=$char$client_addr |" ); while () { my $output = $_; chomp $output; &logit( $output ); } } } } else { open ( CURL, "curl -s $ip_addr:8080/tv/tune?major=$channel$client_addr |" ); while () { my $output = $_; chomp $output; &logit( $output ); } } } sub logit() { my $message = shift; my $timestamp = &getLoggingTime(); if ( $debug ) { open ( LOG, ">> $log" ); print LOG "[$timestamp]\t$message\n"; close LOG; } } sub getLoggingTime() { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); my $nice_timestamp = sprintf ( "%04d%02d%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec); return $nice_timestamp; }