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 | |
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.
-rw-r--r-- | archiveview.cpp | 4 | ||||
-rw-r--r-- | archiveview.h | 1 | ||||
-rw-r--r-- | fswidget.cpp | 54 | ||||
-rw-r--r-- | fswidget.h | 3 | ||||
-rw-r--r-- | moviemetadatapage.cpp | 4 | ||||
-rw-r--r-- | moviemetadatapage.h | 2 | ||||
-rw-r--r-- | newmoviewizard.h | 1 |
7 files changed, 69 insertions, 0 deletions
diff --git a/archiveview.cpp b/archiveview.cpp index d665da2..a494231 100644 --- a/archiveview.cpp +++ b/archiveview.cpp @@ -240,6 +240,10 @@ void MetadataEditorWidget::addToComment(const QString &reason){ mComment->append(reason); } +void MetadataEditorWidget::replaceSubject(const QString &subject){ + mSubject->setText(subject); +} + /* Metadata Editor */ MetadataEditor::MetadataEditor(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ mWidget = new MetadataEditorWidget; diff --git a/archiveview.h b/archiveview.h index 13b572a..2e3171a 100644 --- a/archiveview.h +++ b/archiveview.h @@ -85,6 +85,7 @@ class MetadataEditorWidget : public QWidget { explicit MetadataEditorWidget(QWidget *parent = nullptr); void setMetadata(const QList<QVariant> &data); QList<QVariant> metadata() const; + void replaceSubject(const QString &subject); signals: void oldSelected(const QString &); 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(); @@ -12,6 +12,7 @@ class QSortFilterProxyModel; class QContextMenuEvent; class QAction; class QProcess; +class QDir; class NewMovieWizard; class NewPicsDialog; class Viewer; @@ -61,6 +62,8 @@ class FSWidget : public QWidget { private: void setupWidget(); + const QStringList readDescript(const QDir &dir); + const QString guessSubject(const QStringList &subjects, const QString &fn); QComboBox *mDirCB; QComboBox *mFilterCB; QProcess *mPlayer; diff --git a/moviemetadatapage.cpp b/moviemetadatapage.cpp index 5bf7651..597ea85 100644 --- a/moviemetadatapage.cpp +++ b/moviemetadatapage.cpp @@ -39,3 +39,7 @@ void MovieMetadataPage::initializePage(){ mWidget->setMetadata(curMetadata); } } + +void MovieMetadataPage::setGuessedSubject(const QString subject){ + mWidget->replaceSubject(subject); +} diff --git a/moviemetadatapage.h b/moviemetadatapage.h index a6cae80..6fccee9 100644 --- a/moviemetadatapage.h +++ b/moviemetadatapage.h @@ -19,12 +19,14 @@ class MovieMetadataPage : public QWizardPage { explicit MovieMetadataPage(QWidget *parent = nullptr); MetadataEditorWidget *widget() { return mWidget; } virtual void initializePage(); + virtual void setGuessedSubject(const QString subject); private: void setupGui(); /* defined in archiveview.h */ MetadataEditorWidget *mWidget; QCheckBox *mMetadataEnabled; + QString mGuessedSubject; }; #endif // MOVIEMETADATAPAGE_H diff --git a/newmoviewizard.h b/newmoviewizard.h index 5d84928..aef50f5 100644 --- a/newmoviewizard.h +++ b/newmoviewizard.h @@ -23,6 +23,7 @@ class NewMovieWizard : public QWizard { MovieInfoPage *infoPage() { return mInfoPage; } MovieMappingPage *actorPage() { return mActorPage; } MovieMappingPage *genrePage() { return mGenrePage; } + MovieMetadataPage *metadataPage() { return mMetadataPage; } private: MovieInfoPage *mInfoPage; |