-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlaunch.sh
90 lines (76 loc) · 1.8 KB
/
launch.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
#!/bin/bash
cd "$(dirname ${0})"
shopt -s expand_aliases
if [[ ! -f config.conf ]]; then
echo "You forgot to create the 'config.conf' configuration file!"
exit 1
fi
mkdir -p .tmp
PLAYLIST_FILE=".tmp/playlist.m3u"
source config.conf
trap "before_exit" EXIT HUP INT QUIT PIPE TERM
log() {
echo "${@}" >&2
}
log_reset() {
tput reset
log "${@}"
}
before_exit() {
player_stop
exit 0
}
fetch_playlist() {
if hash curl 2>/dev/null; then
curl -o ${PLAYLIST_FILE} "${PLAYLIST_URL}"
elif hash wget 2>/dev/null; then
wget -O ${PLAYLIST_FILE} "${PLAYLIST_URL}"
else
hash curl wget
exit 1
fi
}
remove_playlist() {
rm -f ${PLAYLIST_FILE}
}
get_channel() {
if [[ ! -f $(find ${PLAYLIST_FILE} -mmin -30 2>/dev/null) ]]; then
log "Updating channels..."
fetch_playlist
fi
local line
line=$(grep -in "tvg-name=\"${CHANNELS[$1]}\"" ${PLAYLIST_FILE} | cut -d: -f1 | head -1)
if [[ -n ${line} ]]; then
cat ${PLAYLIST_FILE} | sed -n $(( line + 1 ))p
fi
}
manage_input() {
local stream
log_reset "Status: press any key"
while :; do
read -t5 key
if [[ -z ${key} ]]; then
if [[ -z ${stream} ]]; then
log_reset "Status: press any key"
continue
fi
if ! player_status; then
player_start "${stream}" &
else
log_reset "Status: running"
fi
continue
fi
stream="$(get_channel ${key})"
if [[ -z ${stream} ]]; then
remove_playlist
continue
fi
if player_status; then
player_stop
fi
log "Starting player..."
player_start "${stream}" &
done
}
python remote.py | manage_input