html/mpg123.pl
1 # Display current mpg123 track to channel
2 # you should run mpg123 as,
3 # mpg123 --verbose file1 file2 2> ~/.irssi/scripts/mpg123.log
4 # or just put this on a file
5
6 # #--- mpg123a file ---#
7 # #!/bin/sh
8 # mpg123 --verbose * 2> ~/.irssi/scripts/mpg123.log
9
10 # save it as mpg123a and make it executable
11 # chmod a+x mpg123a
12 #
13 # execute it on the directory you have your mp3 files
14 # ./mpg123a
15
16
17 #
18 # HOWTO use "mpg123 script" from Irssi:
19 # /mpg123 [#channel] [-h|--help]
20 #
21 # This script works with no problems on mpg123 Version 0.59r
22 # bugs: if u call it from the "status" window, it ill crash the script, since you arent currently on a channel.
23 # It ill crash the script not the Irssi program, so u shall re-run it.
24
25
26 use Irssi;
27 use Irssi::Irc;
28 use strict;
29 use vars qw($VERSION %IRSSI);
30
31 $VERSION = "0.01+1";
32 %IRSSI = (
33 authors => 'Ricardo Mesquita',
34 contact => 'ricardomesquita@netcabo.pt',
35 name => 'mpg123',
36 description => 'Display current mpg123 track',
37 url => 'http://pwp.netcabo.pt/ricardomesquita/irssi',
38 license => 'GPLv2',
39 changed => 'Mon Nov 27 18:00:00 CET 2006'
40 );
41
42 my $mpg123file = glob "~/.irssi/scripts/mpg123.log";
43
44
45 sub cmd_mpg123 {
46 my ($data, $server, $witem) = @_;
47 my ($mpg123msg, $mpg123linha, $channel);
48
49 my $showhelp="mpg123 irssi script version $VERSION\n/mpg123 [#channel] [-h|--help]";
50
51 if ($data=~/-h|--help/) {
52 Irssi::print($showhelp);
53 return
54 } else {
55 if ($data=~ /#./) {
56 $channel = $data;
57 } else {
58 if ($witem->{name} ne "") {
59 $channel = $witem->{name};
60 }
61 }
62
63 open (f, $mpg123file) || return;
64
65 while ($mpg123linha=<f>) {
66
67 chomp($mpg123linha);
68 if ($mpg123linha=~/playing/i) {
69 $mpg123linha =~s/(.*)stream from\s(.*)\.(.*)\s(.*)/\2\.\3/;
70 $mpg123msg="on MPG123 playing $mpg123linha";
71 }
72
73 chomp($mpg123linha);
74 if ($mpg123linha =~/time:\s/i) {
75 $mpg123linha=~s/[\s]frame#.*,\s(.*),/\1/i;
76 $mpg123linha=~s/time:\s(\d\d).(\d\d).(\d\d)..(\d\d).(\d\d).(\d\d)./\[\1:\2.\3\]/i;
77 $mpg123msg.=" $mpg123linha";
78 }
79 }
80 close(f);
81 $mpg123msg =~ s/[\r\n]/ /g;
82 $server->command("action ". $channel . " $mpg123msg");
83 }
84 }
85
86 Irssi::command_bind('mpg123', 'cmd_mpg123');