forked from EXL/QAndroidFileHostParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
335 lines (283 loc) · 9.75 KB
/
widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include "widget.h"
#include "ui_widget.h"
#include <QUrl>
#include <QDebug>
#include <QRegExp>
#include <QMessageBox>
#include <QFileDialog>
#include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QWebFrame>
#else
#include <QtWebKit/QWebFrame>
#endif
#include <algorithm>
#define MULTI_LINE_STRING(a) #a
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
pageCount = filesCount = 0;
fileCNT = 0;
pgtCNT = 1;
stackSize = 0;
directLink = lastPage = false;
filesOnPage = 18;
textLog = new QFile(this);
textLog->setFileName("SW-Log.txt");
webPage = new WebPage(this);
ui->webView->setPage(webPage);
timer = new QTimer(this);
mainFrame = ui->webView->page()->mainFrame();
ui->tableWidget->setRowCount(100);
ui->tableWidget->setColumnCount(4);
QStringList labels;
labels << "Name" << "Link" << "Direct Links" << "MD5 chksm";
ui->tableWidget->setHorizontalHeaderLabels(labels);
setWindowState(Qt::WindowMaximized);
ui->webView->setDisabled(true);
connect(mainFrame, SIGNAL(loadFinished(bool)), this, SLOT(webPageLoaded(bool)));
connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(goToURL()));
connect(ui->webView, SIGNAL(loadProgress(int)), ui->progressBar, SLOT(setValue(int)));
connect(timer, SIGNAL(timeout()), this, SLOT(timerOff()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::webPageLoaded(bool)
{
qDebug() << "Page Loaded!";
if (!directLink) {
pageCount = getPageCount();
filesCount = getFilesCount();
qDebug() << "Files: " << filesCount << "Pages: " << pageCount;
ui->tableWidget->setRowCount(filesCount);
}
ui->label_2->setText(tr("Getting links..."));
if (pageCount && filesCount && !directLink) {
const char* theJavaScriptCodeToInject = MULTI_LINE_STRING(
function gettingLinks()
{
var stackLinks = [];
var allSpans = document.getElementsByClassName("list-group-item-heading");
for (theSpan in allSpans)
{
var link = allSpans[theSpan].innerHTML;
if (link)
{
link = link.replace("<i class=\"fa fa-file-archive-o\"></i> ", "");
stackLinks.push(link);
}
}
return stackLinks;
}
gettingLinks();
);
QVariant jsReturn = mainFrame->evaluateJavaScript(theJavaScriptCodeToInject);
fillTableLinks(jsReturn.toStringList());
}
if (directLink) {
const char* clickJsCode = MULTI_LINE_STRING(
function clickMirrorButton()
{
document.getElementById('loadMirror').click();
}
clickMirrorButton();
);
mainFrame->evaluateJavaScript(clickJsCode);
timer->start(ui->spinBox->value() * 1000);
}
}
void Widget::goToURL()
{
ui->label_2->setText("Loading page...");
ui->webView->load(QUrl(ui->lineEdit->text()));
}
void Widget::fillTableLinks(const QStringList &stackLinks)
{
stackSize = stackLinks.length();
for (int i = 0; i < stackLinks.length(); ++i) {
QString string = stackLinks[i];
QString name = string;
name.remove(QRegExp("<[^>]*>"));
QString link = string;
link.remove("<a href=\"");
link = link.left(23);
ui->tableWidget->setItem(i + getArg(), 0, new QTableWidgetItem(name));
ui->tableWidget->setItem(i + getArg(), 1, new QTableWidgetItem("https://androidfilehost.com" + link));
}
directLink = true;
ui->lineEdit->setText(ui->tableWidget->item(fileCNT + getArg(), 1)->text());
goToURL();
}
int Widget::getPageCount() const
{
ui->label_2->setText("Pages count is...");
const char* theJavaScriptCodeToInject = MULTI_LINE_STRING(
function getPagesCount()
{
var stackLinks = [];
var allSpans = document.getElementsByClassName("pagination navbar-right");
for (theSpan in allSpans)
{
var link = allSpans[theSpan].innerHTML;
if (link)
{
stackLinks.push(link);
}
}
return stackLinks;
}
getPagesCount();
);
QVariant jsReturn = mainFrame->evaluateJavaScript(theJavaScriptCodeToInject);
QString s = jsReturn.toStringList()[0].replace(QRegExp("<[^>]*>"), "a");
QString pageCnt = "";
bool flag = false;
for (int i = s.length(); i >= 0; --i) {
if (s[i].isDigit()) {
pageCnt += s[i];
flag = true;
} else {
if (flag) {
break;
}
}
}
std::reverse(pageCnt.begin(), pageCnt.end());
int pgCnt = pageCnt.toInt();
ui->label_2->setText(QString("Pages count is... %1.").arg(pgCnt));
return pgCnt;
}
int Widget::getFilesCount() const
{
const char* theJavaScriptCodeToInject = MULTI_LINE_STRING(
function getFilesNum()
{
var stackLinks = [];
var allSpans = document.getElementsByClassName("navbar-brand");
for (theSpan in allSpans)
{
var link = allSpans[theSpan].innerHTML;
if (link)
{
stackLinks.push(link);
}
}
return stackLinks;
}
getFilesNum();
);
QVariant jsReturn = mainFrame->evaluateJavaScript(theJavaScriptCodeToInject);
QString s = jsReturn.toStringList()[1].replace("files", "").trimmed();
return s.toInt();
}
void Widget::flushToFile(int begin, int end)
{
if (!(textLog->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))) {
qDebug() << "Error open file!";
}
QTextStream out(textLog);
for(int i = begin; i < end; ++i)
{
out << "Name: " << ui->tableWidget->item(i, 0)->text() << "\n";
out << "Link: " << ui->tableWidget->item(i, 1)->text() << "\n";
out << "MD5: " << ui->tableWidget->item(i, 3)->text() << "\n";
out << "Direct Links:\n" << ui->tableWidget->item(i, 2)->text() << "\n\n\n";
}
textLog->close();
}
void Widget::tableDirectLinks(const QString &links)
{
QString dlinks = links;
QString buffer = "";
dlinks = dlinks.trimmed();
QStringList linksList = dlinks.split("<a href=\"");
linksList.removeAt(0);
for (int i = 0; i < linksList.length(); ++i) {
int r = linksList[i].indexOf(".zip");
buffer += linksList[i].left(r) + ".zip\n";
}
ui->tableWidget->setItem(fileCNT + getArg(), 2, new QTableWidgetItem(buffer));
}
void Widget::md5ToTable(const QString &md5)
{
ui->tableWidget->setItem(fileCNT + getArg(), 3, new QTableWidgetItem(md5));
}
int Widget::getArg() const
{
if (!lastPage) {
return (pgtCNT - 1) * stackSize;
} else {
int lastPagesFilesCount = filesCount % filesOnPage;
int allFilesOnFullPage = filesCount - lastPagesFilesCount;
return allFilesOnFullPage;
}
}
void Widget::timerOff()
{
// Get Direct Links
const char* clickJsCode_1 = MULTI_LINE_STRING(
function getDirectLinks()
{
var stackLinks = [];
var allSpans = document.getElementsByClassName("list-group");
for (theSpan in allSpans)
{
var link = allSpans[theSpan].innerHTML;
if (link)
{
stackLinks.push(link);
}
}
return stackLinks;
}
getDirectLinks();
);
QVariant jsRet_1 = mainFrame->evaluateJavaScript(clickJsCode_1);
tableDirectLinks(jsRet_1.toStringList()[0]);
// Get MD5 checksums
const char* clickJsCode_2 = MULTI_LINE_STRING(
function getMd5List()
{
var stackLinks = [];
var allSpans = document.getElementsByTagName("code");
for (theSpan in allSpans)
{
var link = allSpans[theSpan].innerHTML;
if (link)
{
stackLinks.push(link);
}
}
return stackLinks;
}
getMd5List();
);
QVariant jsRet_2 = mainFrame->evaluateJavaScript(clickJsCode_2);
md5ToTable(jsRet_2.toStringList()[0]);
timer->stop();
fileCNT++;
if (fileCNT != stackSize) {
ui->lineEdit->setText(ui->tableWidget->item(fileCNT + getArg(), 1)->text());
goToURL();
} else {
directLink = false;
flushToFile(getArg(), fileCNT + getArg());
fileCNT = 0;
if (pgtCNT < pageCount - 1) {
pgtCNT++;
ui->lineEdit->setText(QString("https://www.androidfilehost.com/?w=search&s=.xml.zip&type=files&page=%1").arg(pgtCNT));
goToURL();
} else if (pgtCNT == pageCount - 1) { // Last Page
pgtCNT++;
lastPage = true;
ui->lineEdit->setText(QString("https://www.androidfilehost.com/?w=search&s=.xml.zip&type=files&page=%1").arg(pgtCNT));
goToURL();
} else { // All
ui->label_2->setText("All Done!");
}
}
}