Update rarbg.js
Browse files12345678910 unmodified lines202122232425262 unmodified lines293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310 unmodified lines114115116117118119120121122123124125import { XMLParser } from 'fast-xml-parser';// Single fetchRSSFeeds export for searching torrents on RARBGasync function fetchRSSFeeds(searchQuery) {const searchUrl = `https://rarbg.to/torrents.php?search=${encodeURIComponent(searchQuery)}&category=movies`;console.log('\n๐ Fetching RARBG search results for:', searchQuery);try {10 unmodified lines}const pageHtml = await response.text();const torrentLinks = $(pageHtml).find('a[href^="/torrent/"]'); // Finding torrent links on the pageif (torrentLinks.length === 0) {console.log('โ No torrents found for:', searchQuery);2 unmodified linesconsole.log(`Found ${torrentLinks.length} torrent links`);const torrent_results = await Promise.all(torrentLinks.map(async (i, link) => {const href = $(link).attr('href');const id = href.split('/')[2]; // Extract torrent IDconst target = $(link).attr('title') || $(link).html(); // Extract the title or textconst ddhref = `http://rarbg.to/download.php?id=${id}&f=${target}-[rarbg.com].torrent`; // Direct download linkconst torrentPageUrl = `https://rarbg.to${href}`;const magnetLink = await fetchMagnetLink(torrentPageUrl); // Fetch magnet linkif (!magnetLink) return null;const sizeMatch = $(link).parent().next().text().match(/Size:\s*([\d.]+)\s*(MB|GB|TB)/i); // Extract size infoconst size = sizeMatch ? `${sizeMatch[1]} ${sizeMatch[2]}` : 'Unknown';let sizeInBytes = 0;if (sizeMatch) {const [, value, unit] = sizeMatch;const multiplier =unit.toUpperCase() === 'TB'? 1024 * 1024 * 1024 * 1024: unit.toUpperCase() === 'GB'? 1024 * 1024 * 1024: 1024 * 1024;sizeInBytes = parseFloat(value) * multiplier;}const infoHashMatch = magnetLink.match(/urn:btih:([A-Za-z0-9]+)/i);const infoHash = infoHashMatch ? infoHashMatch[1] : null;let websiteTitle = target;if (websiteTitle.includes(' - ')) {websiteTitle = websiteTitle.split(' - ')[0]; // Take only the first part of the title}return {magnetLink,websiteTitle,quality: extractQuality(target),size,source: 'RARBG',infoHash,mainFileSize: sizeInBytes,categories: ['Movies'], // Assuming a default category, can be adjusted};}));const validStreams = torrent_results.filter(Boolean);validStreams.sort((a, b) => {const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);if (qualityDiff === 0) {return b.mainFileSize - a.mainFileSize;}return qualityDiff;});console.log(`โ Processed ${validStreams.length} valid streams`);return validStreams;} catch (error) {console.error('โ Error fetching from RARBG:', error);return [];}}// Function to fetch the magnet link from a RARBG torrent pageasync function fetchMagnetLink(pageUrl) {try {console.log(`๐ Fetching magnet link from: ${pageUrl}`);10 unmodified lines}}function extractQuality(title) {if (!title) return '';// Match quality in titlelet qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|hdr|dv|blu[- ]?ray|webrip|brrip|dvdrip|hdtv)\b/i);return qualityMatch ? qualityMatch[1].toLowerCase().replace(/[- ]/g, '') : '';}export { fetchRSSFeeds };123456789101110 unmodified lines2223242526272829302 unmodified lines3334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959610 unmodified lines107108109110111112113114115116117import fetch from 'node-fetch';import { XMLParser } from 'fast-xml-parser';import * as cheerio from 'cheerio';// Function to fetch RSS feeds and search torrents on RARBGasync function fetchRSSFeeds(searchQuery) {const searchUrl = `https://rarbg.to/torrents.php?search=${encodeURIComponent(searchQuery)}&category=movies`;console.log('\n๐ Fetching RARBG search results for:', searchQuery);try {10 unmodified lines}const pageHtml = await response.text();const $ = cheerio.load(pageHtml);const torrentLinks = $('a[href^="/torrent/"]').toArray(); // Convert to real arrayif (torrentLinks.length === 0) {console.log('โ No torrents found for:', searchQuery);2 unmodified linesconsole.log(`Found ${torrentLinks.length} torrent links`);// Process torrents sequentially to avoid overwhelming requestsconst torrent_results = [];for (const link of torrentLinks) {const href = $(link).attr('href');const id = href.split('/')[2];const target = $(link).attr('title') || $(link).text();const ddhref = `http://rarbg.to/download.php?id=${id}&f=${target}-[rarbg.com].torrent`;const torrentPageUrl = `https://rarbg.to${href}`;const magnetLink = await fetchMagnetLink(torrentPageUrl); // Sequential requestif (!magnetLink) continue;const sizeMatch = $(link).parent().next().text().match(/Size:\s*([\d.]+)\s*(MB|GB|TB)/i);const size = sizeMatch ? `${sizeMatch[1]} ${sizeMatch[2]}` : 'Unknown';let sizeInBytes = 0;if (sizeMatch) {const [, value, unit] = sizeMatch;const multiplier = unit.toUpperCase() === 'TB' ? 1024 * 1024 * 1024 * 1024 :unit.toUpperCase() === 'GB' ? 1024 * 1024 * 1024 :1024 * 1024;sizeInBytes = parseFloat(value) * multiplier;}const infoHashMatch = magnetLink.match(/urn:btih:([A-Za-z0-9]+)/i);const infoHash = infoHashMatch ? infoHashMatch[1] : null;let websiteTitle = target.split(' - ')[0];torrent_results.push({magnetLink,websiteTitle,quality: extractQuality(target),size,source: 'RARBG',infoHash,mainFileSize: sizeInBytes,categories: ['Movies'],});}// Sort results based on quality and sizetorrent_results.sort((a, b) => {const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);return qualityDiff === 0 ? b.mainFileSize - a.mainFileSize : qualityDiff;});console.log(`โ Processed ${torrent_results.length} valid streams`);return torrent_results;} catch (error) {console.error('โ Error fetching from RARBG:', error);return [];}}// Function to fetch the magnet link from a RARBG torrent page (Sequential)async function fetchMagnetLink(pageUrl) {try {console.log(`๐ Fetching magnet link from: ${pageUrl}`);10 unmodified lines}}// Function to extract quality from titlefunction extractQuality(title) {if (!title) return '';let qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|hdr|dv|blu[- ]?ray|webrip|brrip|dvdrip|hdtv)\b/i);return qualityMatch ? qualityMatch[1].toLowerCase().replace(/[- ]/g, '') : '';}export { fetchRSSFeeds };
rarbg.js+57-65