forked from KFERMercer/chaturbate-grabber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctbcap-healthcheck
executable file
·56 lines (48 loc) · 2.14 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env sh
#
# Copyright (C) 2019-2024 KFERMercer <https://github.com/KFERMercer>
#
[ "${DEBUG_MODE}" = "1" ] && set -x # Debug Mode
# Check for assignment of runtime variables
[ -z "${MODEL}" ] || [ -z "${PLATFORM}" ] || [ -z "${SAVE_PATH}" ] || [ -z "${LOG_PATH}" ] && exit 0
# Process ${MODEL}
# TODO: Model may change their name, consider using realtime name.
# Assume ${MODEL} contain some link form, process & cut invalid chars.
MODEL_TEMP=$(echo "${MODEL}" \
| tr '[:upper:]' '[:lower:]' \
| grep -oE 'http[s]?://[a-zA-Z]?+[.]?[a-zA-Z]+[.][a-zA-Z]+[/][^ /]+' \
| cut -d '/' -f4 \
| grep -oE '[a-zA-Z0-9_-]+' \
| head -n 1)
[ -n "${MODEL_TEMP}" ] && MODEL=${MODEL_TEMP}
# If ${MODEL} not link form, cut invalid chars.
[ -z "${MODEL_TEMP}" ] && MODEL=$(echo "${MODEL}" | tr '[:upper:]' '[:lower:]'| grep -oE '[a-zA-Z0-9_-]+' | head -n 1)
[ -z "${MODEL}" ] && echo "(ERROR) Invalid Username or Link!" && exit 1
# Process $PLATFORM
PLATFORM=$(echo "${PLATFORM}" | tr '[:upper:]' '[:lower:]')
case ${PLATFORM} in
chaturbate|ctb|cb)
PLATFORM=chaturbate
;;
stripchat|stc|sc|st)
PLATFORM=stripchat
;;
*)
echo "(ERROR) Invalid Platform!" && exit 1
;;
esac
# Is directories writable?
[ ! -w "${SAVE_PATH}" ] && echo "(ERROR) SAVE_PATH is unwritable!" && exit 1
[ ! -w "${LOG_PATH}" ] && echo "(ERROR) LOG_PATH is unwritable!" && exit 1
# If Model currently online, set HTTP Status Code of m3u8 link as flag
if [ -f "${LOG_PATH}/${MODEL}-${PLATFORM}.online" ]; then
STREAM_LINK="$(cat "${LOG_PATH}/${MODEL}-${PLATFORM}.online")"
[ -n "${UA}" ] || UA="$(ctbcap -v | grep '^UA: ' | sed 's|UA: ||')"
[ -z "${UA}" ] && echo "(ERROR) UA does not exist!" && exit 1
# Has ffmpeg process, but m3u8 link is unavailable --> err
FFMPEG_PROCESS=$(ps -ef | grep -oE "[f]fmpeg.*-i.*.m3u8.*${MODEL}.*.mkv" 2>/dev/null)
M3U8_RESPONSE=$(curl "${STREAM_LINK}" -4 -L -s -A "${UA}" --compressed --retry 3 --retry-delay 2 2>/dev/null | tr -d '\r')
[ -n "${FFMPEG_PROCESS}" ] && [ -z "${M3U8_RESPONSE}" ] && echo "(ERROR) FFMPEG process did not exit correctly!" && exit 1
fi
echo "Everything is OK!"
exit 0