Ignore:
Timestamp:
Oct 9, 2014, 2:54:21 PM (11 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: updated trunk to 14.9.0

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/findsubtitles/osclient.cpp

    r165 r170  
    2020#include "version.h"
    2121
    22 OSClient::OSClient(QObject* parent) : QObject(parent), logged_in(false), search_size(0) {
     22OSClient::OSClient(QObject* parent) :
     23        QObject(parent)
     24        , logged_in(false)
     25        , search_size(0)
     26#ifdef OS_SEARCH_WORKAROUND
     27        , best_search_count(0)
     28#endif
     29{
    2330        rpc = new MaiaXmlRpcClient(QUrl("http://api.opensubtitles.org/xml-rpc"), this);
    2431}
     
    6673}
    6774
     75#ifdef OS_SEARCH_WORKAROUND
    6876void OSClient::doSearch() {
     77        best_search_count = -1;
     78        for (int n = 1; n < 8; n++) doSearch(n);
     79}
     80
     81void OSClient::doSearch(int nqueries) {
     82#else
     83void OSClient::doSearch() {
     84#endif
    6985        qDebug("OSClient::doSearch");
    7086
     
    7490        m["moviebytesize"] = QString::number(search_size);
    7591
    76         // For some reason it seems opensubtitles fails
    77         // sometimes if there's only one item in the list.
    78         // So as workaround, the item is appended twice.
    79 
    80         // Update: and the opposite, sometimes it doesn't return any
    81         // result with 2 items but it does with 1.
    82         // Workaround: use 3 items... Seems to work in all cases.
    8392        QVariantList list;
     93#ifdef OS_SEARCH_WORKAROUND
     94        // Sometimes opensubtitles return 0 subtitles
     95        // A workaround seems to add the query several times
     96        qDebug("OSClient::doSearch: nqueries: %d", nqueries);
     97        for (int count = 0; count < nqueries; count++) list.append(m);
     98        //qDebug("OSClient::doSearch: list count: %d", list.count());
     99#else
    84100        list.append(m);
    85         list.append(m);
    86         list.append(m);
    87         list.append(m);
    88         //list.append(m);
    89         list.append(m); // Adding more, sometimes it keeps failing...
     101#endif
    90102
    91103        QVariantList args;
     
    148160        QVariantList data = m["data"].toList();
    149161        qDebug("OSClient::responseSearch: data count: %d", data.count());
     162
     163#ifdef OS_SEARCH_WORKAROUND
     164        if (best_search_count >= data.count()) {
     165                qDebug("OSClient::responseSearch: we already have a better search (%d). Ignoring this one.", best_search_count);
     166                return;
     167        }
     168        best_search_count = data.count();
     169#endif
    150170
    151171        for (int n = 0; n < data.count(); n++) {
Note: See TracChangeset for help on using the changeset viewer.