]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/play
file: mp3 audio data detection by syncword, play: remote -t option as file now works...
[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.tmp $tmp)
26                 dd -bs 1024 -count 1 >$tmp(1) >[2]/dev/null
27                 cat $tmp(1) /fd/0 | play1 `{file -m $tmp(1)} xxx
28                 cleanup
29         }
30         if not {
31                 switch($1){
32                 case *plain*
33                         sed 's/\r//g' | while(j=`{read}){
34                                 echo $"j >[1=2]
35                                 if(~ $"j http:* https:* HTTP:* HTTPS:*){
36                                         hget -r 'Icy-MetaData: 0' $j | play1
37                                 }
38                                 if not {
39                                         if(test -r $"j)
40                                                 play1 <$"j
41                                         if not {
42                                                 echo $argv0: 'can''t open file:' $"j >[1=2]
43                                         }
44                                 }
45                         }
46                 case *ogg* *vorbis*
47                         audio/oggdec
48                 case *mp3* *mpeg*
49                         audio/mp3dec
50                 case *flac*
51                         audio/flacdec
52                 case *pls*
53                         awk 'BEGIN {FS="="} /^File/{print $2}' | play1 plain
54                 case *
55                         echo $argv0: unknown format: $1 >[1=2]
56                 }
57         }
58 }
59
60 fn usage {
61         echo usage: $argv0 [ -o file ] [ file ... ] >[1=2]
62         exit usage
63 }
64
65 while(~ $1 -*){
66         switch($1){
67         case -o
68                 out=$2
69                 shift
70         case *
71                 usage
72         }
73         shift
74 }
75
76 >$out {
77         if(~ $#* 0){play1; exit}
78         for(i){echo $i} | play1 plain 
79