-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrj.sh
executable file
·94 lines (82 loc) · 1.62 KB
/
nrj.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#/bin/bash
# canonicalize OSTYPE to OSKIND
case $OSTYPE in
darwin*) OSKIND=darwin ;;
linux*) OSKIND=linux ;;
openbsd*) OSKIND=openbsd ;;
freebsd*) OSKIND=freebsd ;;
cygwin*) OSKIND=windows ;;
*) OSKIND=$OSTYPE ;;
esac
# canonicalize CPU to ARCH
[ -z "$CPU" ] && CPU=`uname -m`
case $CPU in
arm64|amd64|x86_64|x86-64) ARCH=x86_64 ;;
i386|x86) ARCH=x86 ;;
*) ARCH=$CPU ;;
esac
PLAY=""
OUTPUT=""
METRICS=""
while [[ $# -gt 0 ]]; do
key="$1"
val="${key#*=}"
case $key in
--play)
PLAY="mpv"
;;
--play=*)
PLAY="$val"
;;
--stream)
OUTPUT="udp://127.0.0.1:1234?pkt_size=1316&tos=0x80&ttl=5"
;;
--output=*)
OUTPUT="$val"
;;
--metrics)
METRICS="--metrics"
;;
--)
shift
break
;;
--*)
echo "unknow flag $1" >&2
exit 1
;;
*)
break
;;
esac
shift
done
if [[ -n $PLAY && -n $OUTPUT ]]; then
echo "Cannot specify both --play and an --output/--stream at the same time" >&2
exit 1
fi
if [[ $PLAY != "" && $PLAY = "mpv" ]]; then
FOUND="$(which mpv 2> /dev/null)"
if [[ $? -ne 0 ]]; then
echo "Executable $PLAY not found." >&2
exit 1
fi
PLAY="$FOUND -"
fi
ICYCAT="./bin/$OSKIND.$ARCH/icycat"
if [[ ! -x $ICYCAT ]]; then
ICYCAT="./icycat"
if [[ ! -x $ICYCAT ]]; then
echo "you need to build icycat first!" >&2
exit 1
fi
fi
if [[ $OUTPUT != "" ]]; then
OUTPUT="--output $OUTPUT"
fi
URL="https://frontend.streamonkey.net/energy-digital/stream/mp3?aggregator=energyde"
if [[ -n $PLAY ]]; then
$ICYCAT --logtostderr --stderrthreshold=INFO $METRICS $OUTPUT $URL | $PLAY
exit $?
fi
exec $ICYCAT --logtostderr --stderrthreshold=INFO $METRICS $OUTPUT --timeout=10s $URL