mad/plugins/CatnapCtrlC.sh
kittykat d62376f7a8
# 2025.02.18 - [uploadhive] Add handling of the new /cgi-bin/dl.cgi/ url tickets (WIP)
#               (unfortunately, this is tied to the requesting ip, so downloads get "Wrong IP")
# 2025.02.18 - [up_oshi] Add Manage url as comment on uploads
# 2025.02.18 - [up_oshi / oshi] use /nossl/ url and http
# 2025.02.17 - [gofile] Add a random sleep if 429 response detected (too many requests)
# 2025.02.17 - [*ALL] Audit and update all single bracket operations
# 2025.02.17 - [filehaus] Fix downloading from fh
# 2025.02.15 - [uploadbay] Update urls regex for acceptable alternate
# 2025.02.15 - [up_sendnow] Add send.now as upload host
# 2025.02.15 - [sendnow] Fix handling of filenames with special characters in url
2025-02-19 13:41:07 +00:00

57 lines
2.8 KiB
Bash

#! Name: CatnapCtrlC.sh
#! Author: kittykat
#! Version: 2025.02.18
#! Desc: Keeps mad.sh running until Ctrl-C, waiting for urls.txt updates
#! Usage: Edit LoadPlugin="" line in mad.sh or mad.config
#! LoadPlugin="CatnapCtrlC.sh"
#! Notes:
#! * Return 0 (true), continue script (exit)
#! * Return 1 (false), return to processing the beginning of urls.txt -- would be used with a sleep
#! to continue to run indefinitely until Ctrl-C is pressed, waiting for more urls
#!
#! Plugin System: Additional Hook Functions added for easy of overriding:
#!
#! To Hook a Function, your function must begin with the hookable function name, and be unique
#! Best practice: HooKFuncName_<yourfilename>
#! ie.
#! PostSuccessfulDownload_myfilename() {
#! }
#!
#! Available Hook Functions:
#! -------------------------
#! * OnLoad(): Occurs after load mad.config / load plugins (prior to processing).
#! * BeginProcessing(): Occurs immediately after beginning processin of urls.txt (loops with Catnaps).
#! * PreProcessUrl(): occurs immediately after reading in an unprocessed url (^http) line to process.
#! * PostSuccessfulDownload(): occurs after a download success (is marked #OK# in the urls.txt).
#! * PostFailedDownload(): occurs after a download fails (is marked #FAIL# in the urls.txt).
#! * PostFailRetryDownload(): occurs after a download fails with a retry (is marked #RETRY# in the urls.txt).
#! * DoneProcessingAllUrls(): occurs after all the urls have finished processing (no flocks or other terms downloading).
#! * PostSuccessfulUpload(): occurs after an upload success (after upload completed ticket is created in ./downloads/).
#! * PostFailedUpload(): occurs after an upload fails definitively -- #FAIL# in the temp_upload_handler.txt
#! * PostFailRetryUpload(): occurs after an upload fails with a retry (network drop, unexpected result)
#! * DoneProcessingAllUploads: occurs after alll the files have finished processing
#!
DoneProcessingAllUrls_CatnapCtrlC() {
local plugName='CatnapCtrlC'
local plugFunc='DoneProcessingAllUrls_CatnapCtrlC'
if [[ "${DebugPluginsEnabled}" == "true" ]]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pInputFile="$1"
CatnapCount=$((CatnapCount + 1))
if ((CatnapCount > 2)); then
for ((a=1; a<=2; a++)); do
printf "\033[1A\r"
printf "\33[2K\r"
done
elif ((CatnapCount > 1)); then
for ((a=1; a<=5; a++)); do
printf "\033[1A\r"
printf "\33[2K\r"
done
fi
echo -e "${NC}"
echo -e "${YELLOW}Ctrl-C Catnapping${NC} for ${CatnapDuration} mins and waiting for urls in ${YELLOW}${pInputFile}${NC}... ${YELLOW}zZzZzZ${NC} ${BLUE}x$CatnapCount${NC}"
sleep ${CatnapDuration}m
return 1
}