html/ogg123.pl


   1 # Display current ogg123 track to channel
   2 # you should run ogg123 as,
   3 # ogg123 --verbose file1 file2 2> ~/.irssi/scripts/ogg123.log
   4 # or just put this on a file 
   5 
   6 #   #--- ogg123a file ---#
   7 #   #!/bin/sh
   8 #   ogg123 --verbose * 2> ~/.irssi/scripts/ogg123.log
   9 
  10 # save it as ogg123a and make it executable
  11 # chmod a+x ogg123a
  12 #
  13 # execute it on the directory you have your .ogg files
  14 # ./ogg123a
  15 
  16 
  17 #
  18 # HOWTO use "ogg123 script" from Irssi:
  19 # /ogg123 [#channel] [-h|--help]
  20 #
  21 # bugs: if u call it from the "status" window, it ill crash the script, since you arent currently on a channel. 
  22 # It ill crash the script not the Irssi program, so u shall re-run it.
  23 #
  24 # **** note ****
  25 # Yeah i now that this is a copy of mpg123.pl script ;D
  26 # to be true it was just a question of doing %s/mpg/ogg/gi and small changes on the regexp, 
  27 # but its workable, the mpg123 author doenst complain, so who really cares?!  =:)  
  28 # isnt what all ppl is doing since recent events moving all... mv *.mp3 *.ogg
  29 
  30 use Irssi;
  31 use Irssi::Irc;
  32 use strict;
  33 use vars qw($VERSION %IRSSI);
  34 
  35 $VERSION = "0.01+1";
  36 %IRSSI = (
  37     authors     => 'Ricardo Mesquita',
  38     contact	=> 'ricardomesquita@netcabo.pt',
  39     name        => 'ogg123',
  40     description => 'Display current ogg123 track',
  41     url		=> 'http://pwp.netcabo.pt/ricardomesquita/irssi',
  42     license     => 'GPLv2',
  43     changed	=> 'Mon Nov 27 18:00:00 CET 2006'
  44 );
  45 
  46 my $ogg123file = glob "~/.irssi/scripts/ogg123.log";
  47 
  48 
  49 sub cmd_ogg123 {
  50 	my ($data, $server, $witem) = @_;
  51 	my ($ogg123msg, $ogg123linha, $channel);
  52 
  53 	my $showhelp="ogg123 irssi script version $VERSION\n/ogg123 [#channel] [-h|--help]";
  54 	
  55 	if ($data=~/-h|--help/) {
  56 		Irssi::print($showhelp);
  57 		return
  58 	} else {		
  59 		if ($data=~ /#./) {
  60 			$channel = $data;
  61 		} else {
  62 			if ($witem->{name} ne "") {
  63 				$channel = $witem->{name};	
  64 			}
  65 		}
  66 		
  67 		open (f, $ogg123file) || return;
  68 
  69 		while ($ogg123linha=<f>) {		
  70 			
  71 			chomp($ogg123linha);
  72 			if ($ogg123linha=~/Playing:/i) {
  73 				$ogg123linha =~s/(.*)Playing:\s(.*)/\2/;
  74 				$ogg123msg="on ogg123 playing $ogg123linha";
  75 			}
  76 
  77 			chomp($ogg123linha);
  78 			if ($ogg123linha =~/Title:/i) {
  79 				$ogg123linha =~s/(.*)Title:\s(.*)/\2/;
  80 				$ogg123msg="on ogg123 playing $ogg123linha";
  81 			}
  82 
  83 			chomp($ogg123linha);
  84 			if ($ogg123linha =~/Artist:/i) {
  85 				$ogg123linha =~s/(.*)Artist:\s(.*)/\2/;
  86 				$ogg123msg.=" - $ogg123linha";
  87 			}
  88 		}
  89 		close(f);
  90 		$ogg123msg =~ s/[\r\n]/ /g;
  91 		$server->command("action ".  $channel . " $ogg123msg");
  92 	}	
  93 }
  94 
  95 Irssi::command_bind('ogg123', 'cmd_ogg123');