Skip to content

Commit

Permalink
Support language codes in file names while batch-downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sum-duma committed Jul 28, 2020
1 parent 66f26e0 commit 7a35ffd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions gui/src/forms/frmscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ void frmScan::accept() {
QDialog::accept();
}

ScanFilesThread::ScanFilesThread() : staticConfig(LibQNapi::staticConfig()) {}
ScanFilesThread::ScanFilesThread()
: subExtensionFilters(LibQNapi::staticConfig()->subtitleExtensionsFilter()
.split(" ")),
subLangFilter("^()|(\\.[a-z][a-z][a-z]?)$",
QRegularExpression::CaseInsensitiveOption) {}

void ScanFilesThread::run() {
abort = false;
Expand Down Expand Up @@ -264,6 +268,14 @@ bool ScanFilesThread::doScan(const QString &path, QDir::Filters filters) {

emit folderChange(myPath);

QStringList subtitlesBaseNames;
if (skipIfSubtitlesExists) {
for (const auto &s : QDir(myPath).entryInfoList(subExtensionFilters,
QDir::Files | QDir::Hidden)) {
subtitlesBaseNames << s.completeBaseName();
}
}

QFileInfoList list = QDir(myPath).entryInfoList(scanFilters, filters);

for (QFileInfoList::iterator p = list.begin(); p != list.end(); p++) {
Expand All @@ -276,9 +288,10 @@ bool ScanFilesThread::doScan(const QString &path, QDir::Filters filters) {

bool subtitleFileFound = false;
if (skipIfSubtitlesExists) {
foreach (QString subExt, staticConfig->subtitleExtensions()) {
if (QFile::exists((*p).absolutePath() + "/" +
(*p).completeBaseName() + "." + subExt)) {
QString baseName = (*p).completeBaseName();
for (const auto &subBaseName : subtitlesBaseNames) {
if (subBaseName.startsWith(baseName, Qt::CaseInsensitive) &&
subLangFilter.match(subBaseName, baseName.length()).hasMatch()) {
subtitleFileFound = true;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions gui/src/forms/frmscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class ScanFilesThread : public QNapiThread {
private:
bool doScan(const QString &path, QDir::Filters filters);

QSharedPointer<const StaticConfig> staticConfig;
QString searchPath;
QStringList scanFilters, skipFilters;
QStringList scanFilters, skipFilters, subExtensionFilters;
QRegularExpression subLangFilter;
bool skipIfSubtitlesExists, followSymLinks;
QSet<QString> visited;
};
Expand Down

0 comments on commit 7a35ffd

Please sign in to comment.