From da4ffd85935346710348af9eb7147df8c63237e0 Mon Sep 17 00:00:00 2001 From: Tas33n <55633040+tas33n@users.noreply.github.com> Date: Sun, 11 Aug 2024 10:37:35 +0000 Subject: [PATCH 1/7] use youtube cookie to avoid bot restrictions. --- scripts/cmds/ytb.js | 436 +++++++++++++++++++++++++------------------- ytdl.json | 1 + 2 files changed, 246 insertions(+), 191 deletions(-) create mode 100644 ytdl.json diff --git a/scripts/cmds/ytb.js b/scripts/cmds/ytb.js index 63df97e80f..0dee98f2b9 100644 --- a/scripts/cmds/ytb.js +++ b/scripts/cmds/ytb.js @@ -2,52 +2,56 @@ const axios = require("axios"); const ytdl = require("@distube/ytdl-core"); const fs = require("fs-extra"); const { getStreamFromURL, downloadFile, formatNumber } = global.utils; +const agent = ytdl.createAgent( + JSON.parse(fs.readFileSync(process.cwd() + "/ytdl.json")) +); async function getStreamAndSize(url, path = "") { const response = await axios({ method: "GET", url, responseType: "stream", headers: { - 'Range': 'bytes=0-' - } + Range: "bytes=0-", + }, }); - if (path) - response.data.path = path; + if (path) response.data.path = path; const totalLength = response.headers["content-length"]; return { stream: response.data, - size: totalLength + size: totalLength, }; } module.exports = { config: { name: "ytb", - version: "1.16", + version: "1.17", author: "NTKhang", countDown: 5, role: 0, description: { vi: "Tải video, audio hoặc xem thông tin video trên YouTube", - en: "Download video, audio or view video information on YouTube" + en: "Download video, audio or view video information on YouTube", }, category: "media", guide: { - vi: " {pn} [video|-v] [|]: dùng để tải video từ youtube." - + "\n {pn} [audio|-a] [|]: dùng để tải audio từ youtube" - + "\n {pn} [info|-i] [|]: dùng để xem thông tin video từ youtube" - + "\n Ví dụ:" - + "\n {pn} -v Fallen Kingdom" - + "\n {pn} -a Fallen Kingdom" - + "\n {pn} -i Fallen Kingdom", - en: " {pn} [video|-v] [