UNPKG

@srart24/scraper

Version:

@srart24/scraper adalah sebuah module npm yang menyediakan berbagai fitur seru dan berguna seperti pengunduh konten dari platform populer, teks acak, permainan interaktif, dan berbagai fungsi hiburan.

232 lines (220 loc) 7.97 kB
// @srart24 const got = require("got"); const cheerio = require('cheerio'); const fetch = require("node-fetch"); const { JSDOM } = require("jsdom"); const yts = require("usetube"); const axios = require('axios').default; const { cNm, post, timeFormat } = require('../utils/index.js'); const tiktokIdef = /(?:https?:\/\/)?(?:www\.)?tiktok\.com/ const ytr = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/; async function yt(url, quality, type, bitrate, server = "en68") { if (!ytr.test(url)) throw "Invalid URL"; let ytId = ytr.exec(url); url = "https://youtu.be/" + ytId[1]; let timesamp = await (await yts.searchVideo(ytId[1])).videos.find((v) => v.id == ytId[1]); let res = await post(`https://www.y2mate.com/mates/${server}/analyze/ajax`, { url, q_auto: 0, ajax: 1, }); let json = await res.json(); let { document } = new JSDOM(json.result).window; let tables = document.querySelectorAll("table"); let table = tables[ { mp4: 0, mp3: 1, }[type] || 0 ]; let list; switch (type) { case "mp4": list = Object.fromEntries( [...table.querySelectorAll('td > a[href="#"]')] .filter((v) => !/\.3gp/.test(v.innerHTML)) .map((v) => [ v.innerHTML.match(/.*?(?=\()/)[0].trim(), v.parentElement.nextSibling.nextSibling.innerHTML, ]) ); break; case "mp3": list = { "128kbps": table.querySelector('td > a[href="#"]').parentElement.nextSibling.nextSibling.innerHTML, }; break; default: list = {}; } let filesize = list[quality]; let id = /var k__id = "(.*?)"/.exec(document.body.innerHTML) || ["", ""]; let thumb = document.querySelector("img").src; let title = document.querySelector("b").innerHTML; let res2 = await post(`https://www.y2mate.com/mates/convert`, { type: "youtube", _id: id[1], v_id: ytId[1], ajax: "1", token: "", ftype: type, fquality: bitrate, }); let json2 = await res2.json(); let KB = parseFloat(filesize) * (1000 * /MB$/.test(filesize)); let reshs = { result: { title, thumb, duration: timeFormat(typeof timesamp != "undefined" ? timesamp.duration : 0), link: /<a.+?href="(.+?)"/.exec(json2.result)[1], } } return reshs } module.exports = class downloader { tiktok = async (url) => { if (!url) throw new Error('Masukkan URL TikTok'); if (!url.match(tiktokIdef)) throw new Error('URL Bukan Dari TikTok'); for (let attempts = 0; attempts < 3; attempts++) { try { const data = await got.post('https://api.tikmate.app/api/lookup', { form: { url } }).json(); let hasil = { username: '@' + data.author_name, upload: data.create_time, like: await cNm(data.like_count), share: await cNm(data.share_count), link: `https://tikmate.app/download/${data.token}/${data.id}.mp4` }; let hslnya = { result: hasil } return hslnya; } catch (error) { console.log(`Percobaan ke ${attempts + 1} gagal`, error); } } throw new Error('Internal Server Error') }; instagram = async (url) => { return new Promise(async (resolve) => { try { if (!url.match(/(?:https?:\/\/(web\.|www\.|m\.)?(facebook|fb)\.(com|watch)\S+)?$/) && !url.match(/(https|http):\/\/www.instagram.com\/(p|reel|tv|stories)/gi)) return resolve({ msg: `Link Url Tidak Falid` }) function decodeSnapApp(args) { let [h, u, n, t, e, r] = args // @ts-ignore function decode (d, e, f) { const g = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/'.split('') let h = g.slice(0, e) let i = g.slice(0, f) // @ts-ignore let j = d.split('').reverse().reduce(function (a, b, c) { if (h.indexOf(b) !== -1) return a += h.indexOf(b) * (Math.pow(e, c)) }, 0) let k = '' while (j > 0) { k = i[j % f] + k j = (j - (j % f)) / f } return k || '0' } r = '' for (let i = 0, len = h.length; i < len; i++) { let s = "" // @ts-ignore while (h[i] !== n[e]) { s += h[i]; i++ } for (let j = 0; j < n.length; j++) s = s.replace(new RegExp(n[j], "g"), j.toString()) // @ts-ignore r += String.fromCharCode(decode(s, e, 10) - t) } return decodeURIComponent(encodeURIComponent(r)) } function getEncodedSnapApp(data) { return data.split('decodeURIComponent(escape(r))}(')[1] .split('))')[0] .split(',') .map(v => v.replace(/"/g, '').trim()) } function getDecodedSnapSave (data) { return data.split('getElementById("download-section").innerHTML = "')[1] .split('"; document.getElementById("inputData").remove(); ')[0] .replace(/\\(\\)?/g, '') } function decryptSnapSave(data) { return getDecodedSnapSave(decodeSnapApp(getEncodedSnapApp(data))) } const html = await got.post('https://snapsave.app/action.php?lang=id', { headers: { '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', 'content-type': 'application/x-www-form-urlencoded','origin': 'https://snapsave.app', 'referer': 'https://snapsave.app/id', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36' }, form: { url } }).text() const decode = decryptSnapSave(html) const $ = cheerio.load(decode) const results = [] if ($('table.table').length || $('article.media > figure').length) { const thumbnail = $('article.media > figure').find('img').attr('src') $('tbody > tr').each((_, el) => { const $el = $(el) const $td = $el.find('td') const resolution = $td.eq(0).text() let _url = $td.eq(2).find('a').attr('href') || $td.eq(2).find('button').attr('onclick') const shouldRender = /get_progressApi/ig.test(_url || '') if (shouldRender) { _url = /get_progressApi\('(.*?)'\)/.exec(_url || '')?.[1] || _url } results.push(_url) }) } else { $('div.download-items__thumb').each((_, tod) => { const thumbnail = $(tod).find('img').attr('src') $('div.download-items__btn').each((_, ol) => { let _url = $(ol).find('a').attr('href') if (!/https?:\/\//.test(_url || '')) _url = `https://snapsave.app${_url}` results.push(_url) }) }) } if (!results.length) return resolve({ msg: `Blank data` }) return resolve({ result: results }) } catch (e) { console.log(e) return resolve({ msg: "Error Cuy" }) } }) } telegramsticker = async (url) => { try { if (!url.match(/(https:\/\/t.me\/addstickers\/)/gi)) { throw new Error('Enter your Telegram sticker URL'); } const packName = url.replace("https://t.me/addstickers/", ""); const response = await axios.get(`https://api.telegram.org/bot891038791:AAHWB1dQd-vi0IbH2NjKYUk-hqQ8rQuzPD4/getStickerSet?name=${encodeURIComponent(packName)}`, { headers: { "User-Agent": "GoogleBot" } }); const hasil = []; for (const sticker of response.data.result.stickers) { const fileId = sticker.thumb.file_id; const response2 = await axios.get(`https://api.telegram.org/bot891038791:AAHWB1dQd-vi0IbH2NjKYUk-hqQ8rQuzPD4/getFile?file_id=${fileId}`); const res = `https://api.telegram.org/file/bot891038791:AAHWB1dQd-vi0IbH2NjKYUk-hqQ8rQuzPD4/${response2.data.result.file_path}`; hasil.push(res); } const resultObject = { result: hasil }; return resultObject; } catch (error) { return { error: error.message }; } } ytv = async (url, server = "en406") => { try { let to = await yt(url, "480p", "mp4", "480", server); return to } catch (error) { return { result: "error" } } } }