-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdvr
executable file
·208 lines (171 loc) · 4.61 KB
/
pdvr
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#! /bin/bash
COMMAND=$1
CWD=$( cd `dirname $0`; pwd )
if [ ! -f ${CWD}/config ]; then
echo "Missing configuration: ${CWD}/config"
exit 1
fi
. ${CWD}/config
. ${CWD}/core/utils
function is_running()
{
local NAME=$1
[ -f ${PIDS}/${NAME}.pid ] && [ -d /proc/`cat ${PIDS}/${NAME}.pid` ]
}
function stop()
{
local NAME=$1
if [ -f ${PIDS}/${NAME}.pid ]; then
local PID=`cat ${PIDS}/${NAME}.pid`
kill ${PID}
sleep 1
fi
}
function show_log()
{
local NAME=$1
[ -f ${LOG}/${NAME}.log ] && cat ${LOG}/${NAME}.log \
|| echo "-- no log --"
}
function show_schedule()
{
local MODE=$1
local TIMESTAMP
for TIMESTAMP in `ls ${SCHEDULE} | sort -n`; do
[ ${MODE} -eq 0 ] && echo "${TIMESTAMP} `format_schedule ${TIMESTAMP}`"
[ ${MODE} -eq 1 ] && echo "${TIMESTAMP}|`cat ${SCHEDULE}/${TIMESTAMP}`"
done
[ ${MODE} -eq 0 ] && [ -z "${TIMESTAMP}" ] && echo "-- no schedule --"
}
case ${COMMAND} in
start)
mkdir -p ${LOG}
echo "Starting."
if ! is_running scheduler-service; then
bash `dirname $0`/core/pdvr-scheduler > ${LOG}/scheduler.log 2>&1 &
disown $!
sleep 1
fi
if ! is_running converter-service; then
bash `dirname $0`/core/pdvr-converter > ${LOG}/converter.log 2>&1 &
disown $!
sleep 1
fi
if ! is_running epg-updater-service; then
bash `dirname $0`/core/pdvr-epg-updater > ${LOG}/epg-updater.log 2>&1 &
disown $!
sleep 1
fi
is_running scheduler-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " Scheduler"
is_running converter-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " Converter"
is_running epg-updater-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " EPG Updater"
;;
stop)
echo "Stopping."
is_running scheduler-service && stop scheduler-service
is_running converter-service && stop converter-service
is_running epg-updater-service && stop epg-updater-service
is_running scheduler-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " Scheduler"
is_running converter-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " Converter"
is_running epg-updater-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " EPG Updater"
;;
status)
is_running scheduler-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " Scheduler"
is_running converter-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " Converter"
is_running epg-updater-service \
&& echo -n "[Running]" || echo -n "[Stopped]"
echo " EPG Updater"
if is_running record; then
TIMESTAMP=`ls ${SCHEDULE} | sort -n | head -1`
ENTRY=`cat ${SCHEDULE}/${TIMESTAMP}`
TIME=`date -d @${TIMESTAMP}`
DURATION=`echo "${ENTRY}" |cut -d"|" -f1`
CHANNEL=`echo "${ENTRY}" |cut -d"|" -f2`
NAME=`echo "${ENTRY}" |cut -d"|" -f3`
UNTIL=$(( ${TIMESTAMP} + ${DURATION} ))
UNTIL_TIME=`date +"%H:%M" -d @${UNTIL}`
echo ""
echo "[ Rec ] ${NAME} <${CHANNEL}>"
echo " Until ${UNTIL_TIME}"
fi
if is_running converter-service && ! is_running converter; then
FILE=`ls -t ${EXPORTS}/*.mp4 2>/dev/null| head -1`
SIZE=`stat -c %s "${FILE}"`
echo ""
echo "[Convert] `basename \"${FILE}\"` (${SIZE} Bytes)"
fi
;;
record)
if is_running scheduler-service; then
bash `dirname $0`/core/pdvr-add "$2" "$3" "$4" "$5"
else
echo "The scheduler service is not running."
fi
;;
cancel)
bash `dirname $0`/core/pdvr-cancel $2
;;
show)
show_schedule 0
;;
epg)
CWD=`cd $(dirname $0); pwd`
node `dirname $0`/core/js/epg-browser.js ${CWD}/`basename $0`
;;
get-epg)
cat ${EPG}/epg.json
;;
get-channels)
cat ${CHANNELS_CONF}
;;
get-recordings)
show_schedule 1
;;
log)
show_log $2
;;
*)
echo "Pikku-DVR version 1.0rc - (c) 2019 Martin Grimme"
echo ""
echo "Usage: pdvr <command> [parameter ...]"
echo ""
echo "Commands:"
echo ""
echo " start Start the background services."
echo ""
echo " stop Stop the background services."
echo ""
echo " status Show the current status of the background services."
echo ""
echo " log Show the log."
echo " Parameters: <service>"
echo " <service> is one of: scheduler, converter, epg-updater"
echo ""
echo " record Schedule a recording."
echo " Parameters: <time> <duration> <channel> <name>"
echo ""
echo " cancel Cancel a recording."
echo " Parameters: <recording ID>"
echo ""
echo " show Show the scheduled recordings with their recording IDs."
echo ""
echo " epg Browse the electronic program guide."
;;
esac
true