diff options
author | Mateusz Łukasik <mati75@linuxmint.pl> | 2014-04-21 11:53:35 +0200 |
---|---|---|
committer | Mateusz Łukasik <mati75@linuxmint.pl> | 2014-04-21 11:53:35 +0200 |
commit | 2a117cc570574099839da41a5ae9fbb2a5ca9e55 (patch) | |
tree | 6107da409f9c7f07c0ffa0869a26a161b097aea7 /src/youtube/ytsig.cpp | |
parent | aa68b7bd585a157e8952881e87e2c09de6ec742f (diff) |
Imported Upstream version 14.3.0
Diffstat (limited to 'src/youtube/ytsig.cpp')
-rw-r--r-- | src/youtube/ytsig.cpp | 80 |
1 files changed, 50 insertions, 30 deletions
diff --git a/src/youtube/ytsig.cpp b/src/youtube/ytsig.cpp index f0a5664..d85de43 100644 --- a/src/youtube/ytsig.cpp +++ b/src/youtube/ytsig.cpp @@ -1,5 +1,5 @@ /* smplayer, GUI front-end for mplayer. - Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net> + Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,12 +20,10 @@ #ifdef YT_USE_SCRIPT #include <QtScript> -#endif -#ifdef YT_USE_SCRIPT -QString YTSig::aclara(const QString & text) { +QString YTSig::aclara(const QString & text, const QString & player, const QString & function_name) { int dot = text.indexOf('.'); - qDebug("YTSig::aclara: length: %d (%d.%d)", text.size(), dot, text.size()-dot-1); + qDebug("YTSig::aclara: length: %d (%d.%d) p: %d", text.size(), dot, text.size()-dot-1, !player.isEmpty()); if (script.isEmpty()) script = default_script; @@ -35,8 +33,28 @@ QString YTSig::aclara(const QString & text) { //qDebug() << (int) r.state(); engine.evaluate(script); - QScriptValue aclarar = engine.globalObject().property("aclara"); - QString res = aclarar.call(QScriptValue(), QScriptValueList() << text).toString(); + + QScriptValueList args; + QString fname; + + if (!function_name.isEmpty()) { + fname = function_name; + args << text; + } + else + if (player.isEmpty()) { + fname = "aclara"; + args << text; + } + else { + fname = "aclara_p"; + args << text << player; + } + + //qDebug("YTSig::aclara: function_name: %s", function_name.toLatin1().constData()); + + QScriptValue aclarar = engine.globalObject().property(fname); + QString res = aclarar.call(QScriptValue(), args).toString(); //qDebug() << res; @@ -60,44 +78,37 @@ void YTSig::reloadScriptFile() { QByteArray bytes = f.readAll(); f.close(); + parsed_ts = ""; + if (!bytes.isEmpty()) { script = bytes; + + QRegExp rx("D: ([\\d,a-z,A-Z-]+)"); + if (rx.indexIn(bytes)) { + QByteArray d = rx.cap(1).toLatin1(); + qDebug("YTSig::reloadScriptFile: d: %s", d.constData()); + parsed_ts = QByteArray::fromBase64(d); + } + } } QString YTSig::script; QString YTSig::script_file; -// Algorithms from youtube-dl (http://rg3.github.io/youtube-dl/) - QString YTSig::default_script; -#else +#else // YT_USE_SCRIPT -QString YTSig::rev(const QString & orig) { - QString r; - for (int n = orig.size()-1; n >= 0; n--) { - r.append(orig.at(n)); - } - return r; -} - -QString YTSig::aclara(const QString & text) { +#ifdef YTSIG_STATIC +#include "ytsig_priv.cpp" +#else +QString YTSig::aclara(const QString & text, const QString & player, const QString & function_name) { QString res; int dot = text.indexOf('.'); qDebug("YTSig::aclara (2): length: %d (%d.%d)", text.size(), dot, text.size()-dot-1); -#if 0 - if (text.size() == xx) { - res = <your code>; - } - else { - qDebug("YTSig::aclara: signature length not supported: %d: %s", text.size(), text.toLatin1().constData()); - return res; - } -#endif - /* qDebug("%d: orig: %s", text.size(), text.toLatin1().constData()); qDebug("%d: conv: %s", text.size(), res.toLatin1().constData()); @@ -105,5 +116,14 @@ QString YTSig::aclara(const QString & text) { return res; } - #endif + +#endif // YT_USE_SCRIPT + +void YTSig::check(QString & u) { + if (!parsed_ts.isEmpty()) { + u.append(QString("&%1").arg(parsed_ts)); + } +} + +QString YTSig::parsed_ts; |