[mythtv-users] The Telnet interface and Perl
Jerome Yuzyk
jerome at supernet.ab.ca
Tue Sep 2 16:27:33 UTC 2008
Reading the "Web-based remote control thread" got me wondering about using the
Telnet interface for controlling my own set-up. I don't need web access, just
some remote method I can use through my main workstation. This script may be
informative or demonstrative for others interested in their own interface. To
give it a bit of a (cheap) GUI I made a little tree of KDE KMenu entries to
run the script with the most-common functions I use. It's pretty simple Perl,
but requires the Net::Telnet module. Maybe you will see something you can
use. This could be modifieded to create a web interface with Perl's CGI
module, which I might do when I have "tinker time" next.
------------------------------------------------------------------------------
#!/usr/bin/perl
my $host = 'tv'; # Modify for your Host and Port
my $port = '6546';
my %P = (
# Skip
#
'sa' => [ 'key right', 'skip ahead 30s'],
'sb' => [ 'key left', 'skip back 5s' ],
'sc' => [ 'key end', 'skip Commercial'],
'scb' => [ 'key home', 'skip Commercial back'],
# Jump
#
'ja' => [ 'key pagedown', 'jump ahead 10m'],
'jb' => [ 'key pageup', 'jump back 10m' ],
'esc' => [ 'key escape', 'Escape' ],
'del' => [ 'Delete', 'delete program'],
'p' => [ 'key p', 'Pause/Unpause' ],
'i' => [ 'key i', 'Information' ],
# Jump Points
#
'slide' => [ 'Slideshow', 'Slide show' ],
'play' => [ 'jump playbackrecordings', 'Playback recordings' ],
# Volume
#
'mute' => [ 'key f9', 'Mute/Unmute' ],
'vd' => [ 'key f10', 'Volume Down' ],
'vu' => [ 'key f11', 'Volume Up' ],
);
unless ( @ARGV ) { &Menu; exit 0; }
my $function = lc $ARGV[0];
unless ( defined $P{$function} ) { &Menu; exit 0; }
my $repeatable = 'sa|sb|ja|jb|i|vu|vd';
my $repeats = $ARGV[1] || 1;
use Net::Telnet;
my $telnet = new Net::Telnet (
Timeout =>10, Errmode =>'die',
Host => $host, Port => $port,
);
$telnet->open;
# Special keys that require multiple steps.
#
# Delete
#
if ( $function eq 'del' ) {
$telnet->print('key d');
sleep 1;
$telnet->print('key up');
sleep 1;
$telnet->print('key enter');
}
# Random Slideshow
#
elsif ( $function eq 'slide' ) {
$telnet->print( 'jump mythgallery' );
$ok = $telnet->waitfor( /OK/ );
$telnet->print( 'key m' );
$ok = $telnet->waitfor( /OK/ );
$telnet->print( 'key down' );
$ok = $telnet->waitfor( /OK/ );
$telnet->print( 'key enter' );
$ok = $telnet->waitfor( /OK/ );
}
# Operations that can be repeated
#
elsif ( $function =~ /$repeatable/ ) {
my $operation = $P{$function}->[0];
for ( 1..$repeats ) {
$telnet->print( $operation );
$ok = $telnet->waitfor( /OK/ );
}
}
else {
$telnet->print( $P{$function}->[0] );
}
$telnet->close;
# All Done!
sub Menu
{
print "\n";
print " remote function [repeat]\n";
print "\n";
foreach my $k ( sort keys %P ) {
print sprintf( " %-5s%-20s %s\n", $k, $P{$k}->[0], $P{$k}->[1] );
}
print "\n";
}
------------------------------------------------------------------------------
More information about the mythtv-users
mailing list