Skip to content

Commit

Permalink
ctbcap: replace conjunction chain with code block
Browse files Browse the repository at this point in the history
  • Loading branch information
KFERMercer committed Jan 3, 2025
1 parent 8ef6215 commit 117c122
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 6 additions & 6 deletions ctbcap
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ genesis_juicer() {
}
SAVE_PATH=${OPTARG}
;;
h) doc help && return 2 ;;
h) doc help; return 2 ;;
l) LINK_MODE=1 ;;
o)
[ "$(echo "${OPTARG}" | cut -c1)" = "-" ] && {
Expand Down Expand Up @@ -304,14 +304,14 @@ utils() {

init_dir() {
printf '%s\n' "$@" | while IFS='' read -r DIR ; do
[ -z "${DIR%"/"}" ] && echo "(ERROR) Root directory are not allowed!" >&2 && return 1
[ -z "${DIR%"/"}" ] && { echo "(ERROR) Root directory are not allowed!" >&2; return 1; }
mkdir -p "${DIR}" 1>/dev/null 2>&1
[ ! -e "${DIR}" ] && echo "(ERROR) Unable to create directory [${DIR}] !" >&2 && return 1
[ ! -d "${DIR}" ] && echo "(ERROR) [${DIR}] is not a directory!" >&2 && return 1
[ ! -w "${DIR}" ] && echo "(ERROR) Cannot Write To [${DIR}/] !" >&2 && return 1
[ ! -e "${DIR}" ] && { echo "(ERROR) Unable to create directory [${DIR}] !" >&2; return 1; }
[ ! -d "${DIR}" ] && { echo "(ERROR) [${DIR}] is not a directory!" >&2; return 1; }
[ ! -w "${DIR}" ] && { echo "(ERROR) Cannot Write To [${DIR}/] !" >&2; return 1; }
true
done
return $?
return 0
}

# Sleep time (s) before initial request to server. Range better EQ to watchdog().while.case.1).echo .
Expand Down
13 changes: 7 additions & 6 deletions ctbcap-healthcheck
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _MODEL="$(echo "${MODEL}" \
[ -n "${_MODEL}" ] && MODEL="${_MODEL}"
# If ${MODEL} not URL form, cut invalid chars.
[ -z "${_MODEL}" ] && _MODEL="$(echo "${MODEL}" | tr '[:upper:]' '[:lower:]'| grep -oE '[a-z0-9_-]+' | head -n 1)"
[ -z "${_MODEL}" ] && echo "(ERROR) Invalid Username or Link!" && exit 1
[ -z "${_MODEL}" ] && { echo "(ERROR) Invalid Username or Link!"; exit 1; }
[ -n "${_MODEL}" ] && MODEL="${_MODEL}"

# Process $PLATFORM
Expand All @@ -33,23 +33,24 @@ stripchat|stc|sc|st)
PLATFORM=stripchat
;;
*)
echo "(ERROR) Invalid Platform!" && exit 1
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
[ ! -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
[ -f "${LOG_PATH}/${MODEL}-${PLATFORM}.online" ] && {
STREAM_LINK="$(cat "${LOG_PATH}/${MODEL}-${PLATFORM}.online")"
UA="$(ctbcap -v | grep '^UA: ' | sed 's|UA: ||')"
[ -z "${UA}" ] && echo "(ERROR) UA does not exist!" && exit 1
[ -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
[ -n "${FFMPEG_PROCESS}" ] && [ -z "${M3U8_RESPONSE}" ] && { echo "(ERROR) FFMPEG process did not exit correctly!"; exit 1; }
}

echo "Everything is OK!"
Expand Down

0 comments on commit 117c122

Please sign in to comment.