v2024.11.06

This commit is contained in:
kittykat 2024-11-08 09:32:54 +00:00
parent 1f87d598a4
commit 808d64768b
118 changed files with 28958 additions and 0 deletions

View file

@ -0,0 +1,67 @@
#! Name: ExampleAddNewFuncAndCallOnSuccessfulDownload.sh
#! Author: kittykat
#! Version: 2024.09.21
#! Desc: Add a new function to MAD and call it whenever a file is successfully downloaded
#! Usage: Edit LoadPlugin="" line in mad.sh or mad.config
#! LoadPlugin="ExampleAddNewFuncAndCallOnSuccessfulDownload.sh"
#!
#! Notes: Not that this would be used as such (performing a sha256 hash of file would be added directly to the
#! desired hook -- PostSuccessfulDownload(). This is just an example to show that creating your own
#! function and then calling it is possible.
#!
#! * This could be used to add new host urls, and process them:
#! PreProcessUrl_mysha256() : parse the line and determine if it is a supported host, call new functions
#!
#! 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
#!
#! ----------- Hooks ----------------------------
#!
#! Hook PostSuccessfulDownload() function
PostSuccessfulDownload_mysha256() {
local plugName='ExampleAddNewFuncAndCallOnSuccessfulDownload'
local plugFunc='PostSuccessfulDownload_mysha256'
if [ "${DebugAllEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pRemoteUrl="$1"
local pFilePath="$2"
local pFileName="$3"
local pFolderName="$4"
local pFileSize="$5"
local fileHash=$(hookHashFile "$pFilePath")
echo -e "${BLUE}File${NC}: $pFileName"
echo -e "${BLUE}sha256${NC}: $fileHash"
return 0
}
#! ---------- New User Defined Functions --------------------
#! Define a new function to hash a file
#! This will be loaded in the OnLoad() hook in mad.sh, and will become an available function to use after OnLoad()
hookHashFile() {
local plugName='ExampleAddNewFuncAndCallOnSuccessfulDownload'
local plugFunc='hookHashFile'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pFilePath="$1"
echo $(sha256sum "$pFilePath" | awk '{ print $1 }')
}

View file

@ -0,0 +1,163 @@
#! Name: ExamplesMainHooks.sh
#! Author: kittykat
#! Version: 2024.09.21
#! Desc: Just some examples on easy plugins...
#! Usage: Edit LoadPlugin="" line in mad.sh or mad.config
#! LoadPlugin="ExamplesMainHooks.sh"
#!
#!
#! 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 (host not responding, missing required response)
#! * PostFailRetryUpload(): occurs after an upload fails with a retry (network drop, unexpected result)
#! * DoneProcessingAllUploads: occurs after alll the files have finished processing
#!
#! ----------- Hooks ----------------------------
#!
OnLoad_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='OnLoad_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pScriptSourceDir="$1"
local pScriptArguments="$2"
return 0
}
BeginProcessing_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='BeginProcessing_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pInputFile="$1"
return 0
}
PreProcessUrl_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PreProcessUrl_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pFullLine="$1"
local pUrlOnly="${1%%\ *}"
if grep -Eqi '|' <<< "${pUrlOnly}" ; then
pUrlOnly="${pUrlOnly%%\|*}"
fi
if grep -Eqi '^direct=' <<< "${pUrlOnly}" ; then
pUrlOnly="${pUrlOnly%%\=*}"
fi
return 0
return 1
}
PostSuccessfulDownload_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PostSuccessfulDownload_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pRemoteUrl="$1"
local pFilePath="$2"
local pFileName="$3"
local pFolderName="$4"
local pFileSize="$5"
return 0
}
PostFailedDownload_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PostFailedDownload_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pRemoteUrl="$1"
local pMessage1="$2"
local pMessage2="$3"
return 0
}
PostFailRetryDownload_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PostFailRetryDownload_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pRemoteUrl="$1"
local pMessage1="$2"
local pMessage2="$3"
return 0
}
DoneProcessingAllUrls_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='DoneProcessingAllUrls_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pInputFile="$1"
madReset "$pInputFile" "true" "false" "false" "true"
qChkLineCount=$(grep -Ei '^(http|direct=http)' "${pInputFile}" | wc -l | awk '{ print $1 }')
if ((qChkLineCount > 0)) ; then
ReloadScript "$@"
fi
return 0
}
PostSuccessfulUpload_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PostSuccessfulUpload_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pFilePath="$1"
local pHostCode="$2"
local pFileName="$3"
local pFileSize="$4"
local pDownloadLink="$5"
return 0
}
PostFailedUpload_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PostFailedUpload_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pFilePath="$1"
local pHostCode="$2"
local pMessage1="$3"
local pMessage2="$4"
return 0
}
PostFailRetryUpload_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='PostFailRetryUpload_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pFilePath="$1"
local pHostCode="$2"
local pMessage1="$3"
local pMessage2="$4"
return 0
}
DoneProcessingAllUploads_ExamplesMainHooks() {
local plugName='ExamplesMainHooks'
local plugFunc='DoneProcessingAllUploads_ExamplesMainHooks'
if [ "${DebugPluginsEnabled}" == "true" ]; then
echo -e "[${PINK}DEBUG${NC}]: Running ${PINK}$plugFunc${NC} in ${BLUE}$plugName${NC} ...${NC}"
fi
local pInputFile="$1"
return 0
}