changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/play

changeset 7243: 34f64dcbbc25
parent: 2dbf69ebf7d3
author: cinap_lenrek@felloff.net
date: Fri, 17 May 2019 18:14:10 +0200
permissions: -rwxr-xr-x
description: 7l: don't hardcode 4k pagesize, use INITRND
1 #!/bin/rc
2 rfork e
3 
4 nl='
5 '
6 out=/dev/audio
7 typ=()
8 tmp=()
9 argv0=$0
10 
11 fn cleanup {
12  if(! ~ $#tmp 0)
13  rm -f $tmp
14  tmp=()
15 }
16 
17 fn sigint {
18  cleanup
19  exit
20 }
21 
22 fn sigexit {
23  cleanup
24 }
25 
26 fn play1 {
27  if(! ~ $#* 2){
28  tmp=(/tmp/play.$pid.$#tmp.tmp $tmp)
29  dd -bs 8192 -count 1 >$tmp(1) >[2]/dev/null
30  cat $tmp(1) /fd/0 | play1 $1 `{file -m $tmp(1)}
31  cleanup
32  }
33  if not {
34  switch($2){
35  case *plain*
36  sed 's/
37 //g' | while(j=`$nl{read}){
38  echo $"j >[1=2]
39  if(~ $"j http:* https:* HTTP:* HTTPS:*){
40  hget -r 'User-Agent: play' -r 'Icy-MetaData: 0' $"j | play1 $"j
41  }
42  if not {
43  if(test -r $"j)
44  play1 <$"j $"j
45  if not {
46  echo $argv0: 'can''t open file:' $"j >[1=2]
47  }
48  }
49  }
50  case *ogg* *vorbis*
51  audio/oggdec
52  case *mp3* *mpeg*
53  audio/mp3dec
54  case *wave*
55  audio/wavdec
56  case *flac*
57  audio/flacdec
58  case *audio/basic*
59  audio/sundec
60  case *audio/midi*
61  games/midi -c
62  case *audio/mus*
63  games/mus | games/midi -c
64  case *pls*
65  awk 'BEGIN {FS="="} /^File/{print $2}' | play1 list plain
66  case *
67  switch($1){
68  case *.mp3 *.MP3
69  audio/mp3dec
70  case *.ogg *.OGG
71  audio/oggdec
72  case *.wav *.WAV
73  audio/wavdec
74  case *.flac *.FLAC
75  audio/flacdec
76  case *.au *.AU
77  audio/sundec
78  case *.mid *.MID
79  games/midi -c
80  case *.mus *.MUS
81  games/mus | games/midi -c
82  case *
83  echo $argv0: $1: unknown format: $2 >[1=2]
84  }
85  }
86  }
87 }
88 
89 fn usage {
90  echo usage: $argv0 '[ -o file ] [ file ... ]' >[1=2]
91  exit usage
92 }
93 
94 while(~ $1 -*){
95  switch($1){
96  case -o
97  out=$2
98  shift
99  case *
100  usage
101  }
102  shift
103 }
104 
105 # boost priority
106 @{echo pri 13 >/proc/$pid/ctl} >/dev/null >[2=1]
107 
108 >$out {
109  if(~ $#* 0){play1 stdin; exit}
110  for(i){echo $"i} | play1 args plain
111 }