From 8a7e0bf84077ffe51f95f0fef905b2d245817aff Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Sun, 20 Dec 2015 14:25:45 +0100 Subject: [PATCH] Fix VEVO --- src/video.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 5a1dbd0..a5cade0 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -356,7 +356,7 @@ void Video::parseJsPlayer(const QByteArray &bytes) { } else { sigFuncName = funcNameRe.cap(1); captureFunction(sigFuncName, js); - // qWarning() << sigFunctions; + // qWarning() << sigFunctions << sigObjects; } #ifdef APP_DASH @@ -404,16 +404,27 @@ void Video::parseDashManifest(const QByteArray &bytes) { } void Video::captureFunction(const QString &name, const QString &js) { - QRegExp funcRe("function\\s+" + QRegExp::escape(name) + "\\s*\\([" + jsNameChars + ",\\s]*\\)\\s*\\{[^\\}]+\\}"); - if (funcRe.indexIn(js) == -1) { + const QString argsAndBody = "\\s*\\([" + jsNameChars + ",\\s]*\\)\\s*\\{[^\\}]+\\}"; + QString func; + QRegExp funcRe("function\\s+" + QRegExp::escape(name) + argsAndBody); + if (funcRe.indexIn(js) != -1) { + func = funcRe.cap(0); + } else { // try var foo = function(bar) { }; - funcRe = QRegExp("var\\s+" + QRegExp::escape(name) + "\\s*=\\s*function\\s*\\([" + jsNameChars + ",\\s]*\\)\\s*\\{[^\\}]+\\}"); - if (funcRe.indexIn(js) == -1) { - qWarning() << "Cannot capture function" << name; - return; + funcRe = QRegExp("var\\s+" + QRegExp::escape(name) + "\\s*=\\s*function" + argsAndBody); + if (funcRe.indexIn(js) != -1) { + func = funcRe.cap(0); + } else { + // try ,gr= function(bar) { }; + funcRe = QRegExp("[,\\s;}\\.\\)](" + QRegExp::escape(name) + "\\s*=\\s*function" + argsAndBody + ")"); + if (funcRe.indexIn(js) != -1) { + func = funcRe.cap(1); + } else { + qWarning() << "Cannot capture function" << name; + return; + } } } - QString func = funcRe.cap(0); sigFunctions.insert(name, func); // capture inner functions @@ -438,7 +449,7 @@ void Video::captureFunction(const QString &name, const QString &js) { } void Video::captureObject(const QString &name, const QString &js) { - QRegExp re("var\\s+" + QRegExp::escape(name) + "\\s*=\\s*\\{.+\\}\\s*;"); + QRegExp re("var\\s+" + QRegExp::escape(name) + "\\s*=\\s*\\{.*\\}\\s*;"); re.setMinimal(true); if (re.indexIn(js) == -1) { qWarning() << "Cannot capture object" << name; -- 2.39.5