diff --git a/ChangeLog b/ChangeLog index 3adbc039..8e7abe94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -64,6 +64,8 @@ nzbget-0.3.1: - Added remote-command "-V (--serverversion)" to print the server's version; - Added option "ThreadLimit" to prevent program from crash if it wants to create too many threads (sometimes could occur in special cases); + - Added options "NzbDirInterval" and "NzbDirFileAge" to adjust interval and + delay by monitoring of incoming-directory for new nzb-files; - Fixed error on parsing of nzb-files containing percent and other special characters in their names (bug appeared on windows only); - Reformated sample configuration file and changed default optionnames diff --git a/Options.cpp b/Options.cpp index 374c4aa8..3f62efd2 100644 --- a/Options.cpp +++ b/Options.cpp @@ -130,6 +130,8 @@ static const char* OPTION_RETRYONCRCERROR = "RetryOnCrcError"; static const char* OPTION_THREADLIMIT = "ThreadLimit"; static const char* OPTION_DIRECTWRITE = "DirectWrite"; static const char* OPTION_WRITEBUFFERSIZE = "WriteBufferSize"; +static const char* OPTION_NZBDIRINTERVAL = "NzbDirInterval"; +static const char* OPTION_NZBDIRFILEAGE = "NzbDirFileAge"; #ifndef WIN32 const char* PossibleConfigLocations[] = @@ -207,6 +209,9 @@ Options::Options(int argc, char* argv[]) m_bRetryOnCrcError = false; m_bDirectWrite = false; m_iThreadLimit = 0; + m_iWriteBufferSize = 0; + m_iNzbDirInterval = 0; + m_iNzbDirFileAge = 0; char szFilename[MAX_PATH + 1]; #ifdef WIN32 @@ -396,6 +401,8 @@ void Options::InitDefault() SetOption(OPTION_THREADLIMIT, "100"); SetOption(OPTION_DIRECTWRITE, "no"); SetOption(OPTION_WRITEBUFFERSIZE, "0"); + SetOption(OPTION_NZBDIRINTERVAL, "5"); + SetOption(OPTION_NZBDIRFILEAGE, "60"); } void Options::InitOptFile() @@ -488,7 +495,7 @@ void Options::InitOptions() CheckDir(&m_szDestDir, OPTION_DESTDIR); CheckDir(&m_szTempDir, OPTION_TEMPDIR); CheckDir(&m_szQueueDir, OPTION_QUEUEDIR); - m_szNzbDir = strdup(GetOption(OPTION_NZBDIR)); + m_szPostProcess = strdup(GetOption(OPTION_POSTPROCESS)); m_fDownloadRate = (float)atof(GetOption(OPTION_DOWNLOADRATE)); @@ -507,6 +514,13 @@ void Options::InitOptions() m_iUpdateInterval = atoi(GetOption(OPTION_UPDATEINTERVAL)); m_iThreadLimit = atoi(GetOption(OPTION_THREADLIMIT)); m_iWriteBufferSize = atoi(GetOption(OPTION_WRITEBUFFERSIZE)); + m_iNzbDirInterval = atoi(GetOption(OPTION_NZBDIRINTERVAL)); + m_iNzbDirFileAge = atoi(GetOption(OPTION_NZBDIRFILEAGE)); + + if (m_iNzbDirInterval > 0) + { + CheckDir(&m_szNzbDir, OPTION_NZBDIR); + } const char* BoolNames[] = { "yes", "no", "true", "false", "1", "0", "on", "off", "enable", "disable" }; const int BoolValues[] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; diff --git a/Options.h b/Options.h index 6e274e3c..ffa6028f 100644 --- a/Options.h +++ b/Options.h @@ -131,6 +131,8 @@ private: int m_iThreadLimit; bool m_bDirectWrite; int m_iWriteBufferSize; + int m_iNzbDirInterval; + int m_iNzbDirFileAge; // Parsed command-line parameters bool m_bServerMode; @@ -171,8 +173,8 @@ private: void ParseFileIDList(int argc, char* argv[], int optind); public: - Options(int argc, char* argv[]); - ~Options(); + Options(int argc, char* argv[]); + ~Options(); // Options const char* GetDestDir() { return m_szDestDir; } @@ -220,6 +222,8 @@ public: int GetThreadLimit() { return m_iThreadLimit; } bool GetDirectWrite() { return m_bDirectWrite; } int GetWriteBufferSize() { return m_iWriteBufferSize; } + int GetNzbDirInterval() { return m_iNzbDirInterval; } + int GetNzbDirFileAge() { return m_iNzbDirFileAge; } // Parsed command-line parameters bool GetServerMode() { return m_bServerMode; } diff --git a/PrePostProcessor.cpp b/PrePostProcessor.cpp index e5ab1ed2..598878fd 100644 --- a/PrePostProcessor.cpp +++ b/PrePostProcessor.cpp @@ -83,8 +83,6 @@ PrePostProcessor::PrePostProcessor() { debug("Creating PrePostProcessor"); - struct stat buffer; - m_bCheckIncomingNZBs = !stat(g_pOptions->GetNzbDir(), &buffer) && S_ISDIR(buffer.st_mode); m_bHasMoreJobs = false; m_QueueCoordinatorObserver.owner = this; @@ -118,9 +116,10 @@ void PrePostProcessor::Run() #endif while (!IsStopped()) { - if (m_bCheckIncomingNZBs && iNZBDirInterval == 5000) + if (g_pOptions->GetNzbDir() && g_pOptions->GetNzbDirInterval() > 0 && + iNZBDirInterval == g_pOptions->GetNzbDirInterval() * 1000) { - // check nzbdir every 5 seconds + // check nzbdir every g_pOptions->GetNzbDirInterval() seconds CheckIncomingNZBs(); iNZBDirInterval = 0; } @@ -249,10 +248,10 @@ void PrePostProcessor::CheckIncomingNZBs() snprintf(fullfilename, 1024, "%s%c%s", g_pOptions->GetNzbDir(), (int)PATH_SEPARATOR, filename); fullfilename[1024-1] = '\0'; if (!stat(fullfilename, &buffer) && - time(NULL) - buffer.st_mtime > 60 && - time(NULL) - buffer.st_ctime > 60) + time(NULL) - buffer.st_mtime > g_pOptions->GetNzbDirFileAge() && + time(NULL) - buffer.st_ctime > g_pOptions->GetNzbDirFileAge()) { - // the file is at least 60 seconds old, we can process it + // the file is at least g_pOptions->GetNzbDirFileAge() seconds old, we can process it info("Collection %s found", filename); char bakname[1024]; if (g_pQueueCoordinator->AddFileToQueue(fullfilename)) diff --git a/PrePostProcessor.h b/PrePostProcessor.h index fdc79f1d..ee53865b 100644 --- a/PrePostProcessor.h +++ b/PrePostProcessor.h @@ -76,7 +76,6 @@ private: #endif private: - bool m_bCheckIncomingNZBs; QueueCoordinatorObserver m_QueueCoordinatorObserver; bool m_bHasMoreJobs; diff --git a/nzbget.conf.example b/nzbget.conf.example index a0a0c3fb..0c3b9411 100644 --- a/nzbget.conf.example +++ b/nzbget.conf.example @@ -128,6 +128,18 @@ ContinuePartial=yes # Create subdirectory with nzb-filename in destination-directory (yes, no) AppendNzbDir=yes +# How often incoming-directory (option "NzbDir") must be checked for new +# nzb-files, in seconds. +# Value "0" disables the check. +NzbDirInterval=5 + +# How old nzb-file should at least be for it to be loaded to queue, in seconds. +# Nzbget checks if nzb-file was not modified in last few seconds, defined by +# this option. That safety interval prevents the loading of files, which +# were not yet completely saved to disk, for example if they are still being +# downloaded in web-browser. +NzbDirFileAge=60 + # Check for duplicate files (yes, no) # If this option is enabled the program checks by adding of a new nzb-file: # 1) if nzb-file contains duplicate entries. This check aims on detecting @@ -146,11 +158,6 @@ DupeCheck=no # Do not activate this option if par-check is enabled. RenameBroken=no -# Create a log of all broken files (yes ,no) -# It is a text file placed near downloaded files, which contains -# the names of broken files -CreateBrokenLog=yes - # Determine how the articles should be decoded (yenc, uulib, none) # yenc - use internal yEnc-Decoder. Supports only yEnc-format, but is # very fast and does not create temporary files with articles' text @@ -271,6 +278,11 @@ DebugTarget=both # Number of messages stored in buffer and available for remote clients LogBufferSize=1000 +# Create a log of all broken files (yes ,no) +# It is a text file placed near downloaded files, which contains +# the names of broken files +CreateBrokenLog=yes + # See also option "logfile" in secion "PATHS"