From ac0107ca4234d1c51fcf3c7ae30fc6fde86464ae Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 14 Feb 2012 17:29:18 +0100 Subject: [PATCH] file: mp3 audio data detection by syncword, play: remote -t option as file now works for mp3 streams --- rc/bin/play | 23 ++++++++--------------- sys/man/1/play | 30 ++++-------------------------- sys/src/cmd/file.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 41 deletions(-) diff --git a/rc/bin/play b/rc/bin/play index 0eabc9d9b..f000cd0ea 100755 --- a/rc/bin/play +++ b/rc/bin/play @@ -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 } diff --git a/sys/man/1/play b/sys/man/1/play index 5499198e7..d9cd2de6b 100644 --- a/sys/man/1/play +++ b/sys/man/1/play @@ -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 diff --git a/sys/src/cmd/file.c b/sys/src/cmd/file.c index 2759cce8d..7da5abdaa 100644 --- a/sys/src/cmd/file.c +++ b/sys/src/cmd/file.c @@ -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 */