Debian Codegraph @

mplength

raw
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Audio::MPD q{0.19.0};
5
6 =head1 NAME
7
8 mplength - calculates length of mpd playlist
9
10 =head1 SYNOPSIS
11
12 mplength [host]
13
14 =head1 DESCRIPTION
15
16 B<mplength> calculates the total length of the currently selected
17 playlist in mpd. The length is output to standard output in mm:ss format.
18
19 =head1 SEE ALSO
20
21 mpd(1)
22
23 =head1 AUTHOR
24
25 Copyright 2009 Joey Hess <[email protected]>
26
27 Licensed under the GNU GPL version 2 or higher.
28
29 http://kitenet.net/~joey/code/mpdtoys
30
31 =cut
32
33 if (@ARGV) {
34 $ENV{MPD_HOST}=shift;
35 }
36 my $mpd=Audio::MPD->new(conntype => "reuse");
37 my $pl=$mpd->playlist;
38 my @list=$pl->as_items;
39 my $secs=0;
40 foreach my $item (@list) {
41 if (defined $item->time) {
42 $secs+=$item->time;
43 }
44 }
45 my $mins=int($secs/60);
46 printf "%i:%02i\n", $mins, ($secs-$mins*60);