diff options
author | Mateusz Łukasik <mati75@linuxmint.pl> | 2014-09-10 13:50:41 +0200 |
---|---|---|
committer | Mateusz Łukasik <mati75@linuxmint.pl> | 2014-09-10 13:50:41 +0200 |
commit | 2d547200175bcaefcbca0862f8e0395e42c96224 (patch) | |
tree | d2d8508074c5035a8c5af248e147655cdeb0a1cb /src/findsubtitles | |
parent | 02af8398ac9a1089a7fe9efda615a771e1c13637 (diff) |
Imported Upstream version 14.9.0
Diffstat (limited to 'src/findsubtitles')
-rw-r--r-- | src/findsubtitles/findsubtitleswindow.cpp | 4 | ||||
-rw-r--r-- | src/findsubtitles/osclient.cpp | 46 | ||||
-rw-r--r-- | src/findsubtitles/osclient.h | 8 |
3 files changed, 43 insertions, 15 deletions
diff --git a/src/findsubtitles/findsubtitleswindow.cpp b/src/findsubtitles/findsubtitleswindow.cpp index 7381fdf..b7593d5 100644 --- a/src/findsubtitles/findsubtitleswindow.cpp +++ b/src/findsubtitles/findsubtitleswindow.cpp @@ -415,8 +415,8 @@ void FindSubtitlesWindow::parseInfo() { status->setText( tr("%1 files available").arg(l.count()) ); applyCurrentFilter(); - qDebug("sort column: %d", view->header()->sortIndicatorSection()); - qDebug("sort indicator: %d", view->header()->sortIndicatorOrder()); + qDebug("FindSubtitlesWindow::parseInfo: sort column: %d", view->header()->sortIndicatorSection()); + qDebug("FindSubtitlesWindow::parseInfo: sort indicator: %d", view->header()->sortIndicatorOrder()); table->sort( view->header()->sortIndicatorSection(), view->header()->sortIndicatorOrder() ); diff --git a/src/findsubtitles/osclient.cpp b/src/findsubtitles/osclient.cpp index 22d98a7..ddb3581 100644 --- a/src/findsubtitles/osclient.cpp +++ b/src/findsubtitles/osclient.cpp @@ -19,7 +19,14 @@ #include "osclient.h" #include "version.h" -OSClient::OSClient(QObject* parent) : QObject(parent), logged_in(false), search_size(0) { +OSClient::OSClient(QObject* parent) : + QObject(parent) + , logged_in(false) + , search_size(0) +#ifdef OS_SEARCH_WORKAROUND + , best_search_count(0) +#endif +{ rpc = new MaiaXmlRpcClient(QUrl("http://api.opensubtitles.org/xml-rpc"), this); } @@ -65,7 +72,16 @@ void OSClient::search(const QString & hash, qint64 file_size) { #endif } +#ifdef OS_SEARCH_WORKAROUND +void OSClient::doSearch() { + best_search_count = -1; + for (int n = 1; n < 8; n++) doSearch(n); +} + +void OSClient::doSearch(int nqueries) { +#else void OSClient::doSearch() { +#endif qDebug("OSClient::doSearch"); QVariantMap m; @@ -73,20 +89,16 @@ void OSClient::doSearch() { m["moviehash"] = search_hash; m["moviebytesize"] = QString::number(search_size); - // For some reason it seems opensubtitles fails - // sometimes if there's only one item in the list. - // So as workaround, the item is appended twice. - - // Update: and the opposite, sometimes it doesn't return any - // result with 2 items but it does with 1. - // Workaround: use 3 items... Seems to work in all cases. QVariantList list; +#ifdef OS_SEARCH_WORKAROUND + // Sometimes opensubtitles return 0 subtitles + // A workaround seems to add the query several times + qDebug("OSClient::doSearch: nqueries: %d", nqueries); + for (int count = 0; count < nqueries; count++) list.append(m); + //qDebug("OSClient::doSearch: list count: %d", list.count()); +#else list.append(m); - list.append(m); - list.append(m); - list.append(m); - //list.append(m); - list.append(m); // Adding more, sometimes it keeps failing... +#endif QVariantList args; args << token << QVariant(list); @@ -148,6 +160,14 @@ void OSClient::responseSearch(QVariant &arg) { QVariantList data = m["data"].toList(); qDebug("OSClient::responseSearch: data count: %d", data.count()); +#ifdef OS_SEARCH_WORKAROUND + if (best_search_count >= data.count()) { + qDebug("OSClient::responseSearch: we already have a better search (%d). Ignoring this one.", best_search_count); + return; + } + best_search_count = data.count(); +#endif + for (int n = 0; n < data.count(); n++) { OSSubtitle sub; diff --git a/src/findsubtitles/osclient.h b/src/findsubtitles/osclient.h index 145bdc4..e961ec6 100644 --- a/src/findsubtitles/osclient.h +++ b/src/findsubtitles/osclient.h @@ -21,6 +21,8 @@ #include "maiaXmlRpcClient.h" +#define OS_SEARCH_WORKAROUND + class OSSubtitle { public: QString movie, releasename, link, iso639, language, date; @@ -42,6 +44,9 @@ public slots: private slots: void login(); void doSearch(); +#ifdef OS_SEARCH_WORKAROUND + void doSearch(int nqueries); +#endif void gotFault(int, const QString &); @@ -61,6 +66,9 @@ private: bool logged_in; QString search_hash; qint64 search_size; +#ifdef OS_SEARCH_WORKAROUND + int best_search_count; +#endif QList <OSSubtitle> s_list; }; |