2012-01-22 22:30:34 +00:00
|
|
|
#!/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}){
|
2012-01-22 00:12:28 +00:00
|
|
|
echo $"j >[1=2]
|
2012-01-26 00:43:17 +00:00
|
|
|
t=$typ
|
2012-01-22 22:30:34 +00:00
|
|
|
if(~ $"j http:* https:* HTTP:* HTTPS:*){
|
2012-01-26 00:43:17 +00:00
|
|
|
if(~ $#t 0) t=mp3
|
|
|
|
hget -r 'Icy-MetaData: 0' $j | play1 $t
|
2012-01-22 22:30:34 +00:00
|
|
|
}
|
|
|
|
if not {
|
2012-01-26 00:43:17 +00:00
|
|
|
if(test -r $"j){
|
|
|
|
if(~ $#t 0 && ~ $"j *mp3*) t=mp3
|
|
|
|
play1 $t <$"j
|
|
|
|
}
|
2012-01-22 00:12:28 +00:00
|
|
|
if not {
|
|
|
|
echo $argv0: 'can''t open file:' $"j >[1=2]
|
2012-01-22 22:30:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case *ogg* *vorbis*
|
|
|
|
audio/oggdec
|
|
|
|
case *mp3* *mpeg*
|
|
|
|
audio/mp3dec
|
2012-02-11 07:33:22 +00:00
|
|
|
case *flac*
|
|
|
|
audio/flacdec
|
2012-01-22 22:30:34 +00:00
|
|
|
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
|
|
|
|
}
|