diff options
Diffstat (limited to 'mplength')
-rwxr-xr-x | mplength | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/mplength b/mplength new file mode 100755 index 0000000..621891b --- /dev/null +++ b/mplength @@ -0,0 +1,44 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Audio::MPD q{0.19.0}; + +=head1 NAME + +mplength - calculates length of mpd playlist + +=head1 SYNOPSIS + +mplength [host] + +=head1 DESCRIPTION + +B<mplength> calculates the total length of the currently selected +playlist in mpd. The length is output to standard output in mm:ss format. + +=head1 SEE ALSO + +mpd(1) + +=head1 AUTHOR + +Copyright 2009 Joey Hess <joey@kitenet.net> + +Licensed under the GNU GPL version 2 or higher. + +http://kitenet.net/~joey/code/mpdtoys + +=cut + +if (@ARGV) { + $ENV{MPD_HOST}=shift; +} +my $mpd=Audio::MPD->new(conntype => "reuse"); +my $pl=$mpd->playlist; +my @list=$pl->as_items; +my $secs=0; +foreach my $item (@list) { + $secs+=$item->time; +} +my $mins=int($secs/60); +printf "%i:%02i\n", $mins, ($secs-$mins*60); |