File: mprandomwalk

package info (click to toggle)
mpdtoys 0.24
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 104 kB
  • ctags: 22
  • sloc: perl: 842; sh: 58; makefile: 21
file content (62 lines) | stat: -rwxr-xr-x 1,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
use strict;
use warnings;
use Audio::MPD q{0.19.0};

=head1 NAME

mprandomwalk - play random bits of all queued songs

=head1 SYNOPSIS

mprandomwalk [maxduration] [host]

=head1 DESCRIPTION

B<mprandomwalk> plays random segments of randomly chosen songs in the
playlist.

The B<maxduration> can control the maximum number of seconds of a song to
play at a time.

If the hostname is omitted, the MPD_HOST environment variable will be used.

=head1 AUTHOR

Copyright 2010 Joey Hess <joey@kitenet.net>

Licensed under the GNU GPL version 2 or higher.

http://kitenet.net/~joey/code/mpdtoys

=cut

my $maxduration=10;
if (@ARGV && $ARGV[0] =~ /^[0-9.]+$/) {
	$maxduration=shift;
}

if (@ARGV) {
	$ENV{MPD_HOST}=shift;
}

my $mpd=Audio::MPD->new(conntype => "reuse");

$mpd->play;

my $pl=$mpd->playlist;
my @list=$pl->as_items;

if (! @list) {
	die "error: no songs queued\n";
}

while (1) {
	my $song=$list[rand($#list)];
	my $length=$song->time;
	next unless $length;
	my $duration=rand($maxduration);
	my $pos=rand($length-$duration);
	$mpd->seekid($pos, $song->id);
	sleep $duration;
}