summaryrefslogtreecommitdiff
path: root/rc/bin
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@rei2.9hal>2012-01-22 23:30:34 +0100
committercinap_lenrek <cinap_lenrek@rei2.9hal>2012-01-22 23:30:34 +0100
commit5524d7607501020ca891436dfbcd88aaf5d15bdf (patch)
treec82e7714e5f0b4b74ccb716daba88a8c831b04cf /rc/bin
parent29b26a2f175b3fe4329c121eca4c7cbb383f5e28 (diff)
move mp3 stuff to /sys/src/cmd/audio, add ogg vorbis, add play
Diffstat (limited to 'rc/bin')
-rwxr-xr-xrc/bin/play80
1 files changed, 80 insertions, 0 deletions
diff --git a/rc/bin/play b/rc/bin/play
new file mode 100755
index 000000000..a5194b654
--- /dev/null
+++ b/rc/bin/play
@@ -0,0 +1,80 @@
+#!/bin/rc
+
+out=/dev/audio
+typ=()
+tmp=()
+argv0=$0
+
+fn cleanup {
+ if(! ~ $#tmp 0)
+ rm -f $tmp
+ tmp=()
+}
+
+fn sigint {
+ cleanup
+ exit
+}
+
+fn sigexit {
+ cleanup
+}
+
+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
+ cleanup
+ }
+ if not {
+ switch($1){
+ case *plain*
+ sed 's/ //g' | while(j=`{read}){
+ if(~ $"j http:* https:* HTTP:* HTTPS:*){
+ if(~ $#typ 0) typ=mp3
+ echo $"j >[1=2]
+ hget -r 'Icy-MetaData: 0' $j | play1 $typ
+ }
+ if not {
+ if(test -r $"j){
+ echo $"j >[1=2]
+ play1 <$"j
+ }
+ }
+ }
+ case *ogg* *vorbis*
+ audio/oggdec
+ case *mp3* *mpeg*
+ audio/mp3dec
+ case *pls*
+ awk 'BEGIN {FS="="} /^File/{print $2}' | play1 plain
+ case *
+ echo $argv0: unknown format: $1 >[1=2]
+ }
+ }
+}
+
+fn usage {
+ echo usage: $argv0 [ -t type ] [-o file ] [ file ... ] >[1=2]
+ exit usage
+}
+
+while(~ $1 -*){
+ switch($1){
+ case -t
+ typ=$2
+ shift
+ case -o
+ out=$2
+ shift
+ case *
+ usage
+ }
+ shift
+}
+
+>$out {
+ if(~ $#* 0){play1 $typ; exit}
+ for(i){echo $i} | play1 plain
+}