Debian Codegraph @

mprev

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 mprev - reverse the mpd playlist
9
10 =head1 SYNOPSIS
11
12 mprev [host]
13
14 =head1 DESCRIPTION
15
16 B<mprev> reverses mpd's playlist. That's all. The currently playing
17 song doesn't change. The song you heard last will be the next song to
18 play.
19
20 If the hostname is omitted, the MPD_HOST environment variable will be used.
21
22 =head1 AUTHOR
23
24 Copyright 2007 Joey Hess <[email protected]>
25
26 Licensed under the GNU GPL version 2 or higher.
27
28 http://kitenet.net/~joey/code/mpdtoys
29
30 =cut
31
32 if (@ARGV) {
33 $ENV{MPD_HOST}=shift;
34 }
35
36 my $mpd=Audio::MPD->new(conntype => "reuse");
37 my $pl=$mpd->playlist;
38 my $current=$mpd->current;
39 if (! $current) {
40 die "playlist seems to be empty\n";
41 }
42 my $pos=$mpd->current->pos;
43 my $id=$mpd->current->id;
44 my $past=0;
45 my @list=$pl->as_items;
46 foreach my $song (reverse @list) {
47 if ($past) {
48 $pl->moveid($song->id, $#list);
49 }
50 elsif ($id eq $song->id) {
51 $past=1;
52 }
53 else {
54 $pl->moveid($song->id, $pos++);
55 }
56 }