From c5cb95fd8cf5a3859fdeb85757da000fe2f875ca Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Thu, 16 Oct 2014 20:40:09 +0000 Subject: [PATCH] additional parameters (env. vars) are now passed to scan scripts: NZBNP_DUPEKEY, NZBNP_DUPESCORE, NZBNP_DUPEMODE; scan-scripts can now set dupekey, dupemode and dupescore by printing new special commands --- daemon/queue/Scanner.cpp | 50 ++++++++++++++++++++++++++++++++++------ nzbget.conf | 14 ++++++++++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/daemon/queue/Scanner.cpp b/daemon/queue/Scanner.cpp index 51e88043..9b45bf25 100644 --- a/daemon/queue/Scanner.cpp +++ b/daemon/queue/Scanner.cpp @@ -65,6 +65,9 @@ private: NZBParameterList* m_pParameters; bool* m_bAddTop; bool* m_bAddPaused; + char** m_pDupeKey; + int* m_iDupeScore; + EDupeMode* m_eDupeMode; int m_iPrefixLen; void PrepareParams(const char* szScriptName); @@ -75,14 +78,16 @@ protected: public: static void ExecuteScripts(const char* szNZBFilename, const char* szUrl, - const char* szDirectory, char** pNZBName, char** pCategory, int* iPriority, - NZBParameterList* pParameters, bool* bAddTop, bool* bAddPaused); + const char* szDirectory, char** pNZBName, char** pCategory, int* iPriority, + NZBParameterList* pParameters, bool* bAddTop, bool* bAddPaused, + char** pDupeKey, int* iDupeScore, EDupeMode* eDupeMode); }; void ScanScriptController::ExecuteScripts(const char* szNZBFilename, - const char* szUrl, const char* szDirectory, char** pNZBName, char** pCategory, - int* iPriority, NZBParameterList* pParameters, bool* bAddTop, bool* bAddPaused) + const char* szUrl, const char* szDirectory, char** pNZBName, char** pCategory, + int* iPriority, NZBParameterList* pParameters, bool* bAddTop, bool* bAddPaused, + char** pDupeKey, int* iDupeScore, EDupeMode* eDupeMode) { ScanScriptController* pScriptController = new ScanScriptController(); @@ -95,6 +100,9 @@ void ScanScriptController::ExecuteScripts(const char* szNZBFilename, pScriptController->m_iPriority = iPriority; pScriptController->m_bAddTop = bAddTop; pScriptController->m_bAddPaused = bAddPaused; + pScriptController->m_pDupeKey = pDupeKey; + pScriptController->m_iDupeScore = iDupeScore; + pScriptController->m_eDupeMode = eDupeMode; pScriptController->m_iPrefixLen = 0; pScriptController->ExecuteScriptList(g_pOptions->GetScanScript()); @@ -139,6 +147,11 @@ void ScanScriptController::PrepareParams(const char* szScriptName) SetIntEnvVar("NZBNP_PRIORITY", *m_iPriority); SetIntEnvVar("NZBNP_TOP", *m_bAddTop ? 1 : 0); SetIntEnvVar("NZBNP_PAUSED", *m_bAddPaused ? 1 : 0); + SetEnvVar("NZBNP_DUPEKEY", *m_pDupeKey); + SetIntEnvVar("NZBNP_DUPESCORE", *m_iDupeScore); + + const char* szDupeModeName[] = { "SCORE", "ALL", "FORCE" }; + SetEnvVar("NZBNP_DUPEMODE", szDupeModeName[*m_eDupeMode]); // remove trailing slash char szDir[1024]; @@ -199,6 +212,26 @@ void ScanScriptController::AddMessage(Message::EKind eKind, const char* szText) { *m_bAddPaused = atoi(szMsgText + 6 + 7) != 0; } + else if (!strncmp(szMsgText + 6, "DUPEKEY=", 8)) + { + free(*m_pDupeKey); + *m_pDupeKey = strdup(szMsgText + 6 + 8); + } + else if (!strncmp(szMsgText + 6, "DUPESCORE=", 10)) + { + *m_iDupeScore = atoi(szMsgText + 6 + 10); + } + else if (!strncmp(szMsgText + 6, "DUPEMODE=", 9)) + { + const char* szDupeMode = szMsgText + 6 + 9; + if (strcasecmp(szDupeMode, "score") && strcasecmp(szDupeMode, "all") && strcasecmp(szDupeMode, "force")) + { + error("Invalid value \"%s\" for command \"DUPEMODE\" received from %s", szDupeMode, GetInfoName()); + return; + } + *m_eDupeMode = !strcasecmp(szDupeMode, "all") ? dmAll : + !strcasecmp(szDupeMode, "force") ? dmForce : dmScore; + } else { error("Invalid command \"%s\" received from %s", szMsgText, GetInfoName()); @@ -508,7 +541,7 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil int iPriority = 0; bool bAddTop = false; bool bAddPaused = false; - const char* szDupeKey = NULL; + char* szDupeKey = strdup(""); int iDupeScore = 0; EDupeMode eDupeMode = dmScore; EAddStatus eAddStatus = asSkipped; @@ -528,7 +561,8 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil free(szNZBCategory); szNZBCategory = strdup(pQueueData->GetCategory()); iPriority = pQueueData->GetPriority(); - szDupeKey = pQueueData->GetDupeKey(); + free(szDupeKey); + szDupeKey = strdup(pQueueData->GetDupeKey()); iDupeScore = pQueueData->GetDupeScore(); eDupeMode = pQueueData->GetDupeMode(); bAddTop = pQueueData->GetAddTop(); @@ -546,7 +580,8 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil { ScanScriptController::ExecuteScripts(szFullFilename, pUrlInfo ? pUrlInfo->GetURL() : "", szDirectory, - &szNZBName, &szNZBCategory, &iPriority, pParameters, &bAddTop, &bAddPaused); + &szNZBName, &szNZBCategory, &iPriority, pParameters, &bAddTop, + &bAddPaused, &szDupeKey, &iDupeScore, &eDupeMode); bExists = Util::FileExists(szFullFilename); if (bExists && strcasecmp(szExtension, ".nzb")) { @@ -586,6 +621,7 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil free(szNZBName); free(szNZBCategory); + free(szDupeKey); if (pQueueData) { diff --git a/nzbget.conf b/nzbget.conf index c76b4538..68d12bcc 100644 --- a/nzbget.conf +++ b/nzbget.conf @@ -1448,7 +1448,10 @@ PostScript= # NZBNP_TOP - flag indicating that the file will be added to the top # of queue: 0 or 1; # NZBNP_PAUSED - flag indicating that the file will be added as -# paused: 0 or 1. +# paused: 0 or 1; +# NZBNP_DUPEKEY - duplicate key of nzb-file; +# NZBNP_DUPESCORE - duplicate score of nzb-file; +# NZBNP_DUPEMODE - duplicate mode of nzb-file: SCORE, ALL, FORCE. # # In addition to these arguments NZBGet passes all nzbget.conf-options # as environment variables. These variables have prefix "NZBOP_" and @@ -1503,6 +1506,15 @@ PostScript= # To change paused-flag (nzb-file will be added in paused state): # echo "[NZB] PAUSED=1"; # +# To change duplicate key: +# echo "[NZB] DUPEKEY=tv show s01e02"; +# +# To change duplicate score: +# echo "[NZB] DUPESCORE=integer_value"; +# +# To change duplicate mode: +# echo "[NZB] DUPEMODE=(SCORE|ALL|FORCE)"; +# # The script can delete processed file, rename it or move somewhere. # After the calling of the script the file will be either added to queue # (if it was an nzb-file) or renamed by adding the extension ".processed".