#!/usr/bin/perl #--------------------------------------------------------------------- # $Id: client,v 1.5 1999/07/11 18:27:39 eric Exp $ # # eMp3 - taking playlists a step beyond # Copyright (C) 1999 Eric Richardson # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # # For information on eMp3, contact eScripting at # escripting@escripting.com , or check out the eMp3 web site at # http://www.escripting.com/eMp3/ # # this is the eMp3 player script # #--------------------------------------------------------------------- use IPC::Shareable; $player = "/home/eric/scripts/eMp3/player"; # server <-> client $handle = tie %shared,'IPC::Shareable','eMp3',{ exclusive => 0, create => 0, destroy => 0 }; $SIG{INT} = \&kill_sucker; open (SERVER_PID, "/tmp/eMp3.pid"); $e{server_pid} = ; close SERVER_PID; print < "; my $input = ; chop($input); &parse($input); } while (1); #---------- sub parse { $_ = shift; my ($command,$options) = /([^\t]+)\t(.*)/; $command = $_ unless ($command); if ($command eq"add_file") { if (-e $options) { $shared{songs} = [(@{$shared{songs}},$options)]; } else { print "could not add to song list: $!\n"; } } elsif ($command eq"add_dir") { if (-d $options) { opendir(DIR, $options); my @files = readdir DIR; while (my $file = shift(@files)) { if (-d $file) { warn "skipping dir: $file\n"; } else { $shared{songs} = [(@{$shared{songs}},"$options/$file")]; } } closedir DIR; } else { print "$options is not a directory\n"; } } elsif ($command eq"list") { my @songs = @{$shared{songs}}; my $num = '0'; while (my $song = shift(@songs)) { print "$num -- $song\n"; $num++; } } elsif ($command eq"randomize") { my @songs = @{$shared{songs}}; my $i; for ($i = @songs; --$i;) { my $j = int rand ($i+1); next if $i == $j; @songs[$i,$j] = @songs[$j,$i]; } $shared{songs} = [(@songs)]; } elsif ($command eq"drop") { my @songs = @{$shared{songs}}; splice(@songs,$options,1); $shared{songs} = [(@songs)]; } elsif ($command eq"switch") { my ($a,$b) = split(",",$options); my @songs = @{$shared{songs}}; @songs[$a,$b] = @songs[$b,$a]; $shared{songs} = [(@songs)]; } elsif ($command eq"next") { $shared{player_message} = "next"; kill 12, $shared{player_pid}; } elsif ($command eq"seek") { } elsif ($command eq"pause") { if ($shared{player_state} ne"PAUSED") { $shared{player_message} = "pause"; kill 12, $shared{player_pid}; } else { kill 14, $shared{player_pid}; } } elsif ($command eq"rewind") { $shared{player_message} = "restart"; kill 12, $shared{player_pid}; } elsif ($command eq"info") { my $next = ($shared{current_num}+1); print < @{$shared{songs}}); &alert_server; } elsif ($command eq"exit") { print "eMp3 client exiting.\n\n"; exit; } elsif ($command eq"shutdown") { } else { print "command '$command' not recognized.\n"; } } #---------- sub alert_server { kill 14, $e{server_pid}; } #---------- sub kill_sucker { die "$$ dying\n"; }