-
Notifications
You must be signed in to change notification settings - Fork 21
/
ctbcap-healthcheck
executable file
·42 lines (34 loc) · 1.6 KB
/
ctbcap-healthcheck
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
#!/usr/bin/env bash
#
# Copyright (C) 2019-2024 KFERMercer <https://github.com/KFERMercer>
#
# Check for assignment of runtime variables
[ ! ${MODEL} ] || [ ! ${PLATFORM} ] || [ ! ${SAVE_PATH} ] || [ ! ${LOG_PATH} ] && echo "Incomplete Runtime Variables!" && exit 1
# Process $MODEL
MODEL=${MODEL,,}
MODEL=${MODEL#*"chaturbate.com/"}
MODEL=${MODEL#*"stripchat.com/"}
MODEL=${MODEL%"/"*}
# Process $PLATFORM
[ ${PLATFORM} ] || PLATFORM="chaturbate"
PLATFORM=${PLATFORM,,}
# is chaturbate?
[ ${PLATFORM} = "chaturbate" ] || [ ${PLATFORM} = "ctb" ] || [ ${PLATFORM} = "cb" ] \
&& \
PLATFORM=chaturbate
# is stripchat?
[ ${PLATFORM} = "stripchat" ] || [ ${PLATFORM} = "stc" ] || [ $PLATFORM = "sc" ] || [ ${PLATFORM} = "st" ] \
&& \
PLATFORM=stripchat
# Is directories writable?
[ ! -w ${SAVE_PATH} ] && echo "SAVE_PATH are unwritable!" && exit 1
[ ! -w ${LOG_PATH} ] && echo "LOG_PATH are unwritable!" && exit 1
# Flag of ffmpeg process
FFMPEG_PROCESS=$(ps -ef | grep -oE "[f]fmpeg -i.*${MODEL}.*\.m3u8*" 2>/dev/null)
# No ffmpeg process --> normal
[ ! "${FFMPEG_PROCESS}" ] && exit 0
# If Model currently online, set HTTP Status Code of m3u8 link as flag
[ -f ${LOG_PATH}/${MODEL}.online ] && M3U8_RESPONSE=$(curl $(cat ${LOG_PATH}/${PLATFORM}-${MODEL}.online) -4 -s -I -w %{http_code} -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36' 2>/dev/null | tail -n1)
# Has ffmpeg process, but m3u8 link are unavailable --> err
[ "${FFMPEG_PROCESS}" ] && [ ${M3U8_RESPONSE} -ge 400 ] && echo "(ERROR) FFMPEG process did not exit correctly!" && exit 1
exit 0