Skip to content

Instantly share code, notes, and snippets.

@relrod
Created November 15, 2009 03:39
Show Gist options
  • Save relrod/234960 to your computer and use it in GitHub Desktop.
Save relrod/234960 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Audio::MPD;
weechat::register("nowplaying", "Ricky Elrod", "0.1", "BSD", "NowPlaying Script.", "", "");
weechat::hook_command("np", "Display your currently playing MPD song, if any.", "", "", "", "np", "");
my $mpd = Audio::MPD->new();
sub np {
my ($data, $buffer, $param) = @_;
my $act;
my $state = $mpd->status()->{'state'};
$state = 'stopp' if $state eq 'stop';
my $percent = $mpd->status()->{'time'}->{'time'};
my @psplit = split(/:/,$percent);
my $current = int($psplit[0]);
my $full = int($psplit[1]);
$percent = int(($current/$full)*100);
if($state eq "play"){
$act = "is listening to: ".$mpd->current()->{'artist'}." - ".$mpd->current()->{'title'}." [$percent%]";
} else {
$act = "is not listening to anything. (MPD Status: ".$state."ed)";
}
weechat::command($buffer, "/me $act");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment