UNPKG

xnxx-peex-dl

Version:

XNXX Video Downloader by PeeX

81 lines (69 loc) 2.74 kB
const axios = require("axios"); const fs = require("fs"); const cheerio = require("cheerio"); const path = require("path"); const headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", "Accept-Language": "id-ID,id;q=0.9", "Referer": "https://www.xnxx.com/", "Connection": "keep-alive" }; async function downloadFile(fileURL, outputPath) { try { const response = await axios({ url: fileURL, method: "GET", responseType: "stream", headers }); const writer = fs.createWriteStream(outputPath); response.data.pipe(writer); return new Promise((resolve, reject) => { writer.on("finish", () => resolve(outputPath)); writer.on("error", () => reject(null)); }); } catch { return null; } } async function scrapeXNXX(videoURL, outputFolder = "./xnxx_downloads") { try { const response = await axios.get(videoURL, { headers }); const $ = cheerio.load(response.data); const title = $('meta[property="og:title"]').attr("content") || "Unknown Title"; const thumbnail = $('meta[property="og:image"]').attr("content") || null; const dateUpload = $("span.metadata").first().text().trim() || "Unknown Date"; let videoLink = null; $("script").each((_, element) => { const scriptContent = $(element).html(); if (scriptContent.includes('"contentUrl"')) { const match = scriptContent.match(/"contentUrl"\s*:\s*"([^"]+)"/); if (match) videoLink = match[1]; } }); if (!videoLink) { throw new Error("Gagal mendapatkan link video."); } if (!fs.existsSync(outputFolder)) fs.mkdirSync(outputFolder, { recursive: true }); let thumbnailPath = "No Thumbnail"; if (thumbnail) { const thumbFileName = path.join(outputFolder, `${title.replace(/\s+/g, "_")}_thumbnail.jpg`); thumbnailPath = await downloadFile(thumbnail, thumbFileName) || "Failed to download"; } let videoPath = "No Video"; if (videoLink) { const videoFileName = path.join(outputFolder, `${title.replace(/\s+/g, "_")}.mp4`); videoPath = await downloadFile(videoLink, videoFileName) || "Failed to download"; } return { title, thumbnail: thumbnailPath, video: videoPath, dateUpload, sourceURL: videoURL }; } catch (err) { throw new Error("Error: " + err.message); } } module.exports = { scrapeXNXX };