-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
281 lines (281 loc) · 12.4 KB
/
test.js
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
extensionList["f3568f40-9ef6-476c-b140-f5ad8a7d3598"] = {
baseURL: "https://gogoanime.gr",
ajaxURL: "https://ajax.gogo-load.com/ajax",
type: "anime",
supportsMalsync: true,
hasNameWseason: false,
disableAutoDownload: false,
disabled: false,
name: "Gogoanime",
shortenedName: "Gogo",
keys: [
CryptoJS.enc.Utf8.parse("37911490979715163134003223491201"),
CryptoJS.enc.Utf8.parse("54674138327930866480207815084989"),
CryptoJS.enc.Utf8.parse("3134003223491201")
],
searchApi: async function (query) {
var _a, _b;
let dom = new DOMHandler();
try {
let searchHTML = await MakeFetchZoro(`${this.baseURL}/search.html?keyword=${encodeURIComponent(query)}`, {});
dom.innerHTML = DOMPurify.sanitize(searchHTML);
let itemsDOM = dom.document.querySelectorAll("ul.items li");
let data = [];
for (var i = 0; i < itemsDOM.length; i++) {
let con = itemsDOM[i];
let src = con.querySelector("img").getAttribute("src");
let aTag = con.querySelector("a");
let animeName = (_b = (_a = con.querySelector(".name")) === null || _a === void 0 ? void 0 : _a.innerText) === null || _b === void 0 ? void 0 : _b.trim();
let animeHref = aTag.getAttribute("href") + "&engine=7";
data.push({ "name": animeName, "image": src, "link": animeHref });
}
return ({ data, "status": 200 });
}
catch (err) {
throw err;
}
},
getAnimeInfo: async function (url, aniID) {
const settled = "allSettled" in Promise;
const id = (new URLSearchParams(`?watch=${url}`)).get("watch").replace("category/", "");
let response = {
"name": "",
"image": "",
"description": "",
"episodes": [],
"mainName": ""
};
try {
if (settled) {
let anilistID;
if (!isNaN(parseInt(aniID))) {
anilistID = parseInt(aniID);
}
if (!anilistID) {
try {
anilistID = JSON.parse(await MakeFetch(`https://raw.githubusercontent.com/bal-mackup/mal-backup/master/page/Gogoanime/${id}.json`)).aniId;
}
catch (err) {
try {
anilistID = JSON.parse(await MakeFetch(`https://api.malsync.moe/page/Gogoanime/${id}`)).aniId;
}
catch (err) {
// anilistID will be undefined
}
}
}
if (anilistID) {
const promises = [
this.getAnimeInfoInter(url),
MakeFetchTimeout(`https://api.enime.moe/mapping/anilist/${anilistID}`, {}, 2000)
];
const promiseResponses = await Promise.allSettled(promises);
if (promiseResponses[0].status === "fulfilled") {
response = promiseResponses[0].value;
if (promiseResponses[1].status === "fulfilled") {
try {
const metaData = JSON.parse(promiseResponses[1].value).episodes;
const metaDataMap = {};
for (let i = 0; i < metaData.length; i++) {
metaDataMap[metaData[i].number] = metaData[i];
}
for (let i = 0; i < response.episodes.length; i++) {
const currentEp = metaDataMap[response.episodes[i].id];
const currentResponseEp = response.episodes[i];
currentResponseEp.description = currentEp === null || currentEp === void 0 ? void 0 : currentEp.description;
currentResponseEp.thumbnail = currentEp === null || currentEp === void 0 ? void 0 : currentEp.image;
currentResponseEp.date = new Date(currentEp === null || currentEp === void 0 ? void 0 : currentEp.airedAt);
currentResponseEp.title += ` - ${currentEp === null || currentEp === void 0 ? void 0 : currentEp.title}`;
}
}
catch (err) {
console.error(err);
}
}
return response;
}
else {
throw promiseResponses[0].reason;
}
}
else {
return await this.getAnimeInfoInter(url);
}
}
else {
return await this.getAnimeInfoInter(url);
}
}
catch (err) {
console.error(err);
throw err;
}
},
getAnimeInfoInter: async function (url) {
var _a;
url = url.split("&engine")[0];
const rawURL = `${this.baseURL}/${url}`;
const animeDOM = new DOMHandler();
const episodeDOM = new DOMHandler();
try {
const response = {
"name": "",
"image": "",
"description": "",
"episodes": [],
"mainName": ""
};
const animeHTML = await MakeFetchZoro(`${this.baseURL}/${url}`, {});
const id = url.replace("category/", "gogo-");
animeDOM.innerHTML = DOMPurify.sanitize(animeHTML, { ADD_ATTR: ["ep_start", "ep_end"] });
response.mainName = id;
response.image = animeDOM.document.querySelector(".anime_info_body_bg img").getAttribute("src");
response.name = animeDOM.document.querySelector(".anime_info_body_bg h1").innerText.trim();
response.description = animeDOM.document.querySelectorAll(".anime_info_body_bg p.type")[1].innerText.trim();
const episodeCon = animeDOM.document.querySelector("#episode_page").children;
const epStart = episodeCon[0].querySelector("a").getAttribute("ep_start");
const epEnd = episodeCon[episodeCon.length - 1].querySelector("a").getAttribute("ep_end");
const movieID = animeDOM.document.querySelector("#movie_id").getAttribute("value");
const alias = animeDOM.document.querySelector("#alias_anime").getAttribute("value");
const epData = [];
const episodeHTML = await MakeFetchZoro(`${this.ajaxURL}/load-list-episode?ep_start=${epStart}&ep_end=${epEnd}&id=${movieID}&default_ep=${0}&alias=${alias}`);
episodeDOM.innerHTML = DOMPurify.sanitize(episodeHTML);
const episodesLI = episodeDOM.document.querySelectorAll("#episode_related li");
for (let i = 0; i < episodesLI.length; i++) {
const el = episodesLI[i];
let epNum = parseFloat(el.querySelector(`div.name`).innerText.replace('EP ', ''));
if (epNum == 0) {
epNum = 0.1;
}
epData.unshift({
title: `Episode ${epNum}`,
link: `?watch=${id}&ep=${epNum}&engine=7`,
id: epNum.toString(),
altTitle: `Episode ${epNum}`,
sourceID: (_a = el.querySelector("a")) === null || _a === void 0 ? void 0 : _a.getAttribute("href"),
episodeNumber: epNum,
seasonNumber: -1
});
}
response.episodes = epData;
return response;
}
catch (err) {
err.url = rawURL;
throw err;
}
},
getLinkFromUrl: async function (url) {
var _a;
const watchDOM = new DOMHandler();
const embedDOM = new DOMHandler();
try {
const params = new URLSearchParams("?watch=" + url);
const sourceURLs = [];
const resp = {
sources: sourceURLs,
name: "",
nameWSeason: "",
episode: "",
status: 400,
message: "",
next: null,
prev: null,
};
const epNum = params.get("ep");
const epList = await this.getAnimeInfo(params.get("watch").replace("gogo-", "category/"));
const link = epList.episodes.find((ep) => ep.id === epNum).sourceID;
const watchHTML = await MakeFetchZoro(`${this.baseURL}/${link}`);
watchDOM.innerHTML = DOMPurify.sanitize(watchHTML, { ADD_TAGS: ["iframe"] });
try {
const prevTemp = watchDOM.document.querySelector(".anime_video_body_episodes_l a").getAttribute("href");
let ep = parseFloat(prevTemp.split("-episode-")[1]);
if (ep == 0) {
ep = 0.1;
}
resp.prev = `${params.get("watch")}&ep=${ep}&engine=7`;
}
catch (err) {
console.error(err);
}
try {
const nextTemp = watchDOM.document.querySelector(".anime_video_body_episodes_r a").getAttribute("href");
let ep = parseFloat(nextTemp.split("-episode-")[1]);
if (ep == 0) {
ep = 0.1;
}
resp.next = `${params.get("watch")}&ep=${ep}&engine=7`;
}
catch (err) {
console.error(err);
}
let videoURLTemp = watchDOM.document.querySelector("#load_anime iframe").getAttribute("src");
if (videoURLTemp.substring(0, 2) === "//") {
videoURLTemp = "https:" + videoURLTemp;
}
const embedHTML = await MakeFetchZoro(videoURLTemp);
const videoURL = new URL(videoURLTemp);
embedDOM.innerHTML = DOMPurify.sanitize(embedHTML);
const encyptedParams = this.generateEncryptedAjaxParams(embedHTML.split("data-value")[1].split("\"")[1], (_a = videoURL.searchParams.get('id')) !== null && _a !== void 0 ? _a : '', this.keys);
const encryptedData = JSON.parse(await MakeFetch(`${videoURL.protocol}//${videoURL.hostname}/encrypt-ajax.php?${encyptedParams}`, {
"headers": {
"X-Requested-With": "XMLHttpRequest"
}
}));
const decryptedData = await this.decryptAjaxData(encryptedData.data, this.keys);
if (!decryptedData.source)
throw new Error('No source found.');
for (const source of decryptedData.source) {
sourceURLs.push({
url: source.file,
type: "hls",
name: "HLS"
});
}
resp.name = params.get("watch");
resp.nameWSeason = params.get("watch");
resp.episode = params.get("ep");
if (parseFloat(resp.episode) === 0) {
resp.episode = "0.1";
}
return resp;
}
catch (err) {
throw err;
}
},
fixTitle(title) {
try {
title = title.replace("gogo-", "");
}
catch (err) {
console.error(err);
}
finally {
return title;
}
},
generateEncryptedAjaxParams: function (scriptValue, id, keys) {
const encryptedKey = CryptoJS.AES.encrypt(id, keys[0], {
iv: keys[2],
});
const decryptedToken = CryptoJS.AES.decrypt(scriptValue, keys[0], {
iv: keys[2],
}).toString(CryptoJS.enc.Utf8);
return `id=${encryptedKey}&alias=${id}&${decryptedToken}`;
},
decryptAjaxData: function (encryptedData, keys) {
const decryptedData = CryptoJS.enc.Utf8.stringify(CryptoJS.AES.decrypt(encryptedData, keys[1], {
iv: keys[2],
}));
return JSON.parse(decryptedData);
},
getMetaData: async function (search) {
const id = search.get("watch").replace("/category/", "");
return await getAnilistInfo("Gogoanime", id);
},
rawURLtoInfo: function (url) {
// https://gogoanime.bid/category/kimetsu-no-yaiba-movie-mugen-ressha-hen-dub
return `?watch=${url.pathname}&engine=7`;
}
};