#!/usr/bin/perl
#amadcop.pl 1.5 by Bultom ( bultom@gmail.com / bultom (at) gmail (dot) com )
#Licence : GPL 2.0 and next
#Usage : next prev play pause stop volup voldown curplay
#This is a simple script to controle Amarok player by Xchat and DCOP :
#
#
# ( Play / Pause / Next / Previous / Stop / Volume(up/down) )


use strict;

Xchat::register("amadcop","1.5","Amarok xchat info (bultom)");
IRC::print("Amadcop 1.5 for XChat \cB\cC3loaded\cC0 :)");
IRC::add_command_handler("play", "cmd_amaplay");
IRC::add_command_handler("pause", "cmd_amapause");
IRC::add_command_handler("stop", "cmd_amastop");
IRC::add_command_handler("next", "cmd_amanext");
IRC::add_command_handler("prev", "cmd_amaprev");
IRC::add_command_handler("volup", "cmd_amavolup");
IRC::add_command_handler("voldown", "cmd_amavoldown");
IRC::add_command_handler("curplay", "cmd_amacurplay");
my $dcopbin = "dcop";

sub cmd_amaplay {
        my $amaplay;
	$amaplay = `$dcopbin amarok player play`;
Xchat::EAT_XCHAT;
}


sub cmd_amapause {
        my $amapause;
        $amapause = `$dcopbin amarok player pause`;
Xchat::EAT_XCHAT;
}

sub cmd_amastop {
        my $amastop;
        $amastop = `$dcopbin amarok player stop`;
Xchat::EAT_XCHAT;
}


sub cmd_amanext {
	my $amanext; 
	$amanext = `$dcopbin amarok player next`;
Xchat::EAT_XCHAT;
}

sub cmd_amaprev {
        my $amaprev;
        $amaprev = `$dcopbin amarok player prev`;
Xchat::EAT_XCHAT;
}

sub cmd_amavolup {
        my $amavolup;
        $amavolup = `$dcopbin amarok player volumeUp`;
Xchat::EAT_XCHAT;
}

sub cmd_amavoldown {
        my $amavoldown;
        $amavoldown = `$dcopbin amarok player volumeDown`;
Xchat::EAT_XCHAT;
}

sub cmd_amacurplay {
        my $title;
        my $curtime;
        my $totaltime;
        my $bitrate;
        my $type;
        my $rate;
        my $volume;
        my $engine;
        $title = `$dcopbin amarok player nowPlaying`;
        $curtime = `$dcopbin amarok player currentTime`;
        $totaltime = `$dcopbin amarok player totalTime`; 
        $bitrate = `$dcopbin amarok player bitrate`;
        $type = `$dcopbin amarok player type`;
        $rate = `$dcopbin amarok player sampleRate`;
        $volume = `$dcopbin amarok player getVolume`;
        $engine = `$dcopbin amarok player engine`;
        chomp($title);
        chomp($curtime);
        chomp($totaltime);
        chomp($bitrate);
        chomp($type);
        chomp($rate);
        chomp($volume);
        chomp($engine);
        IRC::command("/me play on Amarok: $title [$type] [$curtime/$totaltime] [$bitrate/$rate Hz] [volume:$volume%] [$engine rendering]");
} 