put notes/04723b92-5d23-455f-b013-56b4d32388b9.json
Browse files
notes/04723b92-5d23-455f-b013-56b4d32388b9.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "04723b92-5d23-455f-b013-56b4d32388b9",
|
3 |
+
"title": "atd1.js",
|
4 |
+
"content": "const fs = require(\"fs-extra\");\nconst axios = require(\"axios\");\nconst qs = require(\"querystring\");\n\nmodule.exports.config = {\n name: \"Downlink\",\n version: \"2.3.1\",\n hasPermssion: 0,\n credits: \"gấu lỏ\",\n description: \"Tải video\",\n commandCategory: \"Tiện ích\",\n usages: \"Tự động tải khi có link\",\n cooldowns: 5\n};\n\nconst UA_MOBILE =\n \"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36\";\nconst UA_DESKTOP =\n \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36\";\n\nconst TIMEOUT_HTML = 25_000;\nconst TIMEOUT_MEDIA = 30_000;\n\nconst FSAVE_COOKIE =\n \"_ga=GA1.1.651644104.1750425555; PHPSESSID=ok47d858hgdlteh76flbffjc6f; __gads=ID=16733e5ab4e58bf7:T=1750425553:RT=1755494728:S=ALNI_MaqIK2T2wRFqPEy_WLQC35B1qfhcA; __gpi=UID=0000113521187975:T=1750425553:RT=1755494728:S=ALNI_MY_SUQovG8j_GAaZpxzkgD2pn0ALQ; __eoi=ID=17d3d1b3ab422718:T=1750425553:RT=1755494728:S=AA-AfjaR1P3RkOenub5c4jj_9bpF; FCNEC=%5B%5B%22AKsRol_V23ZjJ8iLZfqeTB1E5bmfsKa0WTJqensWxYL8naKHdNpBkcYTMUfIn_r6B9m6mhMHvO08ifkjitjtCJxXp8G5BoQqjhcpEyXMWft83Oj7TS-8unw7udrhemObS8O_Udtq2yjIkZvDs2vNoNA6z3n7c05Rzg%3D%3D%22%5D%5D; _ga_BS5L7X15HP=GS2.1.s1755494727$o5$g1\";\n\nfunction getResolution(s = \"\") {\n const m = String(s).match(/(\\d{3,4})(?=p\\b)/i) || String(s).match(/\\b(\\d{3,4})\\b/);\n return m ? parseInt(m[1], 10) : 0;\n}\nfunction tryParseJSON(text) { try { return JSON.parse(text); } catch { return null; } }\nfunction extractLinksFromHTML(html) {\n const items = [];\n const aTag = /<a[^>]+href=\"([^\"]+)\"[^>]*>([\\s\\S]*?)<\\/a>/gi;\n let m;\n while ((m = aTag.exec(html))) {\n const href = m[1];\n const label = m[2].replace(/<[^>]+>/g, \" \").replace(/\\s+/g, \" \").trim();\n if (/\\.mp4\\b|video/i.test(href)) {\n items.push({ url: href, title: label, quality: getResolution(label) || getResolution(href) });\n }\n }\n const mp4Loose = /https?:\\/\\/[^\\s\"'<>]+\\.mp4[^\\s\"'<>]*/gi;\n let m2;\n while ((m2 = mp4Loose.exec(html))) {\n const href = m2[0];\n if (!items.find(i => i.url === href)) items.push({ url: href, title: \"\", quality: getResolution(href) });\n }\n return items;\n}\nfunction normalizeFsaveJson(json) {\n const items = [];\n function walk(node) {\n if (!node || typeof node !== \"object\") return;\n if (Array.isArray(node)) return node.forEach(walk);\n const url = node.url || node.src || node.href;\n const title = node.title || node.label || node.name || \"\";\n const quality = node.quality || node.q || node.resolution || getResolution(title) || getResolution(url || \"\");\n if (url && /https?:\\/\\//i.test(url) && /\\.mp4/i.test(url)) {\n items.push({ url, title, quality: typeof quality === \"string\" ? getResolution(quality) : (quality || 0) });\n }\n Object.values(node).forEach(walk);\n }\n walk(json);\n return items;\n}\nasync function fetchFacebookFromFsave(fbUrl) {\n const payload = qs.stringify({ url: fbUrl });\n const headers = {\n \"Content-Type\": \"application/x-www-form-urlencoded; charset=UTF-8\",\n \"X-Requested-With\": \"XMLHttpRequest\",\n \"Origin\": \"https://fsave.net\",\n \"Referer\": \"https://fsave.net/vi\",\n \"User-Agent\": UA_MOBILE,\n Cookie: FSAVE_COOKIE\n };\n const resp = await axios.post(\"https://fsave.net/proxy.php\", payload, { headers, timeout: TIMEOUT_HTML });\n const text = typeof resp.data === \"string\" ? resp.data : JSON.stringify(resp.data);\n\n let items = [];\n const asJson = tryParseJSON(text);\n if (asJson) items = normalizeFsaveJson(asJson);\n if (!items.length) items = extractLinksFromHTML(text);\n\n items.sort((a, b) => (b.quality || 0) - (a.quality || 0));\n return items[0] || null;\n}\nfunction pickBestVideoFromDownr(videoList) {\n if (!videoList || !videoList.length) return null;\n return (\n videoList.find(v => v.quality === \"hd_no_watermark\") ||\n videoList.find(v => v.quality === \"no_watermark\") ||\n videoList[0]\n );\n}\nasync function sendPrettyFail(api, threadID, messageID) {\n const body =\n \"\" +\n \"\";\n await api.sendMessage({ body }, threadID, messageID);\n}\n\nmodule.exports.run = async function () { };\n\nmodule.exports.handleEvent = async function ({ api, event }) {\n const { threadID, messageID, body } = event;\n if (!body) return;\n\n const urls = body.match(/https?:\\/\\/[\\w\\d\\-._~:/?#[\\]@!$&'()*+,;=%]+/g);\n if (!urls) return;\n const url = urls[0];\n\n const supported = [\n \"facebook.com\", \"tiktok.com\", \"douyin.com\",\n \"instagram.com\", \"threads.net\", \"youtube.com\",\n \"youtu.be\", \"capcut.com\", \"threads.com\"\n ];\n if (!supported.some(domain => url.includes(domain))) return;\n\n const isFacebook = /facebook\\.com/i.test(url);\n\n let sent = false;\n try {\n const response = await axios.post(\n \"https://downr.org/.netlify/functions/download\",\n { url },\n {\n headers: {\n accept: \"*/*\",\n \"content-type\": \"application/json\",\n origin: \"https://downr.org\",\n referer: \"https://downr.org/\",\n \"user-agent\": UA_DESKTOP\n },\n timeout: TIMEOUT_HTML\n }\n );\n const data = response.data;\n if (data && Array.isArray(data.medias)) {\n const title = data.title || \"Không có tiêu đề\";\n const author = data.author || \"Không rõ\";\n const header =\n `[${(data.source || \"Unknown\").toUpperCase()}] - Tự Động Tải\\n\\n` +\n `👤 Tác giả: ${author}\\n💬 Tiêu đề: ${title}`;\n\n const videoList = data.medias.filter(m => m.type === \"video\");\n const bestVideo = pickBestVideoFromDownr(videoList);\n const images = data.medias.filter(m => m.type === \"image\").map(img => img.url);\n\n const attachments = [];\n for (const imgUrl of images) {\n try {\n const imgStream = (await axios.get(imgUrl, { responseType: \"stream\", timeout: TIMEOUT_HTML })).data;\n attachments.push(imgStream);\n } catch (e) { console.error(\"Ảnh lỗi:\", e.message); }\n }\n if (bestVideo && bestVideo.url) {\n try {\n const videoStream = (await axios.get(bestVideo.url, { responseType: \"stream\", timeout: TIMEOUT_MEDIA })).data;\n attachments.push(videoStream);\n } catch (e) { console.error(\"Video lỗi:\", e.message); }\n }\n if (attachments.length) {\n await api.sendMessage({ body: header, attachment: attachments }, threadID, messageID);\n sent = true;\n }\n }\n } catch (e) {\n console.error(\"Downr lỗi:\", e.message);\n }\n\n if (!sent && isFacebook) {\n try {\n const best = await fetchFacebookFromFsave(url);\n if (best && best.url) {\n const videoStream = (await axios.get(best.url, {\n responseType: \"stream\",\n timeout: TIMEOUT_MEDIA,\n maxRedirects: 5\n })).data;\n const header = `[FACEBOOK] - Tự động tải \\n 👤 Tác giả: \\n💬 Tiêu đề: `;\n await api.sendMessage({ body: header, attachment: videoStream }, threadID, messageID);\n sent = true;\n }\n } catch (e) {\n console.error(\"Fsave lỗi:\", e.message);\n }\n }\n\n if (!sent) {\n await sendPrettyFail(api, threadID, messageID);\n }\n};\n",
|
5 |
+
"language": "javascript",
|
6 |
+
"createdAt": 1758039944595,
|
7 |
+
"updatedAt": 1758039944595
|
8 |
+
}
|