Debian Codegraph @

mprandomwalk

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 mprandomwalk - play random bits of all queued songs
9
10 =head1 SYNOPSIS
11
12 mprandomwalk [maxduration] [host]
13
14 =head1 DESCRIPTION
15
16 B<mprandomwalk> plays random segments of randomly chosen songs in the
17 playlist.
18
19 The B<maxduration> can control the maximum number of seconds of a song to
20 play at a time.
21
22 If the hostname is omitted, the MPD_HOST environment variable will be used.
23
24 =head1 AUTHOR
25
26 Copyright 2010 Joey Hess <[email protected]>
27
28 Licensed under the GNU GPL version 2 or higher.
29
30 http://kitenet.net/~joey/code/mpdtoys
31
32 =cut
33
34 my $maxduration=10;
35 if (@ARGV && $ARGV[0] =~ /^[0-9.]+$/) {
36 $maxduration=shift;
37 }
38
39 if (@ARGV) {
40 $ENV{MPD_HOST}=shift;
41 }
42
43 my $mpd=Audio::MPD->new(conntype => "reuse");
44
45 $mpd->play;
46
47 my $pl=$mpd->playlist;
48 my @list=$pl->as_items;
49
50 if (! @list) {
51 die "error: no songs queued\n";
52 }
53
54 while (1) {
55 my $song=$list[rand($#list)];
56 my $length=$song->time;
57 next unless $length;
58 my $duration=rand($maxduration);
59 my $pos=rand($length-$duration);
60 $mpd->seekid($pos, $song->id);
61 sleep $duration;
62 }