Audio-Play-MPG123
view release on metacpan or search on metacpan
$rl->Attribs->{completer_terminator_character}="";
if ($pos==0) {
if ($word=~/^(l(?:oad)?|a(?:dd)?|cd?)(\S.*)?/) {
$p = $1." ";
$c = $2;
}
}
@r = file_completion uri_unesc($c);
if ($line =~ /^c/) {
@r = grep -d "$_/.", @r;
}
if (@r == 1) {
if (-f $r[0]) {
$rl->Attribs->{completer_terminator_character}=" ";
} elsif (-d $r[0]) {
$rl->Attribs->{completer_terminator_character}="/";
}
}
#print "\n<$word|$line|$pos> = ",join(":",@r)," #",scalar@r,"\n";
map $p.uri_esc($_),@r;
};
my $pwr_state = 1;
sub pwr_change {
$SIG{PWR} = \&pwr_change;
$pwr_state = !$pwr_state;
};
$SIG{PWR} = \&pwr_change;
sub event_loop {
my $r;
my $rlin = $rl->IN;
# most ugly workaround for perl-readline bug
if ($rl->ReadLine eq "Term::ReadLine::Perl") {
require IO::Handle;
my $o = (fcntl $rlin,F_GETFL,0) & (O_APPEND | O_NONBLOCK);
fcntl $rlin,F_SETFL,$o | O_NONBLOCK;
my $eof = eof($rlin);
fcntl $rlin,F_SETFL,$o;
return unless $eof;
}
do {
next_song if $player->state == 0 && $pwr_state;
$player->stop if $player->state && !$pwr_state;
vec($r, fileno($rlin), 1) = 1;
vec($r, fileno($player->IN), 1) = 1;
(select $r, undef, undef, undef) < 0 and $r = "";
if (vec($r,fileno($player->IN),1)) {
$player->poll(0);
}
} until vec($r, fileno($rlin), 1);
}
$player->statfreq(20);
print "\nmpg123sh, version $Audio::Play::MPG123::VERSION\n";
print "enter 'help' for a command list\n\n";
for(;;) {
my $prompt=fastcwd." ";
if ($player->state) {
$player->stat;
$prompt.=$player->title." ".$player->{frame}[2]."/".($player->{frame}[2]+$player->{frame}[3]);
} else {
$prompt.=$p_url;
}
$_=$rl->readline("$prompt> ");
if (/^l(?:oad)?\s*(.*?)\s*$/i) {
my $url = $player->canonicalize_url(uri_unesc $1);
load_url($url) or print "ERROR: ",$player->error,"\n";
mp3log("l", $url);
$player->stat;
} elsif (/^a(?:dd)?\s*(.*?)\s*$/i) {
for (mglob uri_unesc $1, GLOB_TILDE|GLOB_NOMAGIC) {
add_url $player->canonicalize_url($_);
}
} elsif (/^r(?:epeat)?\s*(\d+)\s*$/) {
$playlist[-1][1] = $1;
} elsif (/^p/i) {
$player->pause;
pause_url ($player->paused);
} elsif (/^DD$/) {
$p_repeat = 0;
$player->stop;
next_song;
unlink @{pop @playlist}[0];
} elsif (/^d(?:el)?\s*(\d*)\s*$/i) {
for (do {
if ($1) {
splice @playlist,$1-1,1;
} else {
$p_repeat = 0;
$player->stop;
next_song;
pop @playlist;
}
}) {
mp3log("d", $_->[0]);
}
} elsif (/^sh/i) {
shuffle;
} elsif (/^s/i) {
$p_repeat=0;
$player->stop;
mp3log("s", $playlist[0][0]);
next_song;
} elsif (/^c(?:d)?\s*(.*?)\s*$/i) {
chdir uri_unesc $1 or print "Unable to change to '$1': $!\n";
} elsif (/^j(?:ump)?\s*([0-9.]+)\s*$/i) {
eval { $player->jump(int($1/$player->tpf)) };
} elsif (/^o\s*([a-z]+)\s*(.*)/i) {
oconf($1,$2);
} elsif (/^m\s*([a-z]+)\s*(.*)/i) {
mfav($1,$2);
} elsif (/^q/i) {
last;
} elsif (/^i(nfo)?/i) {
print "\n";
if ($player->state) {
print "currently playing: ",$player->url,"\n";
printf "title: %-32s artist: %-30s\n",$player->title,$player->artist;
printf "album: %-32s year: %-30s\n",$player->album,$player->year;
printf "comment: %-32s genre: %-30s\n",$player->comment,$player->genre;
print "\n";
printf "MPEG %s layer %s, %d samples/s, %s, mode_extension is %d, %d bytes/frame\n".
"%d channels, %s, %s, emphasis is %s, %d kbit/s\n",
"I" x $player->type, $player->layer, $player->samplerate, $player->mode, $player->mode_extension,
( run in 2.098 seconds using v1.01-cache-2.11-cpan-800906f7e73 )