use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
$VERSION = '1.2';
%IRSSI = (
authors => 'Aurimas',
contact => 'aurimas.d\@gmail.com',
name => 'Now Playing Script',
description => 'Returns infopipe data to active window',
license => 'Public Domain',
url => 'http://freakcore.net',
changed => 'Sun May 8 03:02:17 EEST 2005',
commands => '/np',
note => 'Make sure InfoPipe is configured!',
);
Irssi::settings_add_str( 'np', 'np_output', 'np: %title [%pos/%length]' );
Irssi::settings_add_str( 'np', 'np_pipe', '/tmp/xmms-info' );
sub cmd_np {
my ( $args, $server, $target ) = @_;
$args =~ s/\s+$//;
my $pipe = Irssi::settings_get_str('np_pipe');
if ( $pipe =~ m/%name/ ) {
my $name = getpwuid($<);
$pipe =~ s/%name/$name/g;
}
unless ( open( BMP, "$pipe" ) ) {
Irssi::print "Error occured. Check if media player is running and your";
Irssi::print "InfoPipe module is running properly";
Irssi::print "And np_pipe set to correct file";
}
else {
my %bmp;
while (<BMP>) {
chomp;
my ( $key, $value ) = split /: /, $_, 2;
$bmp{$key} = $value;
}
close BMP;
my %fs;
$fs{'status'} = $bmp{'Status'};
$fs{'title'} = $bmp{'Title'};
$fs{'file'} = $bmp{'File'};
$fs{'length'} = $bmp{'Time'};
$fs{'pos'} = $bmp{'Position'};
$fs{'bitrate'} = $bmp{'Current bitrate'};
$fs{'freq'} = $bmp{'Samping Frequency'};
$fs{'channels'} = $bmp{'Channels'};
$fs{'pl_total'} = $bmp{'Tunes in playlist'};
$fs{'pl_current'} = $bmp{'Currently playing'};
if ( $bmp{'uSecTime'} > 0 ) {
$fs{'pctdone'} = sprintf( "%.1f%%%%",
( $bmp{'uSecPosition'} / $bmp{'uSecTime'} ) * 100 );
}
else {
$fs{'pctdone'} = "0.0%%";
}
$fs{'length'} =~ s/^([0-9]*):([0-9]{2})$/\1m\2s/g;
$fs{'pos'} =~ s/^([0-9]*):([0-9]{2})$/\1m\2s/g;
$fs{'bitrate'} =~ s/000$//g;
my $output = Irssi::settings_get_str('np_output');
foreach ( keys %fs ) {
$output =~ s/\%$_/$fs{$_}/g;
}
if ( !$server || !$server->{connected} ) {
Irssi::print $output;
return;
}
if ($args) { $server->command("msg $args $output"); }
else { Irssi::active_win()->command( 'say ' . $output ); }
}
}
Irssi::command_bind( 'np', 'cmd_np' );
|