#!/usr/bin/perl # by Steve Pomeroy # released under the GNU GPL #use strict; use Xmms::Remote (); use Getopt::Std; getopts("TclndRuUespx:rfhN:"); my $session = 0; $session = $opt_N if $opt_N ne ""; my $remote = Xmms::Remote->new($session); if($opt_h){ print < xmms session number -f forward to next song in playlist -r previous (rewind) -p play -s stop -u pause - note: this is not a togggle, use -p to resume -U pause - if stopped or paused, will start playing, else pause -x searches playlist for pattern -c displays currently playing filename -n displays currently playing title -d dumps the playlist as song titles -e enqueues filename(s) to the end of the playlist -T Total time on the playlist in days, hours, mins, secs -R time Remaining on playlist in days, hours, mins, secs EOF exit; } my $playlist; my $pos; if ($remote->is_running) { #ok $remote->get_version; if ($opt_f){ $remote->playlist_next; }elsif($opt_r){ $remote->playlist_prev; }elsif($opt_u){ unless ($remote->is_paused){$remote->pause} }elsif($opt_U){ unless($remote->is_playing){ $remote->play; }else{ $remote->pause; } }elsif($opt_e){ # enqueue # shift @ARGV; $remote->playlist_add(\@ARGV); }elsif($opt_s){ $remote->stop; }elsif($opt_p){ $remote->play; }elsif($opt_x){ # search for keyword and play match my $i = 0; my $search = -1; my $s_pattern = $opt_x if $opt_x ne ""; getPlaylist(); for ( $i = $remote->get_playlist_pos() + 1; $i < @$playlist && $search == -1; $i++ ){ if(defined $s_pattern && @$playlist[$i]=~/$s_pattern/) { $search = $i } if($opt_l){ if($i == $pos){print "@"}else{print " "} print "$song\n"; } } if($search == -1){die "No match found\n"} $remote->set_playlist_pos($search); $remote->play; }elsif($opt_n){ print @{$remote->get_playlist_titles}[$remote->get_playlist_pos]."\n"; }elsif($opt_d){ # dump filenames and times my $count = 0; my @list = @{$remote->get_playlist_files}; foreach (@list){ print $remote->get_playlist_time($count)."\n"; print "@list[$count]\n"; $count++; } }elsif($opt_R){ # remaining time my $remain = 0; $remain = $remote->get_playlist_time($remote->get_playlist_pos) - $remote->get_output_time; print "Time remaining for current song: ".ftime($remain)."\n"; my @list = @{$remote->get_playlist_files}; for (my $count = $remote->get_playlist_pos + 1; $count < scalar(@list); $count++){ $remain += $remote->get_playlist_time($count); # print "@list[$count]\n"; } print "Time remaining: ".ftime($remain)."\n"; }elsif($opt_T){ # total time my $total = 0; my @list = @{$remote->get_playlist_files}; for (my $count = 0; $count < scalar(@list); $count++){ $total += $remote->get_playlist_time($count); # print "@list[$count]\n"; } print "Total playlist time: ".ftime($total)."\n"; }elsif($opt_c){ getPlaylist(); print @$playlist[$remote->get_playlist_pos]."\n"; } # other stuff to play with later #if ($remote->is_playing) { # $remote->stop; #} # $remote->play; #$remote->playlist_clear; #Xmms::sleep(0.25); #$remote->playlist([map { "$pwd/test$_.mp3" } (1..3)]); #Xmms::sleep(0.25); #$remote->set_playlist_pos(0); #my($vl, $vr) = $remote->get_volume; #$remote->set_main_volume(25); #$remote->set_volume($vl, $vr); #if (@$orig_files) { # $remote->playlist($orig_files); # $remote->set_playlist_pos($orig_pos); # Xmms::sleep(0.25); # $remote->jump_to_time($orig_time); #} } sub ftime { my ($time) = @_; my $out = ""; $time /= 1000; $out .= sprintf "%dd ", $time/60/60/24 if int( $time/60/60/24) > 0; $out .= sprintf "%d:%02d:%-2.2d", $time/60/60 % 24, $time/60 % 60, $time % 60; return $out; } sub getPlaylist { $playlist = $remote->get_playlist_files; $pos = $remote->get_playlist_pos; #my $orig_time = $remote->get_output_time; }