]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/play
move mp3 stuff to /sys/src/cmd/audio, add ogg vorbis, add play
[plan9front.git] / rc / bin / play
1 #!/bin/rc
2
3 out=/dev/audio
4 typ=()
5 tmp=()
6 argv0=$0
7
8 fn cleanup {
9         if(! ~ $#tmp 0)
10                 rm -f $tmp
11         tmp=()
12 }
13
14 fn sigint {
15         cleanup
16         exit
17 }
18
19 fn sigexit {
20         cleanup
21 }
22
23 fn play1 {
24         if(~ $#* 0){
25                 tmp=/tmp/play.$pid.tmp
26                 dd -bs 64 -count 1 >$tmp >[2]/dev/null
27                 cat $tmp /fd/0 | play1 `{file -m $tmp} xxx
28                 cleanup
29         }
30         if not {
31                 switch($1){
32                 case *plain*
33                         sed 's/\r//g' | while(j=`{read}){
34                                 if(~ $"j http:* https:* HTTP:* HTTPS:*){
35                                         if(~ $#typ 0) typ=mp3
36                                         echo $"j >[1=2]
37                                         hget -r 'Icy-MetaData: 0' $j | play1 $typ
38                                 }
39                                 if not {
40                                         if(test -r $"j){
41                                                 echo $"j >[1=2]
42                                                 play1 <$"j
43                                         }
44                                 }
45                         }
46                 case *ogg* *vorbis*
47                         audio/oggdec
48                 case *mp3* *mpeg*
49                         audio/mp3dec
50                 case *pls*
51                         awk 'BEGIN {FS="="} /^File/{print $2}' | play1 plain
52                 case *
53                         echo $argv0: unknown format: $1 >[1=2]
54                 }
55         }
56 }
57
58 fn usage {
59         echo usage: $argv0 [ -t type ] [-o file ] [ file ... ] >[1=2]
60         exit usage
61 }
62
63 while(~ $1 -*){
64         switch($1){
65         case -t
66                 typ=$2
67                 shift
68         case -o
69                 out=$2
70                 shift
71         case *
72                 usage
73         }
74         shift
75 }
76
77 >$out {
78         if(~ $#* 0){play1 $typ; exit}
79         for(i){echo $i} | play1 plain 
80