-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserial.cpp
More file actions
executable file
·284 lines (235 loc) · 9.37 KB
/
Copy pathserial.cpp
File metadata and controls
executable file
·284 lines (235 loc) · 9.37 KB
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
#include <serial.h>
#include <QtCore>
#include <QtNetwork>
//SerialList
void SerialList::save(QString filename) {
QFile f(filename);
f.open(QIODevice::WriteOnly);
QDataStream out(&f);
out.setVersion(QDataStream::Qt_5_2);
out << this->vector;
f.close();
}
void SerialList::load(QString filename) {
QFile f(filename);
f.open(QIODevice::ReadOnly);
QDataStream in(&f);
in.setVersion(QDataStream::Qt_5_2);
in >> this->vector;
f.close();
}
void SerialList::toList(QListWidget *list) {
list->clear();
for (Serial serial: this->vector) {
list->addItem(serial.name);
}
}
Serial* SerialList::add(QString url) {
Serial serial;
serial.url = url;
serial.indexInList = vector.size();
this->vector.push_back(serial);
return &vector[vector.size() - 1];
}
//Serial
QDataStream& operator<<(QDataStream &out, const Serial &serial) {
out << serial.seasonList << serial.name << serial.url << serial.isSingle << serial.iframeUrl;
return out;
}
QDataStream& operator>>(QDataStream &in, Serial &serial) {
serial = Serial();
in >> serial.seasonList >> serial.name >> serial.url >> serial.isSingle >> serial.iframeUrl;
return in;
}
void Serial::updateSeasons() {
isUpdated = false;
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
auto *manager = new QNetworkAccessManager();
QUrl serial(url);
QString hostname(serial.host());
if (hostname != "adultmult.tv" && hostname != "adultmult.ru" && hostname != "zfilm-hd.com" && hostname != "zhd.life" && hostname != "zfilm-hd.net") {
QMessageBox::information(0, "Ошибка", "Клиент поддерживает только сайт zfilm-hd.com!", QMessageBox::Ok);
return;
}
QNetworkRequest request(serial);
manager->get(request);
QObject::connect(manager, &QNetworkAccessManager::finished, [=] (QNetworkReply *reply) {
if (reply->error() == QNetworkReply::NoError) {
Serial serial;
serial.url = reply->url().toString();
QString data = reply->readAll();
if (data.indexOf("обнаружена ошибка") != -1) {
QMessageBox::information(qApp->activeModalWidget(), "Ошибка", "Сериал не найден (обнаружена ошибка).", QMessageBox::Ok);
isUpdated = true;
return;
}
QRegExp name("<span id=\"dle-speedbar\">(.+)</div>");
name.setMinimal(true);
if (name.indexIn(data) == -1) {
QMessageBox::information(qApp->activeModalWidget(), "Ошибка", "Сериал не найден (не нашел название).", QMessageBox::Ok);
isUpdated = true;
return;
}
serial.name = name.cap(1).split("»").last().trimmed().split('<')[0].trimmed();
QFile f("html.html");
f.open(QIODevice::ReadWrite);
QDataStream ds(&f);
ds << data;
f.close();
QRegExp iframeScript("showFilm\\('(.+)'\\)");
iframeScript.setMinimal(true);
if (iframeScript.indexIn(data) == -1) {
QMessageBox::information(0, "Ошибка", "Сериал не найден (отсутствует плеер zfilm-hd).", QMessageBox::Ok);
isUpdated = true;
return;
}
QString iframeSource = QByteArray::fromBase64(iframeScript.cap(0).toUtf8());
QRegExp iframe("<iframe src=\"http://(.+)/(.+)/iframe");
iframe.setMinimal(true);
if (iframe.indexIn(iframeSource) == -1) {
QMessageBox::information(0, "Ошибка", "Сериал не найден (не могу найти плеер).", QMessageBox::Ok);
isUpdated = true;
return;
}
serial.iframeUrl = iframe.cap(0).split('"')[1];
auto *seasonManager = new QNetworkAccessManager();
QUrl frame(serial.iframeUrl);
QNetworkRequest frameRequest(frame);
auto *freply = seasonManager->get(frameRequest);
QEventLoop loop;
QObject::connect(freply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if (freply->error() == QNetworkReply::NoError) {
QString frameData = freply->readAll();
QRegExp seasons("<select name=\"season\" id=\"season\"(.+)</select>");
seasons.setMinimal(true);
if (seasons.indexIn(frameData) == -1) {
QMessageBox::information(0, "Ошибка", "Не найдено ни одного сезона!", QMessageBox::Ok);
isUpdated = true;
return;
}
QStringList seasonsList = seasons.cap(1).split("</option>");
int seasonCount = seasonsList.size() - 1;
for (int i = 0; i < seasonCount; i++) {
Season season;
QString seasonNameData = seasonsList[i];
QRegExp seasonIdRe(".*([0-9]+)");
seasonIdRe.indexIn(seasonNameData);
int seasonId = seasonIdRe.cap(1).toInt();
season.url = serial.iframeUrl + "?season=" + QString::number(seasonId);
if (seasonList.size() >= i + 1 && seasonList[i].url == season.url)
serial.seasonList.append(seasonList[i]);
else
serial.seasonList.append(season);
}
isUpdated = true;
} else {
QMessageBox::information(0, "Ошибка", "Проблема с интернетом. Повторите позже.", QMessageBox::Ok);
isUpdated = true;
return;
}
this->name = serial.name;
this->seasonList = serial.seasonList;
} else {
QMessageBox::information(0, "Ошибка", "Проблема с интернетом. Повторите позже.", QMessageBox::Ok);
isUpdated = true;
return;
}
isUpdated = true;
});
}
void Serial::waitForUpdated() {
while (!isUpdated) {
QTimer t;
t.start(10);
QEventLoop loop;
QObject::connect(&t, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.exec();
}
}
//Season
QDataStream& operator<<(QDataStream &out, const Season &season) {
out << season.episodeList << season.url;
return out;
}
QDataStream& operator>>(QDataStream &in, Season &season) {
season = Season();
in >> season.episodeList >> season.url;
return in;
}
void Season::updateEpisodes() {
isUpdated = false;
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
auto *episodeManager = new QNetworkAccessManager();
QUrl seasonUrl(url);
QNetworkRequest seasonRequest(seasonUrl);
QNetworkReply *seasonReply = episodeManager->get(seasonRequest);
QEventLoop loop;
QObject::connect(seasonReply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QString hostname = seasonUrl.host();
QString episodeData = seasonReply->readAll();
if (episodeData.indexOf("обнаружена ошибка") != -1) {
QMessageBox::information(0, "Ошибка", "Сериал не найден", QMessageBox::Ok);
isUpdated = true;
return;
}
Season season;
QRegExp episodes("<select name=\"episode\" id=\"episode\"(.+)</select>");
episodes.setMinimal(true);
if (episodes.indexIn(episodeData) == -1) {
QMessageBox::information(0, "Ошибка", "Не найдено ни одного эпизода!", QMessageBox::Ok);
isUpdated = true;
return;
}
int episodeCount = episodes.cap(1).split("option").size() / 2;
for (int i = 0; i < episodeCount; i++) {
Episode episode;
episode.link = url + "&episode=" + QString::number(i + 1);
episode.flashPlayer = episode.link;
episode.watched = false;
episode.name = "";
if (episodeList.size() >= i + 1) {
episode.watched = episodeList[i].watched;
}
season.episodeList.append(episode);
}
episodeList = season.episodeList;
isUpdated = true;
}
void Season::waitForUpdated() {
while (!isUpdated) {
QTimer t;
t.start(10);
QEventLoop loop;
QObject::connect(&t, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.exec();
}
}
//Episode
QDataStream& operator<<(QDataStream &out, const Episode &episode) {
out << episode.name << episode.url240 << episode.url360 << episode.url480 << episode.url720 << episode.link << episode.watched;
return out;
}
QDataStream& operator>>(QDataStream &in, Episode &episode) {
episode = Episode();
in >> episode.name >> episode.url240 >> episode.url360 >> episode.url480 >> episode.url720 >> episode.link >> episode.watched;
return in;
}
void Episode::updateSources() {
isUpdated = false;
QTextCodec *codec = QTextCodec::codecForName("Windows-1251");
auto *manager = new QNetworkAccessManager();
QUrl url(link);
isUpdated = true;
//todo
}
void Episode::waitForUpdated() {
while (!isUpdated) {
QTimer t;
t.start(10);
QEventLoop loop;
QObject::connect(&t, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.exec();
}
}