summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-10-01 14:03:24 +0200
committerArno <arno@disconnect.de>2016-10-01 14:03:24 +0200
commit033be9e16598f90d4d86574baf0e00e49763e29c (patch)
tree69a9dcc2fa1c0c53b8ab961a421d571ec30f822b
parentb435f1ecee2202677de3f6fbc294b95a85d4956d (diff)
downloadShemovCleaner-033be9e16598f90d4d86574baf0e00e49763e29c.tar.gz
ShemovCleaner-033be9e16598f90d4d86574baf0e00e49763e29c.tar.bz2
ShemovCleaner-033be9e16598f90d4d86574baf0e00e49763e29c.zip
Add function guessSubtitle
Guess the subtitle from the torrent filename. It's more or less an arbitrary set of strings and regexes that can't be configured.
-rw-r--r--torrentwidget.cpp31
-rw-r--r--torrentwidget.h2
2 files changed, 32 insertions, 1 deletions
diff --git a/torrentwidget.cpp b/torrentwidget.cpp
index 4a1b9b2..9b155cf 100644
--- a/torrentwidget.cpp
+++ b/torrentwidget.cpp
@@ -114,6 +114,9 @@ void TorrentWidget::createActions(){
mCopyFnToClipA = new QAction(QIcon(":/edit-copy.png"), tr("Filename to Clip"), this);
mCopyFnToClipA->setShortcut(tr("CTRL+C"));
connect(mCopyFnToClipA, SIGNAL(triggered()), this, SLOT(copyToClipboard()));
+ mGuessSubtitleA = new QAction(QIcon(":/hourglass_figure.png"), tr("Guess subtitle"), this);
+ mGuessSubtitleA->setShortcut(tr("CTRL+SHIFT+C"));
+ connect(mGuessSubtitleA, SIGNAL(triggered()), this, SLOT(guessSubtitle()));
QMenu *fileMenu = new QMenu(tr("&File"));
fileMenu->addAction(mSelDirA);
@@ -123,6 +126,7 @@ void TorrentWidget::createActions(){
QMenu *editMenu = new QMenu(tr("&Edit"));
editMenu->addAction(mCopyFnToClipA);
+ editMenu->addAction(mGuessSubtitleA);
editMenu->addAction(mMoveA);
editMenu->addAction(mDeleteA);
editMenu->addSeparator();
@@ -137,6 +141,7 @@ void TorrentWidget::createActions(){
mToolBar->addAction(mSelDirA);
mToolBar->addAction(createSeparator());
mToolBar->addAction(mCopyFnToClipA);
+ mToolBar->addAction(mGuessSubtitleA);
mToolBar->addAction(mMoveA);
mToolBar->addAction(mDeleteA);
mToolBar->addAction(createSeparator());
@@ -144,7 +149,7 @@ void TorrentWidget::createActions(){
mToolBar->addAction(createSeparator());
mToolBar->addAction(Globals::instance()->action(Globals::ConfigAction));
- addActions(QList<QAction*>() << mRefreshA << mSelDirA << createSeparator() << mCopyFnToClipA << mMoveA << mDeleteA << createSeparator() << mTorrentInfoA);
+ addActions(QList<QAction*>() << mRefreshA << mSelDirA << createSeparator() << mCopyFnToClipA << mGuessSubtitleA << mMoveA << mDeleteA << createSeparator() << mTorrentInfoA);
}
void TorrentWidget::gatherData(){
@@ -372,6 +377,30 @@ void TorrentWidget::selectFirst(){
}
}
+void TorrentWidget::guessSubtitle(){
+ QModelIndex cur = mFileView->selectionModel()->currentIndex();
+ QClipboard *clip = QApplication::clipboard();
+ QString curName = cur.data().toString().toLower();
+ QRegExp re1(" *\\[.*\\] *");
+ re1.setMinimal(true);
+ curName.replace(re1, "");
+ QRegExp re2(" *\\(.*\\) *");
+ re2.setMinimal(true);
+ curName.replace(re2, "");
+ QRegExp re3("\\s+");
+ curName.replace(re3, " ");
+ curName.replace(".torrent", "");
+ curName = curName.trimmed();
+ QRegExp re4("^shemale\\s*-*");
+ curName.replace(re4, "");
+ QRegExp re5("(\\.mp\\d|rq|\\s*720p|\\s*1080p)");
+ curName.replace(re5, "");
+ curName = curName.trimmed();
+ clip->setText(curName);
+ QString msg = QString(tr("Copied \"%1\" to Clipboard")).arg(curName);
+ emit statusMessage(msg);
+}
+
void TorrentWidget::readSettings(){
QSettings s;
QString dir = s.value("searchdir", QDir::toNativeSeparators(QDir::homePath())).toString();
diff --git a/torrentwidget.h b/torrentwidget.h
index b66fa64..d672398 100644
--- a/torrentwidget.h
+++ b/torrentwidget.h
@@ -47,6 +47,7 @@ class TorrentWidget : public QWidget {
void searchFile();
void fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void selectFirst();
+ void guessSubtitle();
protected:
virtual void keyPressEvent(QKeyEvent *e);
@@ -76,6 +77,7 @@ class TorrentWidget : public QWidget {
QAction *mTorrentInfoA;
QAction *mSelDirA;
QAction *mCopyFnToClipA;
+ QAction *mGuessSubtitleA;
FileSorter *mProxy;
TorrentDisplay *mTorrentDisplay;
};