All pastes #97297 Raw Edit

talim

public text v1 · immutable
#97297 ·published 2006-07-23 15:16 UTC
rendered paste body
#!/usr/bin/perl

Xchat::register("AmaroK announcment.", "0.2", "", "");
Xchat::hook_command("np", "now_playing");
my $col_1 = chr(3)."08";
my $col_2 = chr(3)."09";

sub amarok { chomp(my $dcop = `dcop amarok player @_`); return $dcop; }

sub now_playing {
    if (amarok("isPlaying") eq "true") { 
	my ($i, @echo);
        for ($i = 1; $i <= 4; $i++) { 
	    push @echo, echo_part($i);
	}
	Xchat::command("say ".join($col_1." - ".chr(3), @echo));
    }
    else { 
	Xchat::print("amaroK doesn't seem to be playing.\n");
      }
}

sub echo_part { 
    my $str;
    if ($_[0] == 1) { 
        $str = "Now Playing: ".amarok("artist"); 
    }
    elsif ($_[0] == 2) { 
        $str = amarok("album"); 
    }
    elsif ($_[0] == 3) { 
        $str = amarok("title"); 
    }
    else { 
      my $i = amarok("trackTotalTime");
	my ($m, $s) = (
		       zero(($i / 60)%60), zero($i%60)
		       );
	return pbar().$col_1." - [".$col_2.$m.$col_1.":"
	    .$col_2.$s.$col_1."-".$col_2
	    .amarok("bitrate")." kbps".$col_1."]"; } 
    return str_col($str);
}


sub str_col { 
    my @str = split(/ /, "@_");
    my $i = 0;
    foreach $a (@str) { 
	$str[$i] = $col_1.substr($a, 0, 1)
	    .$col_2.substr($a, 1, (length($a) - 1));
	$i++; 
    }
    return join(" ", @str);
}

sub zero { 
    my $i = $_[0];
    if ($i < 10) {
	$i = "0".$i;
	}
    return $i;
}

sub pbar {
    my $i = int((amarok("trackCurrentTime") / amarok("trackTotalTime")) * 15);
    return chr(3)."08,08"."|" x $i.chr(3)."09,09"."|" x (15 - $i).chr(3);
}