file: mp3 audio data detection by syncword, play: remote -t option as file now works for mp3 streams

This commit is contained in:
cinap_lenrek 2012-02-14 17:29:18 +01:00
parent a57ad59bf0
commit ac0107ca42
3 changed files with 31 additions and 41 deletions

View file

@ -22,9 +22,9 @@ fn sigexit {
fn play1 {
if(~ $#* 0){
tmp=/tmp/play.$pid.tmp
dd -bs 64 -count 1 >$tmp >[2]/dev/null
cat $tmp /fd/0 | play1 `{file -m $tmp} xxx
tmp=(/tmp/play.$pid.$#tmp.tmp $tmp)
dd -bs 1024 -count 1 >$tmp(1) >[2]/dev/null
cat $tmp(1) /fd/0 | play1 `{file -m $tmp(1)} xxx
cleanup
}
if not {
@ -32,16 +32,12 @@ fn play1 {
case *plain*
sed 's/ //g' | while(j=`{read}){
echo $"j >[1=2]
t=$typ
if(~ $"j http:* https:* HTTP:* HTTPS:*){
if(~ $#t 0) t=mp3
hget -r 'Icy-MetaData: 0' $j | play1 $t
hget -r 'Icy-MetaData: 0' $j | play1
}
if not {
if(test -r $"j){
if(~ $#t 0 && ~ $"j *mp3*) t=mp3
play1 $t <$"j
}
if(test -r $"j)
play1 <$"j
if not {
echo $argv0: 'can''t open file:' $"j >[1=2]
}
@ -62,15 +58,12 @@ fn play1 {
}
fn usage {
echo usage: $argv0 [ -t type ] [-o file ] [ file ... ] >[1=2]
echo usage: $argv0 [ -o file ] [ file ... ] >[1=2]
exit usage
}
while(~ $1 -*){
switch($1){
case -t
typ=$2
shift
case -o
out=$2
shift
@ -81,6 +74,6 @@ while(~ $1 -*){
}
>$out {
if(~ $#* 0){play1 $typ; exit}
if(~ $#* 0){play1; exit}
for(i){echo $i} | play1 plain
}

View file

@ -6,9 +6,6 @@ play \- simple audio player
[
.B -o
.I file
] [
.B -t
.I type
] [
.I file
\&|
@ -24,30 +21,11 @@ If no
or
.I url
arguments are given, standard input is used.
Wihout the
.B -t
option, the file type is determined using
The file type is determined using
.IR file (1)
command and the appropriate decoder is invoked.
.PP
Supported
.I type
values are:
.TP
.B plain
Plain text with one file or url per line.
.TP
.B pls
Winamp playlist file.
.TP
.B mp3
Mpeg audio.
.TP
.B ogg
Ogg vorbis.
.TP
.B flac
FLAC lossless audio.
command and a matching
.IR audio (1)
decoder is applied.
.PP
By default, raw audio data is written to
.B /dev/audio

View file

@ -150,6 +150,7 @@ int ishtml(void);
int isrfc822(void);
int ismbox(void);
int islimbo(void);
int ismp3(void);
int ismung(void);
int isp9bit(void);
int isp9font(void);
@ -195,6 +196,7 @@ int (*call[])(void) =
ismsdos, /* msdos exe (virus file attachement) */
isicocur, /* windows icon or cursor file */
isface, /* ascii face file */
ismp3,
/* last resorts */
ismung, /* entropy compressed/encrypted */
@ -1135,6 +1137,23 @@ isas(void)
return 1;
}
int
ismp3(void)
{
uchar *p, *e;
p = buf;
e = p + nbuf-1;
while((p < e) && (p = memchr(p, 0xFF, e - p))){
if((p[1] & 0xFE) == 0xFA){
print(mime ? "audio/mpeg\n" : "mp3 audio\n");
return 1;
}
p++;
}
return 0;
}
/*
* low entropy means encrypted
*/