#!/usr/bin/perl
use Xmms::Remote ();
use MP3::Info();

$xmms = Xmms::Remote->new();
$title=$xmms->get_playlist_title;
$title1 =~ s/_[^_]*_[^_]*_/ - /;


 my $arg = shift;
        $arg =~ s/^\s+//;
        $arg =~ s/\s+$//;

    my $track;
        if ($arg =~ /^(\d+)$/) {
                $track = $1;
        } else {
                $track = $xmms->get_playlist_pos;
        }
    my $file = $xmms->get_playlist_file($track);

        
        
    if (-r $file) {
        if ($file =~ /\.mp3$/i) {
                $tag = MP3::Info::get_mp3tag($file);
		print("[");	
                print("".$tag->{"ARTIST"}." - ") if ($tag->{"ARTIST"});
		
		print("".$tag->{"TITLE"}."")  if ($tag->{"TITLE"});
		
		print($file) if (!($tag->{"TITLE"} || $tag->{"ARTIST"}));		
		
            	print("] - ");
		print("[Album:".$tag->{"ALBUM"}."] - ") if ($tag->{"ALBUM"});
	#	print("[Kommentar:".$tag->{"COMMENT"}."] - ") if ($tag->{"COMMENT"});
		print("[Genre:".$tag->{"GENRE"}."] - ") if ($tag->{"GENRE"});
		print("[Jahr:".$tag->{"YEAR"}."] - ") if ($tag->{"YEAR"});
                $info = MP3::Info::get_mp3info($file);
                print("[MPEG".$info->{"VERSION"}." Layer".$info->{"LAYER"}."] -"); #mpeg version
		print(($info->{"VBR"} ? "[variabel, durchschnittliche Bitrate: " : " [").$info->{"BITRATE"}."Bit] - ");
		print("[".$info->{"FREQUENCY"}." kHz] ".($info->{"STEREO"} ? " - [Stereo]" : " - [Mono]"));
                 print(" - ");
		 
		 my $time = $info->{"MM"}*60+$info->{"SS"};
		 
		if ($time > 3600) {
		     $time_string = sprintf("[%3i:%02i:%02i (h:min:sek)]", int($time/3600), int($time/60) % 60, $time % 60);
		     } 
		     else {
			 $time_string = sprintf("[%02i:%02i (min:sek)]", int($time/60) % 60, $time % 60);
		     }
		print("".$time_string); #dauer
		#print("\n");
        } else {
            print("info supports only mp3 files\n");
        }
    } else {
        print("".$file);
	
    }
