Skip to content
Permalink
Browse files

BackendUniversal: Update implementation

  • Loading branch information...
3unjee committed Nov 8, 2019
1 parent bf74460 commit b54e3fe6e14138b75ac66515fcfda089deae4b9b
@@ -195,8 +195,8 @@ else
cp "$MinGW"/libstdc++-6.dll deploy
cp "$MinGW"/libwinpthread-1.dll deploy

#cp "$Qt"/bin/libEGL.dll deploy
#cp "$Qt"/bin/libGLESv2.dll deploy
cp "$Qt"/bin/libEGL.dll deploy
cp "$Qt"/bin/libGLESv2.dll deploy

cp "$Qt"/bin/Qt5Core.dll deploy
cp "$Qt"/bin/Qt5Gui.dll deploy
@@ -94,6 +94,8 @@ WBackendCache::WBackendCache(QObject * parent)
/* Q_INVOKABLE */ WBackendUniversalScript * WBackendCache::getScript(const QString & name,
const QString & data)
{
if (data.isEmpty()) return NULL;

Q_D(WBackendCache);

QHash<QString, WBackendUniversalScript>::iterator i = d->scripts.find(name);
@@ -110,6 +112,13 @@ WBackendCache::WBackendCache(QObject * parent)

WBackendUniversalScript script(data);

if (script.isValid() == false)
{
qWarning("WBackendCache::getScript: Cannot load [%s] script.", name.C_STR);

return NULL;
}

i = d->scripts.insert(name, script);

d->names.append(name);
@@ -122,11 +122,9 @@ WBackendBing::WBackendBing() : WBackendNet(new WBackendBingPrivate(this))
// WBackendNet reimplementation
//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendBing::checkValidUrl(const QString & url) const
/* Q_INVOKABLE virtual */ QString WBackendBing::validate() const
{
QString source = WControllerNetwork::removeUrlPrefix(url);

return source.startsWith("bing.com");
return "^bing.com";
}

//-------------------------------------------------------------------------------------------------
@@ -37,7 +37,7 @@ class SK_BACKEND_EXPORT WBackendBing : public WBackendNet
/* Q_INVOKABLE virtual */ QString getTitle() const;

public: // WBackendNet reimplementation
/* Q_INVOKABLE virtual */ bool checkValidUrl(const QString & url) const;
/* Q_INVOKABLE virtual */ QString validate() const;

//---------------------------------------------------------------------------------------------

@@ -192,17 +192,9 @@ WBackendDailymotion::WBackendDailymotion() : WBackendNet(new WBackendDailymotion

//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendDailymotion::checkValidUrl(const QString & url) const
/* Q_INVOKABLE virtual */ QString WBackendDailymotion::validate() const
{
QString source = WControllerNetwork::removeUrlPrefix(url);

if (source.startsWith("dailymotion.com") || source.startsWith("api.dailymotion.com")
||
source.startsWith("games.dailymotion.com"))
{
return true;
}
else return false;
return "^dailymotion.com|^api.dailymotion.com|^games.dailymotion.com";
}

//-------------------------------------------------------------------------------------------------
@@ -39,7 +39,7 @@ class SK_BACKEND_EXPORT WBackendDailymotion : public WBackendNet
public: // WBackendNet reimplementation
/* Q_INVOKABLE virtual */ bool hasSearch() const;

/* Q_INVOKABLE virtual */ bool checkValidUrl(const QString & url) const;
/* Q_INVOKABLE virtual */ QString validate() const;

/* Q_INVOKABLE virtual */ QString getHost() const;

@@ -119,11 +119,9 @@ WBackendDuckDuckGo::WBackendDuckDuckGo() : WBackendNet(new WBackendDuckDuckGoPri

//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendDuckDuckGo::checkValidUrl(const QString & url) const
/* Q_INVOKABLE virtual */ QString WBackendDuckDuckGo::validate() const
{
QString source = WControllerNetwork::removeUrlPrefix(url);

return source.startsWith("duckduckgo.com");
return "^duckduckgo.com";
}

//-------------------------------------------------------------------------------------------------
@@ -39,7 +39,7 @@ class SK_BACKEND_EXPORT WBackendDuckDuckGo : public WBackendNet
public: // WBackendNet reimplementation
/* Q_INVOKABLE virtual */ bool isSearchEngine() const;

/* Q_INVOKABLE virtual */ bool checkValidUrl(const QString & url) const;
/* Q_INVOKABLE virtual */ QString validate() const;

//---------------------------------------------------------------------------------------------

@@ -192,13 +192,13 @@ WBackendLastFm::WBackendLastFm() : WBackendNet(new WBackendLastFmPrivate(this))

//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendLastFm::checkValidUrl(const QString & url) const
/* Q_INVOKABLE virtual */ QString WBackendLastFm::validate() const
{
QString source = WControllerNetwork::removeUrlPrefix(url);

return source.startsWith("last.fm");
return "^last.fm";
}

//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendLastFm::checkCover(const QString & label,
const QString & q) const
{
@@ -241,11 +241,11 @@ WBackendNetTrack WBackendLastFm::extractTrack(const QByteArray & data,

if (query.id == 1)
{
int index = content.indexOf("id=\"header-expanded-image\"");
int index = content.indexOf("property=\"og:image\"");

if (index == -1) return reply;

QString cover = WControllerNetwork::extractAttribute(content, "src", index);
QString cover = WControllerNetwork::extractAttribute(content, "content", index);

reply.track.setCover(cover);
}
@@ -260,18 +260,18 @@ WBackendNetTrack WBackendLastFm::extractTrack(const QByteArray & data,

foreach (const QString & string, list)
{
QString author = WControllerNetwork::extractAttributeUtf8(string, "title");
int index = string.indexOf("class=\"chartlist-artist\"");

QString author = WControllerNetwork::extractAttributeUtf8(string, "title", index);

QStringList list = d->getList(author);

if (d->match(list, listAuthor))
{
int index = string.indexOf("<span class=\"artist-name-spacer\"");
int index = string.indexOf("class=\"chartlist-name\"");

QString title = WControllerNetwork::extractAttributeUtf8(string, "title", index);

title = title.mid(author.length() + 3);

list = d->getList(title);

if (d->match(list, listTitle))
@@ -39,7 +39,7 @@ class SK_BACKEND_EXPORT WBackendLastFm : public WBackendNet
public: // WBackendNet reimplementation
/* Q_INVOKABLE virtual */ bool isSearchCover() const;

/* Q_INVOKABLE virtual */ bool checkValidUrl(const QString & url) const;
/* Q_INVOKABLE virtual */ QString validate() const;

/* Q_INVOKABLE virtual */ bool checkCover(const QString & label, const QString & q) const;

@@ -114,11 +114,11 @@ void WBackendOpenSubtitlesPrivate::init() {}

QString search = list.last();

int index = Sk::indexAt(search, " ", skip);
int index = Sk::indexSkip(search, " ", skip);

if (index == -1) return;

search = search.mid(0, index - 1);
search = search.mid(0, index);

WBackendOpenSubtitlesPrivate::applyQuery(reply, list.first(), search, query.id + 1);
}
@@ -286,19 +286,19 @@ WBackendOpenSubtitles::WBackendOpenSubtitles()
// WBackendNet reimplementation
//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendOpenSubtitles::checkValidUrl(const QString & url) const
/* Q_INVOKABLE virtual */ QString WBackendOpenSubtitles::validate() const
{
QString source = WControllerNetwork::removeUrlPrefix(url);

return source.startsWith("opensubtitles.org");
return "^opensubtitles.org";
}

//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */
WBackendNetQuery WBackendOpenSubtitles::getQueryItem(const QString & url) const
{
if (checkValidUrl(url) && url.contains("/subtitles/"))
QString source = WControllerNetwork::removeUrlPrefix(url);

if (source.startsWith("opensubtitles.org") && source.contains("/subtitles/"))
{
WBackendNetQuery query;

@@ -324,28 +324,27 @@ WBackendNetQuery WBackendOpenSubtitles::createQuery(const QString & method,
{
WBackendNetQuery query;

if (method == "subtitles")
{
QString language = WBackendOpenSubtitlesPrivate::getLanguage(label);
if (method != "subtitles") return query;

QString search = q.simplified();
QString language = WBackendOpenSubtitlesPrivate::getLanguage(label);

QStringList list;
QString search = q.simplified();

list.append(language);
list.append(search);
QStringList list;

query.url = WBackendOpenSubtitlesPrivate::getUrl(language, search);
list.append(language);
list.append(search);

query.data = list;
query.url = WBackendOpenSubtitlesPrivate::getUrl(language, search);

query.cookies = true;
query.data = list;

// FIXME OpenSubtitles: We have to delay our requests to avoid the captcha.
query.maxHost = 1;
query.delay = BACKENDOPENSUBTITLES_DELAY;
query.timeout = BACKENDOPENSUBTITLES_TIMEOUT;
}
query.cookies = true;

// FIXME OpenSubtitles: We have to delay our requests to avoid the captcha.
query.maxHost = 1;
query.delay = BACKENDOPENSUBTITLES_DELAY;
query.timeout = BACKENDOPENSUBTITLES_TIMEOUT;

return query;
}
@@ -37,7 +37,7 @@ class SK_BACKEND_EXPORT WBackendOpenSubtitles : public WBackendNet
/* Q_INVOKABLE virtual */ QString getTitle() const;

public: // WBackendNet reimplementation
/* Q_INVOKABLE virtual */ bool checkValidUrl(const QString & url) const;
/* Q_INVOKABLE virtual */ QString validate() const;

//---------------------------------------------------------------------------------------------

@@ -175,9 +175,7 @@ bool WBackendSoundCloudPrivate::extractId(const QString & data,

QString WBackendSoundCloudPrivate::extractJson(const QString & data, const QString & id) const
{
int index = data.indexOf("<script>webpackJsonp");

index = data.indexOf("\"id\":" + id, index + 20);
int index = data.indexOf("\"id\":" + id);

return WControllerNetwork::extractJson(data, "data", index + 7);
}
@@ -329,17 +327,9 @@ WBackendSoundCloud::WBackendSoundCloud() : WBackendNet(new WBackendSoundCloudPri

//-------------------------------------------------------------------------------------------------

/* Q_INVOKABLE virtual */ bool WBackendSoundCloud::checkValidUrl(const QString & url) const
/* Q_INVOKABLE virtual */ QString WBackendSoundCloud::validate() const
{
QString source = WControllerNetwork::removeUrlPrefix(url);

if (source.startsWith("soundcloud.com") || source.startsWith("api.soundcloud.com")
||
source.startsWith("a-v2.sndcdn.com"))
{
return true;
}
else return false;
return "^soundcloud.com|^api.soundcloud.com|^a-v2.sndcdn.com";
}

//-------------------------------------------------------------------------------------------------
@@ -557,7 +547,7 @@ WBackendNetSource WBackendSoundCloud::extractSource(const QByteArray & dat

if (query.id == 0)
{
QString json = d->extractJson(content, 67, 2);
QString json = d->extractJson(content, 18, 2);

QString idTrack = WControllerNetwork::extractJsonUtf8(json, "id");

@@ -589,7 +579,7 @@ WBackendNetTrack WBackendSoundCloud::extractTrack(const QByteArray & data,

QString content = Sk::readUtf8(data);

QString json = d->extractJson(content, 67, 2);
QString json = d->extractJson(content, 18, 2);

d->loadTrack(&(reply.track), json);

@@ -636,7 +626,7 @@ WBackendNetPlaylist WBackendSoundCloud::extractPlaylist(const QByteArray &
}
else if (id == 1) // playlist
{
QString json = d->extractJson(content, 84, 2);
QString json = d->extractJson(content, 40, 2);

// NOTE: We have to skip track informations.
int index = json.lastIndexOf("\"kind\":\"track\"");
@@ -664,7 +654,7 @@ WBackendNetPlaylist WBackendSoundCloud::extractPlaylist(const QByteArray &
}
else if (id == 2) // feed
{
QString json = d->extractJson(content, 63, 2);
QString json = d->extractJson(content, 30, 2);

QString source = WControllerNetwork::extractJsonUtf8(json, "uri");

@@ -682,7 +672,7 @@ WBackendNetPlaylist WBackendSoundCloud::extractPlaylist(const QByteArray &
}
else if (id == 3) // related
{
QString json = d->extractJson(content, 67, 2);
QString json = d->extractJson(content, 18, 2);

QString idTrack = WControllerNetwork::extractJsonUtf8(json, "id");

@@ -39,7 +39,7 @@ class SK_BACKEND_EXPORT WBackendSoundCloud : public WBackendNet
public: // WBackendNet reimplementation
/* Q_INVOKABLE virtual */ bool hasSearch() const;

/* Q_INVOKABLE virtual */ bool checkValidUrl(const QString & url) const;
/* Q_INVOKABLE virtual */ QString validate() const;

/* Q_INVOKABLE virtual */ QString getHost() const;

0 comments on commit b54e3fe

Please sign in to comment.
You can’t perform that action at this time.