ref: 08a870633c82f1b1ace70ffce11e990b0088fb53
parent: 0d8cfa83c83077abdd024decd89cbc3cabcf620f
author: cinap_lenrek <cinap_lenrek@rei2.9hal>
date: Tue Feb 14 12:29:18 EST 2012
file: mp3 audio data detection by syncword, play: remote -t option as file now works for mp3 streams
--- a/rc/bin/play
+++ b/rc/bin/play
@@ -22,9 +22,9 @@
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)} xxxcleanup
}
if not {@@ -32,16 +32,12 @@
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 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 @@
}
>$out {- if(~ $#* 0){play1 $typ; exit}+ if(~ $#* 0){play1; exit} for(i){echo $i} | play1 plain }
--- a/sys/man/1/play
+++ b/sys/man/1/play
@@ -6,9 +6,6 @@
[
.B -o
.I file
-] [
-.B -t
-.I type
] [
.I file
\&|
@@ -24,30 +21,11 @@
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
--- a/sys/src/cmd/file.c
+++ b/sys/src/cmd/file.c
@@ -150,6 +150,7 @@
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 @@
ismsdos, /* msdos exe (virus file attachement) */
isicocur, /* windows icon or cursor file */
isface, /* ascii face file */
+ ismp3,
/* last resorts */
ismung, /* entropy compressed/encrypted */
@@ -1133,6 +1135,23 @@
return 0;
print(mime ? PLAIN : "as program\n");
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;
}
/*
--
⑨