#!/usr/bin/perl -w
#
# mplist version 0.1
#
# Requires mpc to be on the user's path.
#
# Written by Hannes Reich (hannesATskynetDOTie), 16/04/2004.
# This code is in the public domain.
#

use strict;
use sigtrap;

use Shell qw(mpc);

# Grab the current playlist postion

my $current_track = 0;
for (mpc)
{
    # match things like "[playing] #1/4086   0:00 (0%)"
    if(/^\[(playing|paused)\] \#(\d+)\//)
    {
	$current_track = $2;
	last;
    }
}


# Spit out the current and following 10 entries

PLAYLIST_ENTRY:
for (mpc 'playlist')
{
    # match things like "#4071) NOFX - Take Two Placebos"
    if( /^\#(\d+)\)/i )
    {
      next PLAYLIST_ENTRY
	unless $1 >= $current_track;
      print;
      last PLAYLIST_ENTRY
	if $1 > $current_track + 10;
    }
}
