UNPKG

@leoo-vanth/zarv-vz

Version:

Modules Downloader.

395 lines (340 loc) 10 kB
const axios = require('axios') const cheerio = require('cheerio') const { createDecipheriv } = require('crypto') const fs = require('fs') async function catbox(path) { const data = new FormData() data.append('reqtype', 'fileupload') data.append('userhash', '') data.append('fileToUpload', fs.createReadStream(path)) roid 10; Mobile; rv:131.0) Gecko/131.0 Firefox/131.0', }, data: data } const api = await axios.request(config) return api.data } async function uguu(path) { try { const form = new FormData() form.append('files[]', fs.createReadStream(path)) const { data } = await axios.post('https://uguu.se/upload', form, { headers: { ...form.getHeaders() } }) return data.files[0].url } catch (err) { throw new Error(err.message) } } async function theoks(path) { try { let form = new FormData() } } async function litterbox(path) { try { let form = new FormData() } async function cloudmini(path) { try { const file_buffer = fs.readFileSync(path) const file_type = path.split('.').pop() }) const { filename } = response.data return `https://files.cloudmini.net/download/${filename}` } catch (err) { throw new Error(err.message) } } async function tempfiles(path) { try { const form = new FormData() form.append('file', fs.createReadStream(path)) throw new Error(err.message) } } async function ytdlv1(url, type, qual = null) { let cookie const match = cookie?.match(/Expires=([^;]+)/) const date = match ? new Date(match[1]) : null const now = new Date() const file_size = FileSize(video_path) return { video: { title: video.title, duration: video.lengthSeconds, }, channel: { name: video.ownerChannelName, subscriber: video.author.subscriber_count, verified: video.author.verified, url: video.author.channel_url }, file_name: `${video.title}.mp4`, file_size, download: video_path } } async function ytdlv2(url, type, quality) { const hex_to_buf = (hex) => Buffer.from(hex, 'hex') const decrypt = (enc) => { try { const secret_key = 'C5D58EF67A7584E4A29F6C35BBC4EB12' const data = Buffer.from(enc, 'base64') const iv = data.slice(0, 16) const content = data.slice(16) const key = hex_to_buf(secret_key) const decipher = createDecipheriv('aes-128-cbc', key, iv) let decrypted = Buffer.concat([decipher.update(content), decipher.final()]) return JSON.parse(decrypted.toString()) } catch (error) { throw new Error(error.message) } } if (type === 'mp3') { const output_file = `./${randomKarakter(4)}.mp3` await convert_audio(file_path, output_file, quality) fs.unlinkSync(file_path) return { title: decrypted.title, format: 'mp3', quality: quality+'kbps', file_size: FileSize(output_file), download: output_file } } return { title: decrypted.title, format: 'mp4', download: file_path } } catch (err) { return { error: err.message } } } async function getTokenFB() { const { data: html } = await axios.get("https://fbdown.me/") const $ = cheerio.load(html) return $("#token").val() } async function fbdl(url) { try { const token = await getTokenFB() const formData = new FormData() thumbnail: data.thumbnail, videos: data.medias.map(v => ({ url: v.url, quality: v.quality, size: v.formattedSize })) } } catch (err) { throw Error(err.message) } } async function igdl(url) { const { data } = await axios.post( 'https://yt1s.io/api/ajaxSearch', new URLSearchParams({ p: 'home', q: url, w: '', lang: 'en' }), { headers: { 'User-Agent': 'Postify/1.0.0', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Accept': 'application/json, text/plain, */*', 'Origin': 'https://yt1s.io', 'Referer': 'https://yt1s.io/' } } ) const $ = cheerio.load(data.data) return $('a.abutton.is-success.is-fullwidth.btn-premium') .map((_, el) => ({ title: $(el).attr('title'), url: $(el).attr('href') })) .get() } async function ttdl(url) { return new Promise(async (resolve, reject) => { try { let data = [] function formatNumber(integer) { second: 'numeric' }) } comment: formatNumber(res.comment_count), share: formatNumber(res.share_count), download: formatNumber(res.download_count) }, author: { id: res.author.id, fullname: res.author.unique_id, nickname: res.author.nickname, avatar: 'https://www.tikwm.com' + res.author.avatar } } resolve(json) } catch (e) { reject(e) } }) } async function ttslide(url) { try { const res = await axios({ method: 'POST', url: 'https://tikvideo.app/api/ajaxSearch', }) } return result.length > 0 ? result : null } catch (err) { throw Error(err.message) } } async function spotify(url) { try { const response = await axios.get(`https://api.siputzx.my.id/api/d/spotify?url=${encodeURIComponent(url)}`) return { title: response.data.data.title, download: response.data.data.download, image: response.data.data.image, duration: response.data.data.durasi } } catch (err) { console.error(err) } } async function capcut(url) { const headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'en-US,en;q=0.9', 'Content-Type': 'application/json;charset=UTF-8', thumbnail: videoData.thumbnail, source: videoData.source, media: videoData.medias.map((item) => ({ url: item.url, quality: item.quality, format: item.extension, size: item.formattedSize })) } } catch (err) { throw Error(err.message) } } async function threads(url) { try { const { data } = await axios.get('https://threads.snapsave.app/api/action', { params: { url: url }, headers: { 'accept': 'application/json, text/plain, */*', 'referer': 'https://threads.snapsave.app/', 'user-agent': 'Postify/1.0.0', }, timeout: 10000, }) const type = (type) => ({ GraphImage: 'Photo', GraphVideo: 'Video', GraphSidecar: 'Gallery', }[type] || type) return { postInfo: { id: data.postinfo.id, thumbnailUrl: item.display_url, videoUrl: item.video_url, duration: item.video_duration, }), })), } } catch (err) { throw Error(err.message) } } async function terabox(url) { const terabox = { api: { base: "https://teraboxdl.site/api/", token: "token", terabox: "terabox" }, headers: { 'authority': 'teraboxdl.site', 'user-agent': 'Postify/1.0.0' }, token: null } const getToken = async () => { if (terabox.token) return terabox.token try { const { data } = await axios.get(`${terabox.api.base}${terabox.api.token}`, { headers: terabox.headers }) terabox.token = data.token return terabox.token } catch (err) { throw Error(err.message) } } const isUrl = (url) => { const match = url.match(/https?:\/\/(?:www\.)?(?:\w+)\.(com|app)\/s\/([^\/]+)/i) return match ? `https://1024terabox.com/s/${match[2]}` : null } } catch (err) { throw Error(err.message) } } const linkNya = isUrl(url.trim()) return await request(terabox.api.terabox, { url: linkNya }) } async function gdrive(url) { let id = (url.match(/\/?id=(.+)/i) || url.match(/\/d\/(.*?)\//))[1] let { data } = await axios.post(`https://drive.google.com/uc?id=${id}&authuser=0&export=download`, null, { kBCMS2yQEIqZ3KAQioo8oBGLeYygE=', 'x-drive-first-party': 'DriveWebUi', 'x-json-requested': 'true' } }) let { fileName, sizeBytes, downloadUrl } = JSON.parse(data.slice(4) return { download: downloadUrl, fileName, fileSize: `${(sizeBytes / (1024 * 1024)).toFixed(2)} MB`, mimetype: (await axios.head(downloadUrl)).headers['content-type'], extension: fileName.split('.').pop(), modified: (await axios.head(downloadUrl)).headers['last-modified'] } } async function whatmusic(input) { try { let file_path = './sampah.mp3' if (Buffer.isBuffer(input)) { fs.writeFileSync(file_path, input) } else if (typeof input === 'string') { let song = metadata.metadata.music[0] let spotify_data = song.external_metadata?.spotify let youtube_id = song.external_metadata?.youtube?.vid || null resolve({ title: song.title, artists: song.artists.map(a => a.name).join(', '), album: song.album.name, release_date: song.release_date, label: song.label, duration: song.duration_ms, spotify: spotify_data?.track?.id ? { name: song.title, url: `https://open.spotify.com/track/${spotify_data.track.id}` } : null, youtube: youtube_id ? `https://www.youtube.com/watch?v=${youtube_id}` : null }) }).catch((err) => reject(err.message)) }) }) } catch (err) { throw Error(err.message) } } module.exports = { catbox, uguu, theoks, litterbox, cloudmini, tempfiles, ytdlv1, ytdlv2, fbdl, igdl, ttdl, ttslide, spotify, capcut, threads, terabox, gdrive, whatmusic }