IPv4 Fremnet Logo
TOOLS, TINKERINGS & CODE

If it helps

amarok.pl - amaroK script for X-Chat · Sept 22, 21:21 by Shannon Wynter

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.

  1. #!/usr/bin/perl
  2. use DCOP::Amarok::Player;
  3.  
  4. Xchat::register('amaroK','0.0.1','Perl based X-Chat interface to amaroK');
  5.  
  6. # We only hook one /command, then run all our sub commands off that
  7. # It's just cleaner this way
  8. Xchat::hook_command('amarok',\&amarok_root,{help_text => 'amaroK command root, type /amarok help for more information'});
  9.  
  10. # We define our commands here
  11. my %cmds = (
  12. 'help' => {
  13.   desc => 'Display help',
  14.   hook => \&help
  15. },
  16. 'np' => {
  17.   desc => 'Performs the now playing action on the current window',
  18.   hook => \&now_playing
  19. }
  20. );
  21.  
  22. # The root sub, this is our router
  23. sub amarok_root {
  24. my $cmd = lc($_[0][1]);
  25.  
  26. if (exists($cmds{$cmd})) {
  27.   use Data::Dumper;
  28.   return &{$cmds{$cmd}{hook}}($_);
  29. } else {
  30.   Xchat::print("Huh?");
  31. }
  32. }
  33.  
  34. # Help target, list commands with their help message
  35. sub help {
  36. Xchat::printf('%-8s - %s','Command','Help');
  37. foreach my $key (keys(%cmds)) {
  38.   Xchat::printf('%-8s - %s',$key,$cmds{$key}{desc});
  39. }
  40. }
  41.  
  42. # Now playing target - Well guess what this does
  43. sub now_playing {
  44. my $player = DCOP::Amarok::Player->new();
  45.  
  46. my %info = ();
  47. foreach my $var (qw(album artist title status track totalTime currentTime isPlaying sampleRate bitrate status)) {
  48.   $info{$var} = $player->$var();
  49. }
  50. $info{sampleRate} = int ($info{sampleRate}/1000);
  51. if ($info{title} =~ /^(.+)\ \/\ (.+)$/) {
  52.   $info{title} = $2;
  53.   $info{artist} = $1;
  54. }
  55.   
  56. my $command = 'action ';
  57. if ($info{status} >= 1) {
  58.   if ($info{status} == 1) {
  59.   $command .= 'has paused while playing: [%title%] by [%artist%] ';
  60.   } else {
  61.   $command .= 'is now playing: [%title%] by [%artist%] ';
  62.   }
  63.   if ($info{album}) {
  64.   $command .= 'from [%album%] ';
  65.   }
  66.   $command .= '[%currentTime%/%totalTime%]-';
  67.   $command .= '[%bitrate%kbps]-';
  68.   $command .= '[%sampleRate%Khz]';
  69. } else {
  70.   $command .= 'isn\'t playing anything...';
  71. }
  72.  
  73. $command =~ s/%([^%]+)%/$info{$1}/gie;
  74.  
  75. Xchat::command($command);
  76. Xchat::EAT_ALL;
  77. }
  78.  
  79. Download this code: amarok.pl (Downloaded 341 time(s))
Comments

Spam no more - rel=nofollow is active here, spamming my comments will not help your page rank.

  Textile help
---== Copyright Shannon Wynter - All rights reserved - All wrongs avenged ==---