#!/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 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 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++); } }