diff options
author | Arno <arno@disconnect.de> | 2020-07-19 12:12:10 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2020-07-19 12:12:10 +0200 |
commit | ff672bb48ecd0f0aa6884628a0ceeac5b50a75a8 (patch) | |
tree | 3b93da494bd181e6a42e373d06677f1401ef3a77 /fswidget.cpp | |
parent | d6c44146adfd534548c985bd7299f94f66e57acd (diff) | |
download | SheMov-ff672bb48ecd0f0aa6884628a0ceeac5b50a75a8.tar.gz SheMov-ff672bb48ecd0f0aa6884628a0ceeac5b50a75a8.tar.bz2 SheMov-ff672bb48ecd0f0aa6884628a0ceeac5b50a75a8.zip |
Guess subject from descript.ion file
The expression matching is the same as in ShemovCleaner, but here we
have a lot more levels of indirection. The guessing is done
automatically when archiveMovie is invoked. If the directory contains a
file descript.ion, it is parsed and the result injected into the
MetadataEditorWidget.
Diffstat (limited to 'fswidget.cpp')
-rw-r--r-- | fswidget.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/fswidget.cpp b/fswidget.cpp index 8918577..10cea04 100644 --- a/fswidget.cpp +++ b/fswidget.cpp @@ -21,12 +21,14 @@ #include <QApplication> #include <QMediaPlayer> #include <QMediaPlaylist> +#include <QStringList> #include "fswidget.h" #include "helper.h" #include "smglobals.h" #include "newmoviewizard.h" #include "movieinfopage.h" +#include "moviemetadatapage.h" #include "newpicsdialog.h" #include "fsproxy.h" #include "smview.h" @@ -219,6 +221,50 @@ FSWidget::~FSWidget(){ writeSettings(); } +const QStringList FSWidget::readDescript(const QDir &dir){ + QStringList retval; + QString fileName = dir.absoluteFilePath("descript.ion"); + QFile descFile(fileName); + if(descFile.open(QFile::ReadOnly)){ + QTextStream in(&descFile); + QString line; + while(in.readLineInto(&line)){ + if(line.contains("yEnc,")){ + QString part = line.left(line.indexOf("yEnc,") + 4); + retval << part; + }else{ + QStringList parts = line.split(','); + if(!parts.isEmpty()){ + retval << parts.at(0); + } + } + } + } + return retval; +} + +const QString FSWidget::guessSubject(const QStringList &subjects, const QString &fn){ + QString fRe = QRegularExpression::escape(fn); + const QRegularExpression fnRe(fRe); + QRegularExpressionMatch m; + for(QString s : subjects){ + m = fnRe.match(s); + if(m.hasMatch()){ + QString subject; + if(s.startsWith('"')){ + int nextQuot = s.indexOf('"', 1); + if(nextQuot > -1){ + subject = s.remove(0, nextQuot + 1).trimmed(); + } + } + subject.replace(QRegularExpression("\\d+$"), ""); + subject = subject.trimmed(); + return subject; + } + } + return QString(); +} + void FSWidget::readSettings(){ QSettings s; QStringList dirs = s.value("fs/dirs").toStringList(); @@ -473,6 +519,14 @@ void FSWidget::archiveMovie(){ mMovieWizard->infoPage()->addFile(path); mMovieWizard->infoPage()->guessOld(path); } + if(!selected.isEmpty()){ + QString fn = selected.at(0).data(FullPathRole).toString(); + QFileInfo fi(fn); + fn = fi.completeBaseName(); + QStringList subjects = readDescript(fi.dir()); + QString subject = guessSubject(subjects, fn); + mMovieWizard->metadataPage()->setGuessedSubject(subject); + } QSettings s; bool autoAddCovers = s.value("ui/autoaddcovers", false).toBool(); QString coverPath = s.value("paths/coverpath").toString(); |