#!/usr/bin/perl -w
# use your shortcut under gnome or any other Windows manager
# usefull to send command using the DAC telco or other IR remote command
# be sure to remove "blanck screen" or "lock screen"

use strict;
use Net::Telnet;

my $ID="8d%3Acb%3A08%3A49%3A4b%3A0e";
my $IP="localhost";
my $PORT="9090";

sub usage() {
    print "
First arg must be:
- next
- pause
- previous
- volumeup
- volumedown
";
    exit 0;
}

if ($ARGV[0] eq "") { usage; }

my @cmd;
if ($ARGV[0] eq "next") {
    @cmd =  ("playlist index +1");
} elsif ($ARGV[0] eq "previous") {
    @cmd = ("playlist index -1");
} elsif ($ARGV[0] eq "pause") {
    @cmd = ("pause");
} elsif ($ARGV[0] eq "volumeup") {
    @cmd = ("mixer volume +2");
} elsif ($ARGV[0] eq "volumedown") {
    @cmd = ( "mixer volume -2", );
}

sub do_cmd {
    my ($cmd) = @_;	
    my @out;
    my $telnet=new Net::Telnet(
	Timeout=>"0",
	Host=>$IP,
	Port=>$PORT,
	Errmode=>'return',
	Prompt => '/\QSQUEEZE\E#\s?$/'   
	);
    $telnet->open($IP);
    if ($telnet->errmsg){
	print "Can't connect to " . $_ . " Error: " . $telnet->errmsg . "\n";
    } else {
        @out = $telnet->cmd($cmd);
        $telnet->close;
    }
}

foreach my $cmd (@cmd) {
    print "Command = $cmd\n";
    do_cmd($cmd);
}
