file: mp3 audio data detection by syncword, play: remote -t option as file now works for mp3 streams
This commit is contained in:
parent
a57ad59bf0
commit
ac0107ca42
3 changed files with 31 additions and 41 deletions
23
rc/bin/play
23
rc/bin/play
|
@ -22,9 +22,9 @@ fn sigexit {
|
||||||
|
|
||||||
fn play1 {
|
fn play1 {
|
||||||
if(~ $#* 0){
|
if(~ $#* 0){
|
||||||
tmp=/tmp/play.$pid.tmp
|
tmp=(/tmp/play.$pid.$#tmp.tmp $tmp)
|
||||||
dd -bs 64 -count 1 >$tmp >[2]/dev/null
|
dd -bs 1024 -count 1 >$tmp(1) >[2]/dev/null
|
||||||
cat $tmp /fd/0 | play1 `{file -m $tmp} xxx
|
cat $tmp(1) /fd/0 | play1 `{file -m $tmp(1)} xxx
|
||||||
cleanup
|
cleanup
|
||||||
}
|
}
|
||||||
if not {
|
if not {
|
||||||
|
@ -32,16 +32,12 @@ fn play1 {
|
||||||
case *plain*
|
case *plain*
|
||||||
sed 's/
//g' | while(j=`{read}){
|
sed 's/
//g' | while(j=`{read}){
|
||||||
echo $"j >[1=2]
|
echo $"j >[1=2]
|
||||||
t=$typ
|
|
||||||
if(~ $"j http:* https:* HTTP:* HTTPS:*){
|
if(~ $"j http:* https:* HTTP:* HTTPS:*){
|
||||||
if(~ $#t 0) t=mp3
|
hget -r 'Icy-MetaData: 0' $j | play1
|
||||||
hget -r 'Icy-MetaData: 0' $j | play1 $t
|
|
||||||
}
|
}
|
||||||
if not {
|
if not {
|
||||||
if(test -r $"j){
|
if(test -r $"j)
|
||||||
if(~ $#t 0 && ~ $"j *mp3*) t=mp3
|
play1 <$"j
|
||||||
play1 $t <$"j
|
|
||||||
}
|
|
||||||
if not {
|
if not {
|
||||||
echo $argv0: 'can''t open file:' $"j >[1=2]
|
echo $argv0: 'can''t open file:' $"j >[1=2]
|
||||||
}
|
}
|
||||||
|
@ -62,15 +58,12 @@ fn play1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage {
|
fn usage {
|
||||||
echo usage: $argv0 [ -t type ] [-o file ] [ file ... ] >[1=2]
|
echo usage: $argv0 [ -o file ] [ file ... ] >[1=2]
|
||||||
exit usage
|
exit usage
|
||||||
}
|
}
|
||||||
|
|
||||||
while(~ $1 -*){
|
while(~ $1 -*){
|
||||||
switch($1){
|
switch($1){
|
||||||
case -t
|
|
||||||
typ=$2
|
|
||||||
shift
|
|
||||||
case -o
|
case -o
|
||||||
out=$2
|
out=$2
|
||||||
shift
|
shift
|
||||||
|
@ -81,6 +74,6 @@ while(~ $1 -*){
|
||||||
}
|
}
|
||||||
|
|
||||||
>$out {
|
>$out {
|
||||||
if(~ $#* 0){play1 $typ; exit}
|
if(~ $#* 0){play1; exit}
|
||||||
for(i){echo $i} | play1 plain
|
for(i){echo $i} | play1 plain
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,6 @@ play \- simple audio player
|
||||||
.B -o
|
.B -o
|
||||||
.I file
|
.I file
|
||||||
] [
|
] [
|
||||||
.B -t
|
|
||||||
.I type
|
|
||||||
] [
|
|
||||||
.I file
|
.I file
|
||||||
\&|
|
\&|
|
||||||
.I url
|
.I url
|
||||||
|
@ -24,30 +21,11 @@ If no
|
||||||
or
|
or
|
||||||
.I url
|
.I url
|
||||||
arguments are given, standard input is used.
|
arguments are given, standard input is used.
|
||||||
Wihout the
|
The file type is determined using
|
||||||
.B -t
|
|
||||||
option, the file type is determined using
|
|
||||||
.IR file (1)
|
.IR file (1)
|
||||||
command and the appropriate decoder is invoked.
|
command and a matching
|
||||||
.PP
|
.IR audio (1)
|
||||||
Supported
|
decoder is applied.
|
||||||
.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.
|
|
||||||
.PP
|
.PP
|
||||||
By default, raw audio data is written to
|
By default, raw audio data is written to
|
||||||
.B /dev/audio
|
.B /dev/audio
|
||||||
|
|
|
@ -150,6 +150,7 @@ int ishtml(void);
|
||||||
int isrfc822(void);
|
int isrfc822(void);
|
||||||
int ismbox(void);
|
int ismbox(void);
|
||||||
int islimbo(void);
|
int islimbo(void);
|
||||||
|
int ismp3(void);
|
||||||
int ismung(void);
|
int ismung(void);
|
||||||
int isp9bit(void);
|
int isp9bit(void);
|
||||||
int isp9font(void);
|
int isp9font(void);
|
||||||
|
@ -195,6 +196,7 @@ int (*call[])(void) =
|
||||||
ismsdos, /* msdos exe (virus file attachement) */
|
ismsdos, /* msdos exe (virus file attachement) */
|
||||||
isicocur, /* windows icon or cursor file */
|
isicocur, /* windows icon or cursor file */
|
||||||
isface, /* ascii face file */
|
isface, /* ascii face file */
|
||||||
|
ismp3,
|
||||||
|
|
||||||
/* last resorts */
|
/* last resorts */
|
||||||
ismung, /* entropy compressed/encrypted */
|
ismung, /* entropy compressed/encrypted */
|
||||||
|
@ -1135,6 +1137,23 @@ isas(void)
|
||||||
return 1;
|
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
|
* low entropy means encrypted
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue