Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the new base.js decryption function #2

Merged
merged 1 commit into from Nov 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 62 additions & 11 deletions src/streamsrequest.cpp
Expand Up @@ -477,7 +477,34 @@ static QString unescape(const QString &s) {
setErrorString(StreamsRequest::tr("No video streams found for %1").arg(id));
emit q->finished();
}


static QString getJsObject(const QString &js, const QString &obj) {
QString rv;

int start = js.indexOf(QRegExp("var\\s" + QRegExp::escape(obj)));
int end = start;

if (start == -1)
return rv;

do {
end = js.indexOf("}", end);

if (end == -1) {
rv.clear();
break;
}

end ++;
rv = js.mid(start, end - start);
} while (rv.count("{") != rv.count("}"));

if (start = rv.count("{"), start && start == rv.count("}"))
rv += ";";

return rv;
}

void _q_onPlayerJSLoaded() {
if (!reply) {
return;
Expand Down Expand Up @@ -510,20 +537,44 @@ static QString unescape(const QString &s) {
}

QRegExp re("\\.sig\\|\\|[\\w\\$]+(?=\\()");

if (re.indexIn(jsresponse) != -1) {
QString funcName = re.cap().section("||", -1);
QString var = jsresponse.section("function " + funcName, 0, 0).section(";var", -1);
QString funcBody = QString("function %2%3").arg(funcName).arg(jsresponse.section("function " + funcName, 1, 1)
.section(";function", 0, 0));
QString js = QString("var%1 %2").arg(var).arg(funcBody);
QString funcName = re.cap().section("||", -1).trimmed();
QString script;
re = QRegExp();
#ifdef QYOUTUBE_DEBUG
qDebug() << "QYouTube::StreamsRequestPrivate::_q_onPlayerJSLoaded: Found decryption function " << js;
qDebug() << "QYouTube::StreamsRequestPrivate::_q_onPlayerJSLoaded: Found decryption function " << funcName;
#endif
decryptionEngine->evaluate(js);

QScriptValue global = decryptionEngine->globalObject();
QScriptValue decryptionFunction = global.property(funcName);
QScriptValue decryptionFunction;
QString objName = funcName;

do {
QString s = getJsObject(jsresponse, objName);

if (s.isEmpty())
break;

script = s + script;
decryptionEngine->evaluate(script);
decryptionFunction = global.property(funcName);

if (!decryptionFunction.isFunction())
break;

decryptionFunction.call(QScriptValue(),
QScriptValueList() << "");

if (decryptionEngine->hasUncaughtException()) {
QString e =
decryptionEngine->uncaughtException().toString();

if (e.startsWith("ReferenceError: Can't find variable:"))
objName = e.section(":", -1, -1).trimmed();
else
break;
}
} while (decryptionEngine->hasUncaughtException());

if (decryptionFunction.isFunction()) {
decryptionCache[playerUrl] = decryptionFunction;
Expand Down