Skip to content

Commit

Permalink
ctbcap-healthcheck: sync var proc with ctbcap
Browse files Browse the repository at this point in the history
  • Loading branch information
KFERMercer committed Jan 3, 2025
1 parent 48fa734 commit a983e76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
28 changes: 14 additions & 14 deletions ctbcap
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,20 @@ genesis_juicer() {

PLATFORM=$(echo "${PLATFORM}" | tr '[:upper:]' '[:lower:]')
case ${PLATFORM} in
chaturbate|ctb|cb)
PLATFORM=chaturbate
LINK="https://chaturbate.com/api/chatvideocontext/${MODEL}/" # Must keep " / " at the end
;;
stripchat|stc|sc|st)
PLATFORM=stripchat
LINK="https://stripchat.com/api/front/v2/models/username/${MODEL}/cam"
;;
*)
echo "(ERROR) Unknown Platform: [${PLATFORM}] !" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
;;
chaturbate|ctb|cb)
PLATFORM=chaturbate
LINK="https://chaturbate.com/api/chatvideocontext/${MODEL}/" # Must keep " / " at the end
;;
stripchat|stc|sc|st)
PLATFORM=stripchat
LINK="https://stripchat.com/api/front/v2/models/username/${MODEL}/cam"
;;
*)
echo "(ERROR) Unknown Platform: [${PLATFORM}] !" >&2
echo >&2
echo "See [ $0 -h ] for help." >&2
return 1
;;
esac

CUT_TIME=$(echo "${CUT_TIME}" | cut -c -9) #Cut to INT range
Expand Down
39 changes: 20 additions & 19 deletions ctbcap-healthcheck
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,46 @@
# 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}" \
_MODEL="$(echo "${MODEL}" \
| tr '[:upper:]' '[:lower:]' \
| grep -oE 'http[s]?://[a-zA-Z]?+[.]?[a-zA-Z]+[.][a-zA-Z]+[/][^ /]+' \
| grep -oE 'http[s]?://[a-z0-9-]?+[.]?[a-z0-9-]+[.][a-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
| grep -oE '[a-z0-9_-]+' \
| head -n 1)"
[ -n "${_MODEL}" ] && MODEL="${_MODEL}"
# If ${MODEL} not URL form, cut invalid chars.
[ -z "${_MODEL}" ] && local _MODEL="$(echo "${MODEL}" | tr '[:upper:]' '[:lower:]'| grep -oE '[a-z0-9_-]+' | head -n 1)"
[ -z "${_MODEL}" ] && echo "(ERROR) Invalid Username or Link!" && exit 1
[ -n "${_MODEL}" ] && MODEL="${_MODEL}"

# 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
;;
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
[ -f "${LOG_PATH}/${MODEL}-${PLATFORM}.online" ] && {
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!"

Expand Down

0 comments on commit a983e76

Please sign in to comment.