5 use constant VERSION
=> '0.10.0';
7 my $x = Audio
::MPD
->new('localhost',6600);
9 # mpctime() - For getting the time in the same format as `mpc` writes it
12 my($psf,$tst) = split /:/, $x->{'time'};
13 return sprintf("%d:%02d (%d%%)",
14 ($psf / 60), # minutes so far
15 ($psf % 60), # seconds - minutes so far
16 $psf/($tst/100)); # Percent
21 print "mpc version: ".VERSION
."\n";
22 print "mpc\t\t\t\tDisplays status\n";
23 print "mpc add <filename>\t\tAdd a song to the current playlist\n";
24 print "mpc del <playlist #>\t\tRemove a song from the current playlist\n";
25 print "mpc play <number>\t\tStart playing a <number> (default: 1)\n";
26 print "mpc next\t\t\tPlay the next song in the current playlist\n";
27 print "mpc prev\t\t\tPlay the previous song in the current playlist\n";
28 print "mpc pause\t\t\tPauses the currently playing song\n";
29 print "mpc stop\t\t\tStop the currently playing song\n";
30 print "mpc seek <0-100>\t\tSeeks to the position specified in seconds\n";
31 print "mpc clear\t\t\tClears the current playlist\n";
32 print "mpc shuffle\t\t\tShuffle the current playlist\n";
33 print "mpc move <from> <to>\t\tMove song in playlist\n";
34 print "mpc playlist\t\t\tPrint the current playlist\n";
35 print "mpc listall [<song>]\t\tList all songs in the music dir\n";
36 print "mpc ls [<dir>]\t\t\tList the contents of <dir>\n";
37 print "mpc lsplaylists\t\t\tLists currently available playlists\n";
38 print "mpc load <file>\t\t\tLoad <file> as a playlist\n";
39 print "mpc save <file>\t\t\tSaves a playlist as <file>\n";
40 print "mpc rm <file>\t\t\tRemoves a playlist\n";
41 print "mpc volume [+-]<num>\t\tSets volume to <num> or adjusts by [+-]<num>\n";
42 print "mpc repeat <on|off>\t\tToggle repeat mode, or specify state\n";
43 print "mpc random <on|off>\t\tToggle random mode, or specify state\n";
44 #print "mpc search <type> <queries>\tSearch for a song\n";
45 print "mpc crossfade [sec]\t\tSet and display crossfade settings\n";
46 print "mpc update\t\t\tScans music directory for updates\n";
47 print "mpc version\t\t\tReports version of MPD\n";
48 print "For more information about these and other options look man 1 mpc\n";
52 # status() - For showing the current status
56 my $repeat = ($x->{repeat
} == 1 ?
'on ' : 'off'); # Let's show the repeat-status a bit nicer
57 my $random = ($x->{random
} == 1 ?
'on ' : 'off'); # And the same for random
58 if($x->{state} eq 'play' || $x->{state} eq 'pause') { # If MPD is either playing or paused
59 print decode_utf8
($x->get_title)."\n";
60 print "[".($x->{state} eq 'play' ?
'playing' : 'paused')."] #".($x->{song
}+1)."/".$x->{playlistlength
}."\t".mpctime
."\n";
61 print "volume: ".$x->{volume
}."% repeat: ".$repeat." random: ".$random."\n";
62 } elsif($x->{state} eq 'stop') { # If MPD is stopped, we don't show much
63 print "volume: ".$x->{volume
}."% repeat: ".$repeat." random: ".$random."\n";
68 sub play
{ $x->play($ARGV[1] ?
($ARGV[1]-1) : 0); status
; }
69 sub stop
{ $x->stop(); status
; }
70 sub pause
{ $x->pause(); status
; }
72 if($ARGV[1] || $ARGV[1] eq '') {
82 if(defined($ARGV[1])) {
83 $x->delete($ARGV[1]-1);
88 sub next { $x->next(); status
; }
89 sub prev
{ $x->prev(); status
; }
91 if(defined($ARGV[1])) {
92 $x->seek($ARGV[1]); status
;
97 sub clear
{ $x->clear(); }
98 sub shuffle
{ $x->shuffle(); }
100 if(defined($ARGV[1]) && defined($ARGV[2])) {
101 $x->move($ARGV[1]-1,$ARGV[2]-1);
108 my $playlist = $x->playlist;
109 for(my $i = 0 ; $i < $x->{playlistlength
} ; $i++)
111 my $title = ($playlist->[$i]{'Artist'} && $playlist->[$i]{'Title'} ?
$playlist->[$i]{'Artist'}." - ".$playlist->[$i]{'Title'} : $playlist->[$i]{'file'});
112 print "#".($i+1).") ".$title."\n";
117 my @list = $x->listall($ARGV[1]);
118 foreach my $item (@list)
120 print "$1\n" if $item =~ /(?:file):\s(.+)/;
125 foreach my $tmp ($x->lsinfo($ARGV[1]))
128 if($hash{'directory'} || $hash{'file'})
130 print $hash{'directory'} || $hash{'file'};
137 #while(my %hash = $x->nextinfo)
138 foreach my $tmp ($x->lsinfo())
141 print $hash{'playlist'}."\n" if $hash{'playlist'};
145 if(defined($ARGV[1])) {
152 if(defined($ARGV[1])) {
159 if(defined($ARGV[1])) {
166 if(defined($ARGV[1])) {
167 $x->set_volume($ARGV[1]);
174 if(defined($ARGV[1])) {
175 $x->set_repeat($ARGV[1]);
182 if(defined($ARGV[1])) {
183 $x->set_random($ARGV[1]);
191 die('No way!') if $ARGV[1] !~ /^(filename|artist|title|album)$/;
192 my @list = $x->search($ARGV[1],$ARGV[2]);
193 foreach my $hash (@list)
196 print $song{'file'}."\n";
200 if(defined($ARGV[1])) {
201 $x->set_fade($ARGV[1]);
206 sub update
{ $x->updatedb(); }
207 sub version
{ print "mpd version: ".$x->{version
}."\n"; }
213 help
if $ARGV[0] !~ /^(add|del|play|next|prev|pause|stop|seek|clear|shuffle|move|playlist|listall|ls|lsplaylists|load|save|rm|volume|repeat|random|search|crossfade|update|version)$/;