Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/clisubtitlesdownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int finishSubtitles(int selIdx, const Console& c, QNapi& napi) {
}

c.printLineOrdinary(tr("Adjusting subtitles..."));
if (!napi.matchSubtitles()) {
if (!napi.matchSubtitles(selIdx)) {
c.printLineError(tr("Could not adjust subtitles!"));
return EC_COULD_NOT_MATCH;
}
Expand Down
2 changes: 1 addition & 1 deletion gui/src/forms/frmprogress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void GetThread::run() {
emit progressChange(i, queue.size(), 0.9f);
emit actionChange(tr("Adjusting subtitles..."));

if (!napi.matchSubtitles()) {
if (!napi.matchSubtitles(selIdx)) {
ABORT_POINT

++napiFail;
Expand Down
8 changes: 6 additions & 2 deletions gui/src/forms/frmscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ void frmScan::accept() {
QDialog::accept();
}

ScanFilesThread::ScanFilesThread() : staticConfig(LibQNapi::staticConfig()) {}
ScanFilesThread::ScanFilesThread() : staticConfig(LibQNapi::staticConfig()) {
const QNapiConfig config = LibQNapi::loadConfig();
langCode = config.generalConfig().language();
}

void ScanFilesThread::run() {
abort = false;
Expand Down Expand Up @@ -278,7 +281,8 @@ bool ScanFilesThread::doScan(const QString &path, QDir::Filters filters) {
if (skipIfSubtitlesExists) {
foreach (QString subExt, staticConfig->subtitleExtensions()) {
if (QFile::exists((*p).absolutePath() + "/" +
(*p).completeBaseName() + "." + subExt)) {
(*p).completeBaseName() +
"." + langCode + "." + subExt)) {
subtitleFileFound = true;
break;
}
Expand Down
1 change: 1 addition & 0 deletions gui/src/forms/frmscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ScanFilesThread : public QNapiThread {
QStringList scanFilters, skipFilters;
bool skipIfSubtitlesExists, followSymLinks;
QSet<QString> visited;
QString langCode;
};

class frmScan : public QDialog {
Expand Down
6 changes: 4 additions & 2 deletions libqnapi/src/qnapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ bool QNapi::unpack(int i) {
return currentEngine ? currentEngine->unpack(subtitlesList[i].id) : false;
}

bool QNapi::matchSubtitles() {
bool QNapi::matchSubtitles(int i) {
if (currentEngine) {
QSharedPointer<const SubtitleMatcher> matcher =
LibQNapi::subtitleMatcher(config);
QString lang = subtitlesList[i].lang;
return matcher->matchSubtitles(currentEngine->subtitlesTmp,
currentEngine->movie);
currentEngine->movie,
lang);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion libqnapi/src/qnapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class QNapi {

bool download(int i);
bool unpack(int i);
bool matchSubtitles();
bool matchSubtitles(int i);
void postProcessSubtitles() const;

void cleanup();
Expand Down
10 changes: 5 additions & 5 deletions libqnapi/src/subtitlematcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ SubtitleMatcher::SubtitleMatcher(
subtitleFormatsRegistry(subtitleFormatsRegistry) {}

bool SubtitleMatcher::matchSubtitles(QString subtitlesTmpFilePath,
QString targetMovieFilePath) const {
QString targetMovieFilePath,
QString language) const {
QFileInfo subtitlesTmpFileInfo(subtitlesTmpFilePath);

if (!subtitlesTmpFileInfo.exists()) return false;

QString targetExtension = selectTargetExtension(subtitlesTmpFileInfo);

QString targetSubtitlesFilePath =
constructSubtitlePath(targetMovieFilePath, targetExtension);
constructSubtitlePath(targetMovieFilePath, targetExtension, language);

if (!isWritablePath(targetSubtitlesFilePath)) return false;

removeOrCopy(targetMovieFilePath, targetSubtitlesFilePath);

bool result = false;

#ifdef Q_OS_WIN
Expand Down Expand Up @@ -79,10 +79,10 @@ QString SubtitleMatcher::selectTargetExtension(

QString SubtitleMatcher::constructSubtitlePath(QString targetMovieFilePath,
QString targetExtension,
QString baseSuffix) const {
QString language) const {
QFileInfo targetMovieFileInfo(targetMovieFilePath);
return targetMovieFileInfo.path() + QDir::separator() +
targetMovieFileInfo.completeBaseName() + baseSuffix + "." +
targetMovieFileInfo.completeBaseName() + "." + language + "." +
targetExtension;
}

Expand Down
3 changes: 2 additions & 1 deletion libqnapi/src/subtitlematcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class SubtitleMatcher : public QObject {
&subtitleFormatsRegistry);

bool matchSubtitles(QString subtitlesTmpFilePath,
QString targetMovieFilePath) const;
QString targetMovieFilePath,
QString language) const;

private:
QString selectTargetExtension(QFileInfo subtitlesTmpFileInfo) const;
Expand Down
4 changes: 2 additions & 2 deletions libqnapi/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#ifndef __VERSION__H__
#define __VERSION__H__

#define QNAPI_VERSION "0.2.4"
#define QNAPI_DISPLAYABLE_VERSION "0.2.4-snapshot"
#define QNAPI_VERSION "0.2.5"
#define QNAPI_DISPLAYABLE_VERSION "0.2.5-snapshot"
#define QNAPI_URL "http://qnapi.github.io"

#endif