summaryrefslogtreecommitdiff
path: root/mprev
diff options
context:
space:
mode:
Diffstat (limited to 'mprev')
-rwxr-xr-xmprev56
1 files changed, 56 insertions, 0 deletions
diff --git a/mprev b/mprev
new file mode 100755
index 0000000..cb1f944
--- /dev/null
+++ b/mprev
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Audio::MPD q{0.19.0};
+
+=head1 NAME
+
+mprev - reverse the mpd playlist
+
+=head1 SYNOPSIS
+
+mprev [host]
+
+=head1 DESCRIPTION
+
+B<mprev> reverses mpd's playlist. That's all. The currently playing
+song doesn't change. The song you heard last will be the next song to
+play.
+
+If the hostname is omitted, the MPD_HOST environment variable will be used.
+
+=head1 AUTHOR
+
+Copyright 2007 Joey Hess <joey@kitenet.net>
+
+Licensed under the GNU GPL version 2 or higher.
+
+http://kitenet.net/~joey/code/mpdtoys
+
+=cut
+
+if (@ARGV) {
+ $ENV{MPD_HOST}=shift;
+}
+
+my $mpd=Audio::MPD->new(conntype => "reuse");
+my $pl=$mpd->playlist;
+my $current=$mpd->current;
+if (! $current) {
+ die "playlist seems to be empty\n";
+}
+my $pos=$mpd->current->pos;
+my $id=$mpd->current->id;
+my $past=0;
+my @list=$pl->as_items;
+foreach my $song (reverse @list) {
+ if ($past) {
+ $pl->moveid($song->id, $#list);
+ }
+ elsif ($id eq $song->id) {
+ $past=1;
+ }
+ else {
+ $pl->moveid($song->id, $pos++);
+ }
+}