From: Flavio Date: Thu, 13 Nov 2014 12:52:59 +0000 (+0100) Subject: Removed unused code, added js ageGate X-Git-Tag: 2.3.1~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8bf382b6d0e865ab6a51042ae74285d3f13ca9cb;p=minitube Removed unused code, added js ageGate --- diff --git a/src/jsfunctions.cpp b/src/jsfunctions.cpp index 2c95a1d..ff78591 100644 --- a/src/jsfunctions.cpp +++ b/src/jsfunctions.cpp @@ -94,13 +94,13 @@ void JsFunctions::errorJs(QNetworkReply *reply) { << reply->url().toString() << reply->errorString(); } -QString JsFunctions::evaluate(const QString &function) { +QString JsFunctions::evaluate(const QString &js) { if (!engine) return QString(); - QScriptValue value = engine->evaluate(function); + QScriptValue value = engine->evaluate(js); if (value.isUndefined()) - qWarning() << "Undefined result for" << function; + qWarning() << "Undefined result for" << js; if (value.isError()) - qWarning() << "Error in" << function << value.toString(); + qWarning() << "Error in" << js << value.toString(); return value.toString(); } @@ -129,6 +129,10 @@ QString JsFunctions::webPageFmtMapRE() { return evaluate("webPageFmtMapRE()"); } +QString JsFunctions::ageGateRE() { + return evaluate("ageGateRE()"); +} + QString JsFunctions::jsPlayerRE() { return evaluate("jsPlayerRE()"); } diff --git a/src/jsfunctions.h b/src/jsfunctions.h index ab0f1d1..e623a4b 100644 --- a/src/jsfunctions.h +++ b/src/jsfunctions.h @@ -40,11 +40,12 @@ public: QString videoTokenRE(); QString videoInfoFmtMapRE(); QString webPageFmtMapRE(); + QString ageGateRE(); QString jsPlayerRE(); QString signatureFunctionNameRE(); protected: - QString evaluate(const QString &function); + QString evaluate(const QString &js); private slots: void gotJs(QByteArray bytes); diff --git a/src/video.cpp b/src/video.cpp index f9018a8..e7c90da 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -162,7 +162,7 @@ void Video::gotVideoInfo(QByteArray data) { // get video token QRegExp videoTokeRE(JsFunctions::instance()->videoTokenRE()); if (videoTokeRE.indexIn(videoInfo) == -1) { - qWarning() << "Cannot get token. Trying next el param" << videoInfo << videoTokeRE.pattern(); + // qWarning() << "Cannot get token. Trying next el param" << videoInfo << videoTokeRE.pattern(); // Don't panic! We're gonna try another magic "el" param elIndex++; getVideoInfo(); @@ -179,7 +179,7 @@ void Video::gotVideoInfo(QByteArray data) { // get fmt_url_map QRegExp fmtMapRE(JsFunctions::instance()->videoInfoFmtMapRE()); if (fmtMapRE.indexIn(videoInfo) == -1) { - qWarning() << "Cannot get urlMap. Trying next el param"; + // qWarning() << "Cannot get urlMap. Trying next el param"; // Don't panic! We're gonna try another magic "el" param elIndex++; getVideoInfo(); @@ -305,18 +305,6 @@ void Video::parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage) { emit errorStreamUrl(tr("Cannot get video stream for %1").arg(m_webpage.toString())); } -void Video::foundVideoUrl(QString videoToken, int definitionCode) { - // qDebug() << "foundVideoUrl" << videoToken << definitionCode; - - QUrl videoUrl = QUrl(QString( - "http://www.youtube.com/get_video?video_id=%1&t=%2&eurl=&el=&ps=&asv=&fmt=%3" - ).arg(videoId, videoToken, QString::number(definitionCode))); - - m_streamUrl = videoUrl; - loadingStreamUrl = false; - emit gotStreamUrl(videoUrl); -} - void Video::errorVideoInfo(QNetworkReply *reply) { loadingStreamUrl = false; emit errorStreamUrl(tr("Network error: %1 for %2").arg(reply->errorString(), reply->url().toString())); @@ -326,7 +314,8 @@ void Video::scrapeWebPage(QByteArray data) { QString html = QString::fromUtf8(data); // qWarning() << html; - if (html.contains("player-age-gate-content\"")) { + QRegExp ageGateRE(JsFunctions::instance()->ageGateRE()); + if (ageGateRE.indexIn(html) != -1) { // qDebug() << "Found ageGate"; ageGate = true; elIndex = 4; diff --git a/src/video.h b/src/video.h index 897fd52..3a85233 100644 --- a/src/video.h +++ b/src/video.h @@ -102,7 +102,6 @@ private slots: private: void getVideoInfo(); - void foundVideoUrl(QString videoToken, int definitionCode); void parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage = false); void captureFunction(const QString &name, const QString &js); void captureObject(const QString &name, const QString &js);