1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2013 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "ytsig.h"
|
---|
20 |
|
---|
21 | #ifdef YT_USE_SCRIPT
|
---|
22 | #include <QtScript>
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | #ifdef YT_USE_SCRIPT
|
---|
26 | QString YTSig::aclara(const QString & text) {
|
---|
27 | int dot = text.indexOf('.');
|
---|
28 | qDebug("YTSig::aclara: length: %d (%d.%d)", text.size(), dot, text.size()-dot-1);
|
---|
29 |
|
---|
30 | if (script.isEmpty()) script = default_script;
|
---|
31 |
|
---|
32 | QScriptEngine engine;
|
---|
33 |
|
---|
34 | //QScriptSyntaxCheckResult r = engine.checkSyntax(script);
|
---|
35 | //qDebug() << (int) r.state();
|
---|
36 |
|
---|
37 | engine.evaluate(script);
|
---|
38 | QScriptValue aclarar = engine.globalObject().property("aclara");
|
---|
39 | QString res = aclarar.call(QScriptValue(), QScriptValueList() << text).toString();
|
---|
40 |
|
---|
41 | //qDebug() << res;
|
---|
42 |
|
---|
43 | if (res.isEmpty()) {
|
---|
44 | qDebug("YTSig::aclara: signature length not supported: %d: %s", text.size(), text.toLatin1().constData());
|
---|
45 | }
|
---|
46 |
|
---|
47 | return res;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void YTSig::reloadScriptFile() {
|
---|
51 | qDebug("YTSig::reloadScriptFile: %s", script_file.toUtf8().constData());
|
---|
52 |
|
---|
53 | if (!QFile::exists(script_file)) {
|
---|
54 | qDebug("YTSig::reloadScriptFile: file doesn't exist.");
|
---|
55 | return;
|
---|
56 | }
|
---|
57 |
|
---|
58 | QFile f(script_file);
|
---|
59 | f.open(QIODevice::ReadOnly);
|
---|
60 | QByteArray bytes = f.readAll();
|
---|
61 | f.close();
|
---|
62 |
|
---|
63 | if (!bytes.isEmpty()) {
|
---|
64 | script = bytes;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | QString YTSig::script;
|
---|
69 | QString YTSig::script_file;
|
---|
70 |
|
---|
71 | // Algorithms from youtube-dl (http://rg3.github.io/youtube-dl/)
|
---|
72 |
|
---|
73 | QString YTSig::default_script;
|
---|
74 |
|
---|
75 | #else
|
---|
76 |
|
---|
77 | QString YTSig::rev(const QString & orig) {
|
---|
78 | QString r;
|
---|
79 | for (int n = orig.size()-1; n >= 0; n--) {
|
---|
80 | r.append(orig.at(n));
|
---|
81 | }
|
---|
82 | return r;
|
---|
83 | }
|
---|
84 |
|
---|
85 | QString YTSig::aclara(const QString & text) {
|
---|
86 | QString res;
|
---|
87 |
|
---|
88 | int dot = text.indexOf('.');
|
---|
89 | qDebug("YTSig::aclara (2): length: %d (%d.%d)", text.size(), dot, text.size()-dot-1);
|
---|
90 |
|
---|
91 | #if 0
|
---|
92 | if (text.size() == xx) {
|
---|
93 | res = <your code>;
|
---|
94 | }
|
---|
95 | else {
|
---|
96 | qDebug("YTSig::aclara: signature length not supported: %d: %s", text.size(), text.toLatin1().constData());
|
---|
97 | return res;
|
---|
98 | }
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | /*
|
---|
102 | qDebug("%d: orig: %s", text.size(), text.toLatin1().constData());
|
---|
103 | qDebug("%d: conv: %s", text.size(), res.toLatin1().constData());
|
---|
104 | */
|
---|
105 |
|
---|
106 | return res;
|
---|
107 | }
|
---|
108 |
|
---|
109 | #endif
|
---|