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

Commit

Permalink
#361: new option "FileNaming"
Browse files Browse the repository at this point in the history
replace pp-parameter “*naming”.
  • Loading branch information
hugbug committed Apr 30, 2017
1 parent 93dc1db commit 7c9b392
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions daemon/main/Options.cpp
Expand Up @@ -93,6 +93,7 @@ static const char* OPTION_PARREPAIR = "ParRepair";
static const char* OPTION_PARSCAN = "ParScan";
static const char* OPTION_PARQUICK = "ParQuick";
static const char* OPTION_POSTSTRATEGY = "PostStrategy";
static const char* OPTION_FILENAMING = "FileNaming";
static const char* OPTION_PARRENAME = "ParRename";
static const char* OPTION_PARBUFFER = "ParBuffer";
static const char* OPTION_PARTHREADS = "ParThreads";
Expand Down Expand Up @@ -464,6 +465,7 @@ void Options::InitDefaults()
SetOption(OPTION_PARSCAN, "extended");
SetOption(OPTION_PARQUICK, "yes");
SetOption(OPTION_POSTSTRATEGY, "sequential");
SetOption(OPTION_FILENAMING, "article");
SetOption(OPTION_PARRENAME, "yes");
SetOption(OPTION_PARBUFFER, "16");
SetOption(OPTION_PARTHREADS, "1");
Expand Down Expand Up @@ -775,6 +777,11 @@ void Options::InitOptions()
const int PostStrategyCount = 4;
m_postStrategy = (EPostStrategy)ParseEnumValue(OPTION_POSTSTRATEGY, PostStrategyCount, PostStrategyNames, PostStrategyValues);

const char* FileNamingNames[] = { "auto", "article", "nzb" };
const int FileNamingValues[] = { nfAuto, nfArticle, nfNzb };
const int FileNamingCount = 4;
m_fileNaming = (EFileNaming)ParseEnumValue(OPTION_FILENAMING, FileNamingCount, FileNamingNames, FileNamingValues);

const char* HealthCheckNames[] = { "pause", "delete", "park", "none" };
const int HealthCheckValues[] = { hcPause, hcDelete, hcPark, hcNone };
const int HealthCheckCount = 4;
Expand Down
8 changes: 8 additions & 0 deletions daemon/main/Options.h
Expand Up @@ -92,6 +92,12 @@ class Options
ppAggressive,
ppRocket
};
enum EFileNaming
{
nfAuto,
nfArticle,
nfNzb
};

class OptEntry
{
Expand Down Expand Up @@ -294,6 +300,7 @@ class Options
int GetDailyQuota() { return m_dailyQuota; }
bool GetDirectRename() { return m_directRename; }
bool GetReorderFiles() { return m_reorderFiles; }
EFileNaming GetFileNaming() { return m_fileNaming; }

Categories* GetCategories() { return &m_categories; }
Category* FindCategory(const char* name, bool searchAliases) { return m_categories.FindCategory(name, searchAliases); }
Expand Down Expand Up @@ -444,6 +451,7 @@ class Options
int m_quotaStartDay = 0;
int m_dailyQuota = 0;
bool m_reorderFiles = false;
EFileNaming m_fileNaming = nfArticle;

// Current state
bool m_serverMode = false;
Expand Down
11 changes: 7 additions & 4 deletions daemon/queue/QueueCoordinator.cpp
Expand Up @@ -668,10 +668,13 @@ void QueueCoordinator::ArticleCompleted(ArticleDownloader* articleDownloader)
articleDownloader->GetStatus() == ArticleDownloader::adFinished &&
articleDownloader->GetArticleFilename())
{
// Use file names from article metadata unless explicitly disabled via pp-parameters
NzbParameter* nameParameter = nzbInfo->GetParameters()->Find("*naming", false);
bool useArticleNames = !(nameParameter && !strcasecmp(nameParameter->GetValue(), "nzb"));
if (useArticleNames)
// in "FileNaming=auto"-mode prefer filename from nzb-file to filename read from article
// if the name from article seems to be obfuscated
bool useFilenameFromArticle = g_Options->GetFileNaming() == Options::nfArticle ||
(g_Options->GetFileNaming() == Options::nfAuto &&
!Util::AlphaNum(articleDownloader->GetArticleFilename()) &&
!nzbInfo->GetManyDupeFiles());
if (useFilenameFromArticle)
{
fileInfo->SetFilename(articleDownloader->GetArticleFilename());
fileInfo->MakeValidFilename();
Expand Down
13 changes: 13 additions & 0 deletions daemon/util/Util.cpp
Expand Up @@ -452,6 +452,19 @@ bool Util::EndsWith(const char* str, const char* suffix)
return !strcmp(str + lenStr - lenSuf, suffix);
}

bool Util::AlphaNum(const char* str)
{
for (const char* p = str; *p; p++)
{
char ch = *p;
if (!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')))
{
return false;
}
}
return true;
}

/* Calculate Hash using Bob Jenkins (1996) algorithm
* http://burtleburtle.net/bob/c/lookup2.c
*/
Expand Down
1 change: 1 addition & 0 deletions daemon/util/Util.h
Expand Up @@ -50,6 +50,7 @@ class Util
static bool EmptyStr(const char* str) { return !str || !*str; }
static std::vector<CString> SplitStr(const char* str, const char* separators);
static bool EndsWith(const char* str, const char* suffix);
static bool AlphaNum(const char* str);

/* replace all occurences of szFrom to szTo in string szStr with a limitation that szTo must be shorter than szFrom */
static char* ReduceStr(char* str, const char* from, const char* to);
Expand Down
11 changes: 11 additions & 0 deletions nzbget.conf
Expand Up @@ -868,6 +868,17 @@ WriteBuffer=0
# slow CPU disabling of CRC-Check may improve performance.
CrcCheck=yes

# How to name downloaded files (auto, article, nzb).
#
# Article - use file names stored in article metadata;
# Nzb - use file names as defined in nzb-file;
# Auto - prefer names from article metadata; for obfuscated files use
# names from nzb-file.
#
# NOTE: This option sets the naming convention for files listed in nzb. It has not
# effect on files extracted from archives.
FileNaming=auto

# Reorder files within nzbs for optimal download order (yes, no).
#
# When nzb-file is added to queue the files listed within nzb can be in a random
Expand Down

0 comments on commit 7c9b392

Please sign in to comment.