]> git.lizzy.rs Git - plan9front.git/blobdiff - rc/bin/play
ircrc: various improvements (thanks again pap!)
[plan9front.git] / rc / bin / play
index 73fdcf6e5c853fa0f18e8fb3d6468086f62868e3..2acbdf8ba13d13680d9716bed00e2bae4250de69 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/rc
+rfork e
 
 out=/dev/audio
 typ=()
@@ -22,9 +23,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 8192 -count 1 >$tmp(1) >[2]/dev/null
+               cat $tmp(1) /fd/0 | play1 `{file -m $tmp(1)} xxx
                cleanup
        }
        if not {
@@ -32,16 +33,12 @@ fn play1 {
                case *plain*
                        sed 's/\r//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]
                                        }
@@ -51,6 +48,10 @@ fn play1 {
                        audio/oggdec
                case *mp3* *mpeg*
                        audio/mp3dec
+               case *wave*
+                       audio/wavdec
+               case *flac*
+                       audio/flacdec
                case *pls*
                        awk 'BEGIN {FS="="} /^File/{print $2}' | play1 plain
                case *
@@ -60,15 +61,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
@@ -78,7 +76,10 @@ while(~ $1 -*){
        shift
 }
 
+# boost priority
+@{echo pri 13 >/proc/$pid/ctl} >/dev/null >[2=1] 
+
 >$out {
-       if(~ $#* 0){play1 $typ; exit}
+       if(~ $#* 0){play1; exit}
        for(i){echo $i} | play1 plain 
 }