After many moons of being annoyed by mp3 ‘now playing’ scripts in channels I sit in on IRC, and many more attempts at trying to ignore them… I’ve decided to join them in their persuite of driving other chatters up the wall
Changelog
Version 0.0.1 – Initial release
Commands
/amarok | Root command |
/amarok help | Provides help on the /amarok commands |
/amarok np | Performs the ‘now playing’ command |
Requirements
DCOP::Amarok::Player
You can install this by using cpan
# cpan
install DCOP
install DCOP::Amarok
force install DCOP::Amarok::Player
You need to force install the last bit because root should not have access to your variables.
Yeh ok, so there’s not a stack in it now in the way of commands but I have a multi-media keyboard so it’s quicker to press a button then type a command into xchat (c:
If ya’ll want more commands you better ask for them.
#!/usr/bin/perl
use DCOP::Amarok::Player;
Xchat::register('amaroK','0.0.1','Perl based X-Chat interface to amaroK');
# We only hook one /command, then run all our sub commands off that
# It's just cleaner this way
Xchat::hook_command('amarok',\&amarok_root,{help_text => 'amaroK command root, type /amarok help for more information'});
# We define our commands here
my %cmds = (
'help' => {
desc => 'Display help',
hook => \&help
},
'np' => {
desc => 'Performs the now playing action on the current window',
hook => \&now_playing
}
);
# The root sub, this is our router
sub amarok_root {
my $cmd = lc($_[0][1]);
if (exists($cmds{$cmd})) {
use Data::Dumper;
return &{$cmds{$cmd}{hook}}($_);
} else {
Xchat::print("Huh?");
}
}
# Help target, list commands with their help message
sub help {
Xchat::printf('%-8s - %s','Command','Help');
foreach my $key (keys(%cmds)) {
Xchat::printf('%-8s - %s',$key,$cmds{$key}{desc});
}
}
# Now playing target - Well guess what this does
sub now_playing {
my $player = DCOP::Amarok::Player->new();
my %info = ();
foreach my $var (qw(album artist title status track totalTime currentTime isPlaying sampleRate bitrate status)) {
$info{$var} = $player->$var();
}
$info{sampleRate} = int ($info{sampleRate}/1000);
if ($info{title} =~ /^(.+)\ \/\ (.+)$/) {
$info{title} = $2;
$info{artist} = $1;
}
my $command = 'action ';
if ($info{status} >= 1) {
if ($info{status} == 1) {
$command .= 'has paused while playing: [%title%] by [%artist%] ';
} else {
$command .= 'is now playing: [%title%] by [%artist%] ';
}
if ($info{album}) {
$command .= 'from [%album%] ';
}
$command .= '[%currentTime%/%totalTime%]-';
$command .= '[%bitrate%kbps]-';
$command .= '[%sampleRate%Khz]';
} else {
$command .= 'isn\'t playing anything...';
}
$command =~ s/%([^%]+)%/$info{$1}/gie;
Xchat::command($command);
Xchat::EAT_ALL;
}