Debian Codegraph @

mptoggle

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 mptoggle - single button control for mpd
9
10 =head1 SYNOPSIS
11
12 mptoggle [host] [playlist ...]
13
14 =head1 DESCRIPTION
15
16 B<mptoggle> allows mpd to be controlled by a single physical button. It
17 was designed for a linksys nslu2 running mpd, for which the only available
18 physical control is a power button that can be remapped to run an arbitrary
19 program.
20
21 B<mptoggle> toggles playback each time it's run. So press the button once
22 to start, and a second time to stop. Each time it starts playing. By
23 default it selects a new different playlist, at random, to play. If
24 playlist names are specified at the command line, it will choose between
25 those at random.
26
27 Example of how to make the nslu2's power button run mptoggle, in
28 /etc/inittab:
29
30 ca:12345:ctrlaltdel:/usr/bin/mptoggle localhost
31
32 =head1 SEE ALSO
33
34 mprompt(1) mpd(1)
35
36 =head1 AUTHOR
37
38 Copyright 2007 Joey Hess <[email protected]>
39
40 Licensed under the GNU GPL version 2 or higher.
41
42 http://kitenet.net/~joey/code/mpdtoys
43
44 =cut
45
46 if (@ARGV) {
47 $ENV{MPD_HOST}=shift;
48 }
49 my $mpd=Audio::MPD->new(conntype => "reuse");
50
51 if ($mpd->status->state ne 'play') {
52 $mpd->playlist->clear;
53 my @playlists;
54 if (@ARGV) {
55 @playlists=@ARGV;
56 }
57 else {
58 @playlists=$mpd->collection->all_playlists;
59 }
60 $mpd->playlist->load($playlists[rand @playlists]);
61 $mpd->play;
62 }
63 else {
64 $mpd->pause;
65 }