Update rarbg.js
Browse files9 unmodified lines101112131415161718193 unmodified lines23242526272829302 unmodified lines33343536373839404142434445464748495051525354555657585960616263646566676869707172737475767723 unmodified lines1011021031041051061071081091101111121131149 unmodified linestry {const response = await fetch(searchUrl, {headers: {'accept': '*/*','accept-language': 'en-US,en;q=0.9',},method: 'GET',});3 unmodified linesconst 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()).trim();const ddhref = `https://en.rarbg.gg/download.php?id=${id}&f=${target}-[rarbg.com].torrent`;const torrentPageUrl = `https://en.rarbg.gg${href}`;const magnetLink = await fetchMagnetLink(torrentPageUrl); // Sequential requestif (!magnetLink) continue;// Filter out unwanted constant torrentsconst unwantedTitles = ["The Eagle 2011 1080p Bluray x265 HEVC 10bit AAC 5 1 Tigole QXR","Mommy's Little Star 2022 720p Web-DL AAC2 0 H264 LBR","The Bridge on the River Kwai 1957 1080p Bluray 1600MB DD2 0 x264 GalaxyRG","Color My World with Love 2022 Hallmark 720p WebRip HEVC Poke","The Godfather 1972 RM4K Repack 1080p Bluray x265 HEVC 10bit AAC 5 1 Tigole QXR","The Good Neighbor 2022 1080p WebRip DD5 1 x 264 EVO","Firestarter 2022 720p Bluray 800MB x264 GalaxyRG","The Winston Affair 1964 Robert Mitchum War 1080p BRRip x264 Classics"].map(title => title.toLowerCase());if (unwantedTitles.some(title => target.toLowerCase().includes(title))) {console.log(`⏩ Skipping unwanted torrent: ${target}`);continue; // Skip this result if it matches any unwanted title}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;}23 unmodified linesconsole.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}`);9 unmodified lines101112131415163 unmodified lines202122232425262 unmodified lines293031323334353637383940414243444546474849505152535455565758596061626364656667686970717223 unmodified lines969798991001011021031041051061071089 unmodified linestry {const response = await fetch(searchUrl, {headers: { 'accept': '*/*', 'accept-language': 'en-US,en;q=0.9' },method: 'GET',});3 unmodified linesconst pageHtml = await response.text();const $ = cheerio.load(pageHtml);const torrentLinks = $('a[href^="/torrent/"]').toArray();if (torrentLinks.length === 0) {console.log('❌ No torrents found for:', searchQuery);2 unmodified linesconsole.log(`Found ${torrentLinks.length} torrent links`);const unwantedTitles = ["The Eagle 2011 1080p Bluray x265 HEVC 10bit AAC 5 1 Tigole QXR","Mommy's Little Star 2022 720p Web-DL AAC2 0 H264 LBR","The Bridge on the River Kwai 1957 1080p Bluray 1600MB DD2 0 x264 GalaxyRG","Color My World with Love 2022 Hallmark 720p WebRip HEVC Poke","The Godfather 1972 RM4K Repack 1080p Bluray x265 HEVC 10bit AAC 5 1 Tigole QXR","The Good Neighbor 2022 1080p WebRip DD5 1 x 264 EVO","Firestarter 2022 720p Bluray 800MB x264 GalaxyRG","The Winston Affair 1964 Robert Mitchum War 1080p BRRip x264 Classics"].map(title => title.toLowerCase());const torrent_results = [];for (const link of torrentLinks) {const href = $(link).attr('href');const target = ($(link).attr('title') || $(link).text()).trim();if (unwantedTitles.some(title => target.toLowerCase().includes(title))) {console.log(`⏩ Skipping unwanted torrent: ${target}`);continue;}const id = href.split('/')[2];const ddhref = `https://en.rarbg.gg/download.php?id=${id}&f=${target}-[rarbg.com].torrent`;const torrentPageUrl = `https://en.rarbg.gg${href}`;const magnetLink = await fetchMagnetLink(torrentPageUrl);if (!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 ** 4 :unit.toUpperCase() === 'GB' ? 1024 ** 3 :1024 ** 2;sizeInBytes = parseFloat(value) * multiplier;}23 unmodified linesconsole.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 pageasync function fetchMagnetLink(pageUrl) {try {console.log(`🔄 Fetching magnet link from: ${pageUrl}`);
rarbg.js+26-32