Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
fixed #171: queue-scripts not called for failed URLs
Browse files Browse the repository at this point in the history
if the scripts were set in category’s option “PostScript”.
  • Loading branch information
hugbug committed Feb 18, 2016
1 parent b5dae56 commit 9dfa66a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 48 deletions.
123 changes: 75 additions & 48 deletions daemon/extension/QueueScript.cpp
Expand Up @@ -313,54 +313,7 @@ void QueueScriptCoordinator::EnqueueScript(NzbInfo* nzbInfo, EEvent event)

for (ScriptConfig::Script& script : g_ScriptConfig->GetScripts())
{
if (!script.GetQueueScript())
{
continue;
}

bool useScript = false;

// check queue-scripts
const char* queueScript = g_Options->GetQueueScript();
if (!Util::EmptyStr(queueScript))
{
// split szQueueScript into tokens
Tokenizer tok(queueScript, ",;");
while (const char* scriptName = tok.Next())
{
if (FileSystem::SameFilename(scriptName, script.GetName()))
{
useScript = true;
break;
}
}
}

// check post-processing-scripts
if (!useScript)
{
for (NzbParameter& parameter : nzbInfo->GetParameters())
{
const char* varname = parameter.GetName();
if (strlen(varname) > 0 && varname[0] != '*' && varname[strlen(varname)-1] == ':' &&
(!strcasecmp(parameter.GetValue(), "yes") ||
!strcasecmp(parameter.GetValue(), "on") ||
!strcasecmp(parameter.GetValue(), "1")))
{
BString<1024> scriptName = varname;
scriptName[strlen(scriptName)-1] = '\0'; // remove trailing ':'
if (FileSystem::SameFilename(scriptName, script.GetName()))
{
useScript = true;
break;
}
}
}
}

useScript &= Util::EmptyStr(script.GetQueueEvents()) || strstr(script.GetQueueEvents(), QUEUE_EVENT_NAMES[event]);

if (useScript)
if (UsableScript(script, nzbInfo, event))
{
bool alreadyQueued = false;
if (event == qeFileDownloaded)
Expand Down Expand Up @@ -396,6 +349,80 @@ void QueueScriptCoordinator::EnqueueScript(NzbInfo* nzbInfo, EEvent event)
m_queueMutex.Unlock();
}

bool QueueScriptCoordinator::UsableScript(ScriptConfig::Script& script, NzbInfo* nzbInfo, EEvent event)
{
if (!script.GetQueueScript())
{
return false;
}

if (!Util::EmptyStr(script.GetQueueEvents()) && !strstr(script.GetQueueEvents(), QUEUE_EVENT_NAMES[event]))
{
return false;
}

// check queue-scripts
const char* queueScript = g_Options->GetQueueScript();
if (!Util::EmptyStr(queueScript))
{
Tokenizer tok(queueScript, ",;");
while (const char* scriptName = tok.Next())
{
if (FileSystem::SameFilename(scriptName, script.GetName()))
{
return true;
}
}
}

// check post-processing-scripts assigned for that nzb
for (NzbParameter& parameter : nzbInfo->GetParameters())
{
const char* varname = parameter.GetName();
if (strlen(varname) > 0 && varname[0] != '*' && varname[strlen(varname)-1] == ':' &&
(!strcasecmp(parameter.GetValue(), "yes") ||
!strcasecmp(parameter.GetValue(), "on") ||
!strcasecmp(parameter.GetValue(), "1")))
{
BString<1024> scriptName = varname;
scriptName[strlen(scriptName)-1] = '\0'; // remove trailing ':'
if (FileSystem::SameFilename(scriptName, script.GetName()))
{
return true;
}
}
}

// for URL-events the post-processing scripts are not assigned yet;
// instead we take the default post-processing scripts for the category (or global)
if (event == qeUrlCompleted)
{
const char* postScript = g_Options->GetPostScript();
if (!Util::EmptyStr(nzbInfo->GetCategory()))
{
Options::Category* categoryObj = g_Options->FindCategory(nzbInfo->GetCategory(), false);
if (categoryObj && !Util::EmptyStr(categoryObj->GetPostScript()))
{
postScript = categoryObj->GetPostScript();
}
}

if (!Util::EmptyStr(postScript))
{
Tokenizer tok(postScript, ",;");
while (const char* scriptName = tok.Next())
{
if (FileSystem::SameFilename(scriptName, script.GetName()))
{
return true;
}
}
}
}

return false;
}

NzbInfo* QueueScriptCoordinator::FindNzbInfo(DownloadQueue* downloadQueue, int nzbId)
{
NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(nzbId);
Expand Down
1 change: 1 addition & 0 deletions daemon/extension/QueueScript.h
Expand Up @@ -65,6 +65,7 @@ class QueueScriptCoordinator

void StartScript(NzbInfo* nzbInfo, QueueItem* queueItem);
NzbInfo* FindNzbInfo(DownloadQueue* downloadQueue, int nzbId);
bool UsableScript(ScriptConfig::Script& script, NzbInfo* nzbInfo, EEvent event);

public:
QueueScriptCoordinator();
Expand Down

0 comments on commit 9dfa66a

Please sign in to comment.