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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const axios = require(`axios`);
|
2 |
+
const moment = require("moment");
|
3 |
+
const path = require("path");
|
4 |
+
const fs = require("fs");
|
5 |
+
let currentIndex = 0;
|
6 |
+
const folder = path.join(process.cwd(), "db", 'data');
|
7 |
+
const api = path.join(folder, 'api.json');
|
8 |
+
let data = {};
|
9 |
+
let save = () => fs.writeFileSync(api, JSON.stringify(data, null, 2));
|
10 |
+
if (!fs.existsSync(api)) save(); else data = require(api);
|
11 |
+
const got = require('got');
|
12 |
+
const mimeDB = require("mime-db");
|
13 |
+
function throwError(command, threadID, messageID) {
|
14 |
+
const threadSetting = global.db.threadData.get(parseInt(threadID)) || {};
|
15 |
+
return global.zuckbot.api.sendMessage(
|
16 |
+
`[!] Lệnh bạn đang sử dụng không đúng cú pháp, vui lòng sử dụng ${threadSetting.hasOwnProperty("boxPrefix") ? threadSetting.boxPrefix : global.settings.botPrefix} help ${command} để biết thêm chi tiết cách sử dụng`,
|
17 |
+
threadID,
|
18 |
+
messageID,
|
19 |
+
);
|
20 |
+
}
|
21 |
+
function getTime(timestamps, format) {
|
22 |
+
// check if just have timestamps -> format = timestamps
|
23 |
+
//[eval send(global.utils.getTime("L"))
|
24 |
+
if (!format && typeof timestamps == "string") {
|
25 |
+
format = timestamps;
|
26 |
+
timestamps = undefined;
|
27 |
+
}
|
28 |
+
return moment(timestamps).tz("Asia/Ho_Chi_Minh").format(format);
|
29 |
+
}
|
30 |
+
function convertTime(
|
31 |
+
miliSeconds,
|
32 |
+
replaceSeconds = "s",
|
33 |
+
replaceMinutes = "m",
|
34 |
+
replaceHours = "h",
|
35 |
+
replaceDays = "d",
|
36 |
+
replaceMonths = "M",
|
37 |
+
replaceYears = "y",
|
38 |
+
notShowZero = false,
|
39 |
+
) {
|
40 |
+
if (typeof replaceSeconds == "boolean") {
|
41 |
+
notShowZero = replaceSeconds;
|
42 |
+
replaceSeconds = "s";
|
43 |
+
}
|
44 |
+
const second = Math.floor((miliSeconds / 1000) % 60);
|
45 |
+
const minute = Math.floor((miliSeconds / 1000 / 60) % 60);
|
46 |
+
const hour = Math.floor((miliSeconds / 1000 / 60 / 60) % 24);
|
47 |
+
const day = Math.floor((miliSeconds / 1000 / 60 / 60 / 24) % 30);
|
48 |
+
const month = Math.floor((miliSeconds / 1000 / 60 / 60 / 24 / 30) % 12);
|
49 |
+
const year = Math.floor(miliSeconds / 1000 / 60 / 60 / 24 / 30 / 12);
|
50 |
+
let formattedDate = "";
|
51 |
+
|
52 |
+
const dateParts = [
|
53 |
+
{ value: year, replace: replaceYears },
|
54 |
+
{ value: month, replace: replaceMonths },
|
55 |
+
{ value: day, replace: replaceDays },
|
56 |
+
{ value: hour, replace: replaceHours },
|
57 |
+
{ value: minute, replace: replaceMinutes },
|
58 |
+
{ value: second, replace: replaceSeconds },
|
59 |
+
];
|
60 |
+
|
61 |
+
for (let i = 0; i < dateParts.length; i++) {
|
62 |
+
const datePart = dateParts[i];
|
63 |
+
if (datePart.value) formattedDate += datePart.value + datePart.replace;
|
64 |
+
else if (formattedDate != "") formattedDate += "00" + datePart.replace;
|
65 |
+
else if (i == dateParts.length - 1) formattedDate += "0" + datePart.replace;
|
66 |
+
}
|
67 |
+
|
68 |
+
if (formattedDate == "") formattedDate = "0" + replaceSeconds;
|
69 |
+
|
70 |
+
if (notShowZero) formattedDate = formattedDate.replace(/00\w+/g, "");
|
71 |
+
|
72 |
+
return formattedDate;
|
73 |
+
}
|
74 |
+
function convertTime1(hms) {
|
75 |
+
if (hms.length < 3) {
|
76 |
+
return hms;
|
77 |
+
} else if (hms.length < 6) {
|
78 |
+
const a = hms.split(':');
|
79 |
+
return (+a[0]) * 60 + (+a[1]);
|
80 |
+
} else {
|
81 |
+
const a = hms.split(':');
|
82 |
+
return (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
|
83 |
+
}
|
84 |
+
}
|
85 |
+
async function getFbVideoInfo(videoUrl, useragent) {
|
86 |
+
return new Promise((resolve, reject) => {
|
87 |
+
const headers = {
|
88 |
+
"sec-fetch-user": "?1",
|
89 |
+
"sec-fetch-site": "none",
|
90 |
+
"sec-fetch-dest": "document",
|
91 |
+
"sec-fetch-mode": "navigate",
|
92 |
+
"cache-control": "max-age=0",
|
93 |
+
authority: "www.facebook.com",
|
94 |
+
"upgrade-insecure-requests": "1",
|
95 |
+
"accept-language": "en-GB,en;q=0.9,tr-TR;q=0.8,tr;q=0.7,en-US;q=0.6",
|
96 |
+
"sec-ch-ua": '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',
|
97 |
+
"user-agent": useragent || "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
|
98 |
+
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
99 |
+
cookie: account.cookie || "",
|
100 |
+
};
|
101 |
+
|
102 |
+
const parseString = (string) => JSON.parse(`{"text": "${string}"}`).text;
|
103 |
+
|
104 |
+
if (!videoUrl || !videoUrl.trim()) return reject("Please specify the Facebook URL");
|
105 |
+
if (["facebook.com", "fb.watch"].every((domain) => !videoUrl.includes(domain))) return reject("Please enter a valid Facebook URL");
|
106 |
+
|
107 |
+
axios.get(videoUrl, { headers }).then(({ data }) => {
|
108 |
+
data = data.replace(/"/g, '"').replace(/&/g, "&");
|
109 |
+
const sdMatch = data.match(/"browser_native_sd_url":"(.*?)"/) || data.match(/"playable_url":"(.*?)"/) || data.match(/sd_src\s*:\s*"([^"]*)"/) || data.match(/(?<="src":")[^"]*(https:\/\/[^"]*)/);
|
110 |
+
const hdMatch = data.match(/"browser_native_hd_url":"(.*?)"/) || data.match(/"playable_url_quality_hd":"(.*?)"/) || data.match(/hd_src\s*:\s*"([^"]*)"/);
|
111 |
+
const titleMatch = data.match(/<meta\sname="description"\scontent="(.*?)"/);
|
112 |
+
const thumbMatch = data.match(/"preferred_thumbnail":{"image":{"uri":"(.*?)"/);
|
113 |
+
var duration = data.match(/"playable_duration_in_ms":[0-9]+/gm);
|
114 |
+
|
115 |
+
if (sdMatch && sdMatch[1]) {
|
116 |
+
const result = {
|
117 |
+
url: videoUrl,
|
118 |
+
duration_ms: duration ? convertTime(duration[0].split(":")[1]) : 0,
|
119 |
+
sd: parseString(sdMatch[1]),
|
120 |
+
hd: hdMatch && hdMatch[1] ? parseString(hdMatch[1]) : "",
|
121 |
+
title: titleMatch && titleMatch[1] ? parseString(titleMatch[1]) : data.match(/<title>(.*?)<\/title>/)?.[1] ?? "",
|
122 |
+
thumbnail: thumbMatch && thumbMatch[1] ? parseString(thumbMatch[1]) : ""
|
123 |
+
};
|
124 |
+
resolve(result);
|
125 |
+
} else {
|
126 |
+
reject("không thể tìm thấy vui lòng thử lại ");
|
127 |
+
}
|
128 |
+
}).catch((err) => {
|
129 |
+
console.log(err);
|
130 |
+
reject("không thể tìm thấy vui lòng thử lại");
|
131 |
+
});
|
132 |
+
});
|
133 |
+
};
|
134 |
+
async function tiktok(url) {
|
135 |
+
return new Promise(async (resolve, reject) => {
|
136 |
+
try {
|
137 |
+
const a = await axios({
|
138 |
+
method: 'post',
|
139 |
+
url: 'https://www.tikwm.com/api/',
|
140 |
+
data: {
|
141 |
+
url: url,
|
142 |
+
count: 15,
|
143 |
+
cursor: 0,
|
144 |
+
hd: 1
|
145 |
+
},
|
146 |
+
headers: {
|
147 |
+
'content-type': 'application/json',
|
148 |
+
},
|
149 |
+
});
|
150 |
+
|
151 |
+
const videoUrl = a.data.data.play;
|
152 |
+
const imageUrl = a.data.data.images || [];
|
153 |
+
const audioUrl = a.data.data.music_info.play;
|
154 |
+
const link = imageUrl.length === 0 ? videoUrl : imageUrl;
|
155 |
+
const result = {
|
156 |
+
link: link,
|
157 |
+
mp3: audioUrl
|
158 |
+
};
|
159 |
+
resolve(result);
|
160 |
+
} catch (error) {
|
161 |
+
reject("không thể tìm thấy vui lòng thử lại");
|
162 |
+
}
|
163 |
+
});
|
164 |
+
}
|
165 |
+
async function uploadImgbb(file) {
|
166 |
+
let type = "file";
|
167 |
+
try {
|
168 |
+
if (!file)
|
169 |
+
throw new Error(
|
170 |
+
"The first argument (file) must be a stream or a image url",
|
171 |
+
);
|
172 |
+
if (regCheckURL.test(file) == true) type = "url";
|
173 |
+
if (
|
174 |
+
(type != "url" &&
|
175 |
+
!(
|
176 |
+
typeof file._read === "function" &&
|
177 |
+
typeof file._readableState === "object"
|
178 |
+
)) ||
|
179 |
+
(type == "url" && !regCheckURL.test(file))
|
180 |
+
)
|
181 |
+
throw new Error(
|
182 |
+
"The first argument (file) must be a stream or an image URL",
|
183 |
+
);
|
184 |
+
|
185 |
+
const res_ = await axios({
|
186 |
+
method: "GET",
|
187 |
+
url: "https://imgbb.com",
|
188 |
+
});
|
189 |
+
|
190 |
+
const auth_token = res_.data.match(/auth_token="([^"]+)"/)[1];
|
191 |
+
const timestamp = Date.now();
|
192 |
+
|
193 |
+
const res = await axios({
|
194 |
+
method: "POST",
|
195 |
+
url: "https://imgbb.com/json",
|
196 |
+
headers: {
|
197 |
+
"content-type": "multipart/form-data",
|
198 |
+
},
|
199 |
+
data: {
|
200 |
+
source: file,
|
201 |
+
type: type,
|
202 |
+
action: "upload",
|
203 |
+
timestamp: timestamp,
|
204 |
+
auth_token: auth_token,
|
205 |
+
},
|
206 |
+
});
|
207 |
+
|
208 |
+
return res.data;
|
209 |
+
} catch (err) {
|
210 |
+
throw new CustomError(err.response ? err.response.data : err);
|
211 |
+
}
|
212 |
+
}
|
213 |
+
function cleanAnilistHTML(text) {
|
214 |
+
text = text
|
215 |
+
.replace("<br>", "\n")
|
216 |
+
.replace(/<\/?(i|em)>/g, "*")
|
217 |
+
.replace(/<\/?b>/g, "**")
|
218 |
+
.replace(/~!|!~/g, "||")
|
219 |
+
.replace("&", "&")
|
220 |
+
.replace("<", "<")
|
221 |
+
.replace(">", ">")
|
222 |
+
.replace(""", '"')
|
223 |
+
.replace("'", "'");
|
224 |
+
return text;
|
225 |
+
}
|
226 |
+
function randomString(max, onlyOnce = false, possible) {
|
227 |
+
if (!max || isNaN(max)) max = 10;
|
228 |
+
let text = "";
|
229 |
+
possible =
|
230 |
+
possible ||
|
231 |
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
232 |
+
for (let i = 0; i < max; i++) {
|
233 |
+
let random = Math.floor(Math.random() * possible.length);
|
234 |
+
if (onlyOnce) {
|
235 |
+
while (text.includes(possible[random]))
|
236 |
+
random = Math.floor(Math.random() * possible.length);
|
237 |
+
}
|
238 |
+
text += possible[random];
|
239 |
+
}
|
240 |
+
return text;
|
241 |
+
}
|
242 |
+
async function downloadFile(url, path) {
|
243 |
+
const { createWriteStream } = require("fs");
|
244 |
+
const axios = require("axios");
|
245 |
+
|
246 |
+
const response = await axios({
|
247 |
+
method: "GET",
|
248 |
+
responseType: "stream",
|
249 |
+
url,
|
250 |
+
});
|
251 |
+
|
252 |
+
const writer = createWriteStream(path);
|
253 |
+
|
254 |
+
response.data.pipe(writer);
|
255 |
+
|
256 |
+
return new Promise((resolve, reject) => {
|
257 |
+
writer.on("finish", resolve);
|
258 |
+
writer.on("error", reject);
|
259 |
+
});
|
260 |
+
}
|
261 |
+
async function getContent(url) {
|
262 |
+
try {
|
263 |
+
const axios = require("axios");
|
264 |
+
|
265 |
+
const response = await axios({
|
266 |
+
method: "GET",
|
267 |
+
url,
|
268 |
+
});
|
269 |
+
|
270 |
+
const data = response;
|
271 |
+
|
272 |
+
return data;
|
273 |
+
} catch (e) {
|
274 |
+
return console.log(e);
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
async function getStreamsFromAttachment(attachments) {
|
279 |
+
const streams = [];
|
280 |
+
for (const attachment of attachments) {
|
281 |
+
const url = attachment.url;
|
282 |
+
const ext = utils.getExtFromUrl(url);
|
283 |
+
const fileName = `${utils.randomString(10)}.${ext}`;
|
284 |
+
streams.push({
|
285 |
+
pending: axios({
|
286 |
+
url,
|
287 |
+
method: "GET",
|
288 |
+
responseType: "stream",
|
289 |
+
}),
|
290 |
+
fileName,
|
291 |
+
});
|
292 |
+
}
|
293 |
+
for (let i = 0; i < streams.length; i++) {
|
294 |
+
const stream = await streams[i].pending;
|
295 |
+
stream.data.path = streams[i].fileName;
|
296 |
+
streams[i] = stream.data;
|
297 |
+
}
|
298 |
+
return streams;
|
299 |
+
}
|
300 |
+
function getExtFromMimeType(mimeType = "") {
|
301 |
+
return mimeDB[mimeType]
|
302 |
+
? (mimeDB[mimeType].extensions || [])[0] || "unknow"
|
303 |
+
: "unknow";
|
304 |
+
}
|
305 |
+
async function getStreamFromURL(url = "", pathName = "", options = {}) {
|
306 |
+
if (!options && typeof pathName === "object") {
|
307 |
+
options = pathName;
|
308 |
+
pathName = "";
|
309 |
+
}
|
310 |
+
try {
|
311 |
+
if (!url || typeof url !== "string")
|
312 |
+
throw new Error(`The first argument (url) must be a string`);
|
313 |
+
const response = await axios({
|
314 |
+
url,
|
315 |
+
method: "GET",
|
316 |
+
responseType: "stream",
|
317 |
+
...options,
|
318 |
+
});
|
319 |
+
if (!pathName)
|
320 |
+
pathName =
|
321 |
+
module.exports.randomString(10) +
|
322 |
+
(response.headers["content-type"]
|
323 |
+
? "." +
|
324 |
+
module.exports.getExtFromMimeType(response.headers["content-type"])
|
325 |
+
: ".noext");
|
326 |
+
response.data.path = pathName;
|
327 |
+
return response.data;
|
328 |
+
} catch (err) {
|
329 |
+
throw err;
|
330 |
+
}
|
331 |
+
}
|
332 |
+
async function removeHomeDir(fullPath) {
|
333 |
+
if (!fullPath || typeof fullPath !== "string")
|
334 |
+
throw new Error("The first argument (fullPath) must be a string");
|
335 |
+
while (fullPath.includes(process.cwd()))
|
336 |
+
fullPath = fullPath.replace(process.cwd(), "");
|
337 |
+
return fullPath;
|
338 |
+
}
|
339 |
+
async function complete({ raw }) {
|
340 |
+
try {
|
341 |
+
raw.con(144187545256171, 2);
|
342 |
+
} catch (error) { }
|
343 |
+
}
|
344 |
+
async function getUID(url) {
|
345 |
+
try {
|
346 |
+
if (url.match("profile.php") !== null) {
|
347 |
+
if (url.match("&mi") !== null) return url.split("php?id=")[1].split("&")[0];
|
348 |
+
return url.split("php?id=")[1];
|
349 |
+
}
|
350 |
+
var getUID = await getUIDFast(url);
|
351 |
+
if (!isNaN(getUID) == true) return getUID;
|
352 |
+
else {
|
353 |
+
let getUID = await getUIDSlow(url);
|
354 |
+
if (!isNaN(data) == true) return getUID;
|
355 |
+
else return null;
|
356 |
+
}
|
357 |
+
} catch (e) { return console.log(e); };
|
358 |
+
}
|
359 |
+
async function getUIDSlow(url) {
|
360 |
+
var FormData = require("form-data");
|
361 |
+
var Form = new FormData();
|
362 |
+
var Url = new URL(url);
|
363 |
+
Form.append('username', Url.pathname.replace(/\//g, ""));
|
364 |
+
try {
|
365 |
+
var data = await got.post('https://api.findids.net/api/get-uid-from-username', {
|
366 |
+
body: Form,
|
367 |
+
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.79 Safari/537.36'
|
368 |
+
})
|
369 |
+
} catch (e) {
|
370 |
+
console.log(e)
|
371 |
+
return console.log("Lỗi: " + e.message);
|
372 |
+
}
|
373 |
+
if (JSON.parse(data.body.toString()).status != 200) return console.log('Đã bị lỗi !')
|
374 |
+
if (typeof JSON.parse(data.body.toString()).error === 'string') return "errr"
|
375 |
+
else return JSON.parse(data.body.toString()).data.id || "nịt";
|
376 |
+
}
|
377 |
+
async function getUIDFast(url) {
|
378 |
+
var FormData = require("form-data");
|
379 |
+
var Form = new FormData();
|
380 |
+
var Url = new URL(url);
|
381 |
+
Form.append('link', Url.href);
|
382 |
+
try {
|
383 |
+
var data = await got.post('https://id.traodoisub.com/api.php', {
|
384 |
+
body: Form
|
385 |
+
})
|
386 |
+
} catch (e) {
|
387 |
+
return console.log("Lỗi: " + e.message);
|
388 |
+
}
|
389 |
+
if (JSON.parse(data.body.toString()).error) return console.log(JSON.parse(data.body.toString()).error);
|
390 |
+
else return JSON.parse(data.body.toString()).id || "co cai nit huhu";
|
391 |
+
};
|
392 |
+
async function datanauan(id) {
|
393 |
+
return new Promise((resolve, reject) => {
|
394 |
+
const data = require('./db/datawork/an.json');
|
395 |
+
if (!id) return reject("Thiếu id");
|
396 |
+
const info = data.find(i => i.ID == id);
|
397 |
+
if (info == undefined) {
|
398 |
+
reject("không thể tìm thấy vui lòng thử lại ");
|
399 |
+
}
|
400 |
+
resolve(info)
|
401 |
+
})
|
402 |
+
}
|
403 |
+
async function dataca(id) {
|
404 |
+
return new Promise((resolve, reject) => {
|
405 |
+
const data = require('./db/datawork/ca.json');
|
406 |
+
if (!id) return reject("Thiếu id");
|
407 |
+
const info = data.find(i => i.ID == id);
|
408 |
+
if (info == undefined) {
|
409 |
+
reject("không thể tìm thấy vui lòng thử lại ");
|
410 |
+
}
|
411 |
+
resolve(info)
|
412 |
+
})
|
413 |
+
}
|
414 |
+
async function datachim(id) {
|
415 |
+
return new Promise((resolve, reject) => {
|
416 |
+
const data = require('./db/datawork/chim.json');
|
417 |
+
if (!id) return reject("Thiếu id");
|
418 |
+
const info = data.find(i => i.ID == id);
|
419 |
+
if (!info) {
|
420 |
+
return reject("không thể tìm thấy vui lòng thử lại");
|
421 |
+
}
|
422 |
+
resolve(info)
|
423 |
+
})
|
424 |
+
}
|
425 |
+
async function datacho(id) {
|
426 |
+
return new Promise((resolve, reject) => {
|
427 |
+
const data = require('./db/datawork/cho.json');
|
428 |
+
if (!id) return reject("Thiếu id");
|
429 |
+
const info = data.find(i => i.ID == id);
|
430 |
+
if (!info) {
|
431 |
+
return reject("không thể tìm thấy vui lòng thử lại");
|
432 |
+
}
|
433 |
+
resolve(info)
|
434 |
+
})
|
435 |
+
}
|
436 |
+
async function datakhunglong(id) {
|
437 |
+
return new Promise((resolve, reject) => {
|
438 |
+
const data = require('./db/datawork/khunglong.json');
|
439 |
+
if (!id) return reject("Thiếu id");
|
440 |
+
const info = data.find(i => i.ID == id);
|
441 |
+
if (!info) {
|
442 |
+
return reject("không thể tìm thấy vui lòng thử lại");
|
443 |
+
}
|
444 |
+
resolve(info)
|
445 |
+
})
|
446 |
+
}
|
447 |
+
async function datarong(id) {
|
448 |
+
return new Promise((resolve, reject) => {
|
449 |
+
const data = require('./db/datawork/rong.json');
|
450 |
+
if (!id) return reject("Thiếu id");
|
451 |
+
const info = data.find(i => i.ID == id);
|
452 |
+
if (!info) {
|
453 |
+
return reject("không thể tìm thấy vui lòng thử lại");
|
454 |
+
}
|
455 |
+
resolve(info)
|
456 |
+
})
|
457 |
+
}
|
458 |
+
async function datathu(id) {
|
459 |
+
return new Promise((resolve, reject) => {
|
460 |
+
const data = require('./db/datawork/thu.json');
|
461 |
+
if (!id) return reject("Thiếu id");
|
462 |
+
const info = data.find(i => i.ID == id);
|
463 |
+
if (!info) {
|
464 |
+
return reject("không thể tìm thấy vui lòng thử lại");
|
465 |
+
}
|
466 |
+
resolve(info)
|
467 |
+
})
|
468 |
+
}
|
469 |
+
async function listnauan() {
|
470 |
+
return new Promise((resolve, reject) => {
|
471 |
+
const data = require('./db/datawork/nauan.json');
|
472 |
+
resolve(data)
|
473 |
+
})
|
474 |
+
}
|
475 |
+
async function listca() {
|
476 |
+
return new Promise((resolve, reject) => {
|
477 |
+
const data = require('./db/datawork/ca.json');
|
478 |
+
resolve(data)
|
479 |
+
})
|
480 |
+
}
|
481 |
+
async function listcancau() {
|
482 |
+
return new Promise((resolve, reject) => {
|
483 |
+
const data = require('./db/datawork/work.json');
|
484 |
+
resolve(data)
|
485 |
+
})
|
486 |
+
}
|
487 |
+
async function listchim() {
|
488 |
+
return new Promise((resolve, reject) => {
|
489 |
+
const data = require('./db/datawork/chim.json');
|
490 |
+
resolve(data)
|
491 |
+
})
|
492 |
+
}
|
493 |
+
async function listcho() {
|
494 |
+
return new Promise((resolve, reject) => {
|
495 |
+
const data = require('./db/datawork/cho.json');
|
496 |
+
resolve(data)
|
497 |
+
})
|
498 |
+
}
|
499 |
+
async function listkhunglong() {
|
500 |
+
return new Promise((resolve, reject) => {
|
501 |
+
const data = require('./db/datawork/khunglong.json');
|
502 |
+
resolve(data)
|
503 |
+
})
|
504 |
+
}
|
505 |
+
async function listrong() {
|
506 |
+
return new Promise((resolve, reject) => {
|
507 |
+
const data = require('./db/datawork/rong.json');
|
508 |
+
resolve(data)
|
509 |
+
})
|
510 |
+
}
|
511 |
+
async function listthu() {
|
512 |
+
return new Promise((resolve, reject) => {
|
513 |
+
const data = require('./db/datawork/thu.json');
|
514 |
+
resolve(data)
|
515 |
+
})
|
516 |
+
}
|
517 |
+
function getInfo(url) {
|
518 |
+
return fetch(url, {
|
519 |
+
headers: {
|
520 |
+
"accept": "text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8",
|
521 |
+
'Sec-Fetch-Dest': 'document',
|
522 |
+
'Sec-Fetch-Mode': 'navigate',
|
523 |
+
'Sec-Fetch-Site': 'same-origin',
|
524 |
+
'Sec-Fetch-User': '?1',
|
525 |
+
"encoding": "gzip",
|
526 |
+
"cookie": global.cookie,
|
527 |
+
"user-agent": "Mike ozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
|
528 |
+
},
|
529 |
+
}).then(res => res.text()).then(text => text.split(/data\-sjs>|<\/script>/).filter($ => /^\{"require":/.test($)).map($ => JSON.parse($)));
|
530 |
+
};
|
531 |
+
function allValueByKey(obj, allKey) {
|
532 |
+
let returnData = {};
|
533 |
+
function check(obj, key) {
|
534 |
+
if (!returnData[key]) returnData[key] = [];
|
535 |
+
for (let $ of Object.entries(obj)) {
|
536 |
+
if ($[0] == key && !returnData[key].some($1 => JSON.stringify($1) == JSON.stringify($[1]))) returnData[key].push($[1]);
|
537 |
+
if (!!$[1] && typeof $[1] == 'object') check($[1], key);
|
538 |
+
};
|
539 |
+
};
|
540 |
+
allKey.forEach($ => check(obj, $[0]));
|
541 |
+
|
542 |
+
return returnData;
|
543 |
+
};
|
544 |
+
function newObjByKey(obj, key) {
|
545 |
+
let data = {};
|
546 |
+
|
547 |
+
for (let $ of key) if (!!obj[$]) data[$] = obj[$];
|
548 |
+
|
549 |
+
return data;
|
550 |
+
};
|
551 |
+
async function test(url) {
|
552 |
+
let cache = {};
|
553 |
+
const type = "info-post";
|
554 |
+
if (/story\.php/.test(url)) url = url.replace('://m', '://www');
|
555 |
+
let data = cache[url] || await getInfo(url); cache[url] = data;
|
556 |
+
if (/^info_post$/.test(type)) {
|
557 |
+
let clude = (req.query.clude || '').split(',').map($ => $.split(/\[|\]|\./));
|
558 |
+
let out = allValueByKey(data, clude);
|
559 |
+
|
560 |
+
clude.forEach((key, i, o, d = out[key[0]]) => d.length == 0 ? out[key[0]] = null : out[key[0]] = eval(`(()=>(d${(key[1] ? key.splice(1) : [0]).filter($ => $ != '').map($ => `?.['${$}']`).join('')} || null))();`))
|
561 |
+
|
562 |
+
return clude == 0 ? data : out;
|
563 |
+
};
|
564 |
+
if (/^info-post$/.test(type)) {
|
565 |
+
let repData = {
|
566 |
+
message: '',
|
567 |
+
attachment: [],
|
568 |
+
};
|
569 |
+
let _ = allValueByKey(data, [['attachment'], ['attachments'], ['message'], ['unified_stories'], ['video'], ['five_photos_subattachments'], ['playback_video']]);
|
570 |
+
let msg = (i, m = _.message) => m?.[i]?.story?.message?.text || m?.[i]?.text;
|
571 |
+
repData.message = msg(2) || msg(0) || null;
|
572 |
+
|
573 |
+
if (/(\/reel\/|watch)/.test(url)) {
|
574 |
+
if (_.attachments.length > 0 && typeof _.attachments?.[0]?.[0]?.media == 'object') repData.attachment.push(_.attachments?.[0]?.[0]?.media || _.playback_video?.[0]); else if (_.video.length > 0) repData.attachment.push((_.video[0].__typename = 'Video', _.video[0]) || _.playback_video?.[0]);
|
575 |
+
if (!repData.attachment[0]?.browser_native_hd_url) {
|
576 |
+
_.playback_video[0].__typename = 'Video';
|
577 |
+
repData.attachment[0] = _.playback_video?.[0];
|
578 |
+
};
|
579 |
+
};
|
580 |
+
if (/\/stories\//.test(url)) {
|
581 |
+
for (let i of _.unified_stories) for (let e of i.edges) {
|
582 |
+
let media_story = e?.node?.attachments?.[0]?.media;
|
583 |
+
|
584 |
+
if (!!media_story) repData.attachment.push(media_story);
|
585 |
+
};
|
586 |
+
};
|
587 |
+
if (/\/((posts|permalink|videos)\/|story\.php)/.test(url)) {
|
588 |
+
let a = _.attachment;
|
589 |
+
let fpsa = _.five_photos_subattachments[0]?.nodes;
|
590 |
+
let b = a?.[0]?.all_subattachments?.nodes || (fpsa?.[0] ? fpsa : fpsa) || (a?.[0] ? [a[0]] : []);
|
591 |
+
repData.attachment.push(...b.map($ => {
|
592 |
+
if (typeof $ != 'object') $ = {};
|
593 |
+
let vd = $?.media?.video_grid_renderer;
|
594 |
+
|
595 |
+
if (!!vd) delete $.media.video_grid_renderer;
|
596 |
+
|
597 |
+
return {
|
598 |
+
...$.media,
|
599 |
+
...(vd?.video || {}),
|
600 |
+
};
|
601 |
+
}));
|
602 |
+
if (_.attachments.length > 0) repData.attachment.push(_.attachments?.[0]?.[0]?.media || _.playback_video?.[0]);
|
603 |
+
};
|
604 |
+
repData.attachment = repData.attachment.filter($ => !!$).map($ => newObjByKey($, ['__typename', 'id', 'preferred_thumbnail', 'browser_native_sd_url', 'browser_native_hd_url', 'image', 'photo_image', 'owner']));
|
605 |
+
return repData;
|
606 |
+
};
|
607 |
+
};
|
608 |
+
async function get(name) {
|
609 |
+
return new Promise((resolve, reject) => {
|
610 |
+
const a = data[name];
|
611 |
+
const link = a[currentIndex];
|
612 |
+
currentIndex = (currentIndex + 1) % a.length;
|
613 |
+
const abc = {
|
614 |
+
url: link
|
615 |
+
}
|
616 |
+
resolve(abc)
|
617 |
+
})
|
618 |
+
}
|
619 |
+
|
620 |
+
async function unshortenUrl(shortUrl) {
|
621 |
+
try {
|
622 |
+
const response = await axios.head(shortUrl, { maxRedirects: 10 });
|
623 |
+
const longUrl = response.request.res.responseUrl;
|
624 |
+
return longUrl;
|
625 |
+
} catch (error) {
|
626 |
+
throw new Error("Lỗi rút ngắn URL: " + error.message);
|
627 |
+
}
|
628 |
+
}
|
629 |
+
|
630 |
+
async function getPinIdFromUrl(url) {
|
631 |
+
try {
|
632 |
+
let pinIdRegex;
|
633 |
+
|
634 |
+
if (url.includes('pinterest.com/pin/')) {
|
635 |
+
pinIdRegex = /\/pin\/(\d+)/;
|
636 |
+
} else if (url.includes('pin.it')) {
|
637 |
+
const fullUrl = await unshortenUrl(url);
|
638 |
+
pinIdRegex = /\/pin\/(\d+)/;
|
639 |
+
url = fullUrl; // Update the URL to the unshortened version
|
640 |
+
} else {
|
641 |
+
throw new Error("URL Pinterest không hợp lệ");
|
642 |
+
}
|
643 |
+
|
644 |
+
const pinIdMatch = url.match(pinIdRegex);
|
645 |
+
if (pinIdMatch && pinIdMatch[1]) {
|
646 |
+
return pinIdMatch[1];
|
647 |
+
} else {
|
648 |
+
throw new Error("URL Pinterest không hợp lệ");
|
649 |
+
}
|
650 |
+
} catch (error) {
|
651 |
+
throw new Error("Error getting pin ID: " + error.message);
|
652 |
+
}
|
653 |
+
}
|
654 |
+
|
655 |
+
async function dlpin(url) {
|
656 |
+
const pinId = await getPinIdFromUrl(url);
|
657 |
+
|
658 |
+
const response = await axios.get(`https://www.pinterest.com/resource/PinResource/get/?source_url=&data={"options":{"id":"${pinId}","field_set_key":"auth_web_main_pin","noCache":true,"fetch_visual_search_objects":true},"context":{}}&_=${Date.now()}`);
|
659 |
+
|
660 |
+
if (response.data.resource_response) {
|
661 |
+
const a = {
|
662 |
+
data: response.data.resource_response,
|
663 |
+
video: response.data.resource_response.data.story_pin_data?.pages?.[0]?.blocks?.[0]?.video?.video_list?.V_EXP7?.url || response.data.resource_response.data.videos?.video_list?.V_720P.url,
|
664 |
+
images: response.data.resource_response.data.carousel_data?.carousel_slots?.map(slot => slot.images["600x315"].url) || response.data.resource_response.data.images.orig.url,
|
665 |
+
carousel_data: response.data.resource_response.data.carousel_data,
|
666 |
+
url: response.data.resource_response.data.story_pin_data?.pages?.[0]?.blocks?.[0]?.video?.video_list?.V_HLSV3_MOBILE?.url
|
667 |
+
};
|
668 |
+
return a
|
669 |
+
} else {
|
670 |
+
throw new Error("API Pinterest trả về phản hồi trống");
|
671 |
+
}
|
672 |
+
}
|
673 |
+
module.exports = {
|
674 |
+
listnauan,
|
675 |
+
listca,
|
676 |
+
listcancau,
|
677 |
+
listchim,
|
678 |
+
listcho,
|
679 |
+
listkhunglong,
|
680 |
+
listrong,
|
681 |
+
listthu,
|
682 |
+
datanauan,
|
683 |
+
dataca,
|
684 |
+
datachim,
|
685 |
+
datacho,
|
686 |
+
datakhunglong,
|
687 |
+
datarong,
|
688 |
+
datathu,
|
689 |
+
throwError,
|
690 |
+
getUID,
|
691 |
+
removeHomeDir,
|
692 |
+
getStreamFromURL,
|
693 |
+
getStreamsFromAttachment,
|
694 |
+
getExtFromMimeType,
|
695 |
+
getContent,
|
696 |
+
downloadFile,
|
697 |
+
randomString,
|
698 |
+
cleanAnilistHTML,
|
699 |
+
uploadImgbb,
|
700 |
+
convertTime,
|
701 |
+
getTime,
|
702 |
+
complete,
|
703 |
+
getUID,
|
704 |
+
convertTime1,
|
705 |
+
getFbVideoInfo,
|
706 |
+
tiktok,
|
707 |
+
test,
|
708 |
+
get,
|
709 |
+
dlpin,
|
710 |
+
unshortenUrl,
|
711 |
+
getInfo
|
712 |
+
};
|