UNPKG

tester-scraper

Version:

Sebuah Module Scraper yang dibuat oleh Sxyz dan SuzakuTeam untuk memudahkan penggunaan scraper di project ESM maupun CJS.

290 lines (269 loc) 8.13 kB
const axios = require("axios"); const FormDatas = require("form-data"); const cheerio = require("cheerio"); const { jsToCoffee, jsToCoffeeEsm } = require("./lib/jsToCoffee.cjs"); /** * Tools Object * * EN: This object exports a collection of utility functions that can be reused in various parts of your project. * Currently, it includes a function to detect NSFW (Not Safe For Work) content in an image using an external API. * * ID: Objek ini mengekspor kumpulan fungsi utilitas yang bisa digunakan ulang di berbagai bagian proyek kamu. * Saat ini, ia mencakup fungsi untuk mendeteksi konten NSFW (tidak pantas) pada gambar dengan bantuan API eksternal. */ const tools = { nsfwDetector: async (imgUrl) => { const { data } = await axios.get(imgUrl, { responseType: "arraybuffer", }); const buffer = Buffer.from(data, "binary"); const form = new FormDatas(); form.append("image", buffer, { filename: "image.jpg" }); const headers = form.getHeaders(); const { data: result } = await axios.post( "https://nsfw-categorize.it/api/upload", form, { headers, }, ); return result; }, ttsmp3: async (text, char) => { const aiChar = { nova: "nova", alloy: "alloy", ash: "ash", coral: "coral", echo: "echo", fable: "fable", onyx: "onyx", sage: "sage", shimmer: "shimmer", }; if (!Object.keys(aiChar).includes(char)) { return { errorCode: 403, message: "Char Tidak Valid!", validChar: Object.keys(aiChar).join(", "), }; } try { const form = new FormDatas(); form.append("msg", text); form.append("lang", aiChar[char]); form.append("speed", "1.00"); form.append("source", "ttsmp3"); const headersList = { headers: { ...form.getHeaders(), }, }; const { data } = await axios.post( "https://ttsmp3.com/makemp3_ai.php", form, headersList, ); return data; } catch (e) { return { errorCode: e?.response?.status || 500, message: e.message, }; } }, checkHost: async (hostName) => { const requestOne = await axios.get("https://check-host.net/ip-info"); const $ = cheerio.load(requestOne.data); const csrf = $("input[name='csrf_token']").val(); const { data } = await axios.get( `https://check-host.net/ip-info?host=${hostName}&csrf_token=${csrf}`, ); const $$ = cheerio.load(data); const info = {}; const tableRows = $$("#ip_info-dbip table tr"); tableRows.each((_, row) => { const key = $$(row).find("td").first().text().trim(); const valueTd = $$(row).find("td").last(); const flagSrc = valueTd.find("img.inline.flag").attr("src"); if (flagSrc) { info.image = `https://check-host.net${flagSrc}`; } const textContent = valueTd.text().replace(/\s+/g, " ").trim(); if (key && textContent) { info[key] = textContent; } }); return info; }, pornDetector: async (imgUrl) => { const buffers = await axios.get(imgUrl, { responseType: "arraybuffer", }); const binarys = Buffer.from(buffers.data, "binary"); const d = new FormDatas(); d.append("file", binarys, { filename: "porn-detector.jpg" }); const headers = { headers: { ...d.getHeaders(), }, }; const { data } = await axios.post( "https://www.nyckel.com/v1/functions/o2f0jzcdyut2qxhu/invoke", d, headers, ); return data; }, saveWebsite: async (url) => { const payload = { url: url, alternativeAlgorithm: false, mobileVersion: false, renameAssets: false, saveStructure: false, }; const { data } = await axios.post( "https://copier.saveweb2zip.com/api/copySite", payload, ); const { md5 } = data; let dataResult; do { const { data: checkResult } = await axios.get( `https://copier.saveweb2zip.com/api/getStatus/${md5}`, ); dataResult = checkResult; } while (!dataResult.success); return { success: true, downloadUrl: `https://copier.saveweb2zip.com/api/downloadArchive/${md5}`, isFinished: true, }; }, translate: async (text, oriLang, toLang) => { if (!text || !oriLang || !toLang) return { message: "Text, OriLang atau ToLang tidak bisa kosong!", queryOfFunction: { text: text || "", oriLang: oriLang || "", toLang: toLang || "", }, }; const apiUrl = "https://api.translasion.com/enhance/dictionary"; const datas = { app_key: "", from: oriLang, gpt_switch: "0", override_from_flag: "0", scene: 100, system_lang: "en", to: toLang, word: text, }; const { data } = await axios.post(apiUrl, datas); return data; }, ytTranscript: async (url) => { if (!url) { return { message: "Parameter Url Tidak Di Isi!", error: true, }; } try { const { data } = await axios.get( `https://apiv2.anthiago.com/transkrip?get_video=${encodeURIComponent(url)}&codeL=id&status=false`, { headers: { Host: "apiv2.anthiago.com", Connection: "keep-alive", Accept: "application/json, text/plain, */*", DNT: "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36", Referer: "https://anthiago.com/", Origin: "https://anthiago.com", "Accept-Language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7", "Accept-Encoding": "gzip, deflate, br", "Upgrade-Insecure-Requests": "1", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-site", "Sec-Ch-Ua": '"Chromium";v="125", "Not.A/Brand";v="8"', "Sec-Ch-Ua-Mobile": "?0", "Sec-Ch-Ua-Platform": '"Windows"', }, }, ); if (data.status !== "ok" || !Array.isArray(data.subtitles)) { return { message: "Gagal mengambil transkrip.", error: true, }; } const transkrip = data.subtitles.map((item) => item.f).join(" "); return { title: data.title, url: data.urlBase, transkrip, error: false, }; } catch (err) { return { message: "Terjadi kesalahan saat mengambil transkrip.", error: true, detail: err.message, }; } }, jsToCoffeeScript: { cjs: async (code) => { const ress = await jsToCoffee(code); return ress; }, esm: async (code) => { const ress = await jsToCoffeeEsm(code); return ress; }, }, pairingCode: async (num) => { const { data: { key }, } = await axios.get( `https://knight-bot-paircode.onrender.com/code?number=${num}`, ); return { codePairing: key, }; }, hostingChecker: async (urlWeb) => { if (!urlWeb) throw new Error("Insert a URL website."); const ds = new FormDatas(); ds.append("target", urlWeb); ds.append("submit", "Find Host"); const headers = { headers: { ...ds.getHeaders(), }, }; const { data } = await axios.post( "https://hostingchecker.com/", ds, headers, ); const $ = cheerio.load(data); const pTags = $(".hcresults p").toArray(); return { hosted_by: $(pTags[0]).find("b").text().trim() || null, organization: $(pTags[2]).find("b").text().trim() || null, ip_address: $(pTags[3]).find("b").text().trim() || null, as_number_and_org: $(pTags[4]).find("b").text().trim() || null, as_name: $(pTags[5]).find("b").text().trim() || null, city: $(pTags[7]).find("b").text().trim() || null, country: $(pTags[8]).find("b").text().trim() || null, }; }, }; module.exports = tools;