html/xmms2.pl
1 # XMMS/InfoPipe script for the Irssi client. You need a few things
2 # installed before this script will work...
3 # 1) Irssi, http://irssi.org/
4 # 2) XMMS, http://www.xmms.org/
5 # 3) InfoPipe, http://www.beastwithin.org
6 # /users/wwwwolf/code/xmms/infopipe.html
7 #
8 # xmms2.pl is a version of xmms.pl slightly modified by Sir Robin,
9 # sir@robsku.cjb.net / http://robsku.cjb.net/
10 #
11 # The script now outputs by default to the active window, instead of
12 # status window. Also removed percentage meter as it didn't work. Only
13 # two lines were modified and the original lines still exist, just
14 # commented out.
15 #
16 # If you have trouble installing any of these, consult the READMEs that
17 # come with the software, thank you.
18 #
19 # Fixed a few vital things adviced by kodgehopper at netscape dot net.
20 # Very appreciated as I had no chance of testing a few of these things
21 # myself. I hope everything works as it should now.
22 #
23 # Visit http://scripts.irssi.de/
24 #
25 # simon at blueshell dot dk
26 use Irssi;
27 use vars qw($VERSION %IRSSI);
28 use strict;
29
30 $VERSION = '1.1.3+1';
31 %IRSSI = (
32 authors => 'simon',
33 contact => 'simon\@blueshell.dk',
34 name => 'XMMS-InfoPipe Script',
35 description => 'Returns XMMS-InfoPipe data',
36 license => 'Public Domain',
37 url => 'http://irssi.dk/',
38 changed => 'Mon Nov 27 18:00:00 CET 2006',
39 commands => '/np',
40 note => 'Make sure InfoPipe is configured!'
41 );
42
43 sub cmd_xmms {
44 my ($args, $server, $target) = @_;
45 $args =~ s/\s+$//; #fix unneeded whitespaces after output dest.
46
47 my (@t, $t, $ttotal, @pos, $pos, $postotal, $title);
48 open xmms, '/tmp/xmms-info' || die; # if nothing happens, it probably
49 # failed here!
50
51 while(<xmms>) {
52 if(/^Time: (.*)$/) {
53 @t = split(/:/, $1);
54 $t = $1;
55 $t =~ s/^([0-9]*):([0-9]{2})$/\1m\2s/; # convert to nice format
56 $ttotal = $t[0] + $t[1]*60;
57 }
58 if(/^Position: (.*)$/) {
59 @pos = split(/:/, $1);
60 $postotal = $pos[0] + $pos[1]*60;
61 }
62 if(/^Title: (.*)$/) { $title = $1; }
63 }
64 close xmms;
65
66 if(!$ttotal || !$postotal) {
67 Irssi::print "An error occurred. Check if XMMS is running and your";
68 Irssi::print "InfoPipe module is running properly. If not, read how";
69 Irssi::print "to get these up and running by reading the script source";
70 die;
71 }
72
73 $pos = sprintf("%.0f", $postotal / $ttotal * 100); # calc. position
74 # my $output = "np: $title ($pos% of $t)";
75 my $output = "np: $title ($t)";
76 $output =~ s/[\r\n]/ /g; # remove newline characters
77 if(!$server || !$server->{connected}) { # are we even connected?
78 Irssi::print $output;
79 return
80 }
81 if($args) { $server->command("msg $args $output"); }
82 else { Irssi::active_win()->command('say ' . $output); }
83 # else { Irssi::print $output; }
84 }
85
86 Irssi::command_bind('np', 'cmd_xmms');