Update rarbg.js
Browse files
rarbg.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
|
|
| 1 |
import { XMLParser } from 'fast-xml-parser';
|
|
|
|
| 2 |
|
| 3 |
-
//
|
| 4 |
async function fetchRSSFeeds(searchQuery) {
|
| 5 |
const searchUrl = `https://rarbg.to/torrents.php?search=${encodeURIComponent(searchQuery)}&category=movies`;
|
| 6 |
-
|
| 7 |
console.log('\nπ Fetching RARBG search results for:', searchQuery);
|
| 8 |
|
| 9 |
try {
|
|
@@ -20,7 +22,9 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 20 |
}
|
| 21 |
|
| 22 |
const pageHtml = await response.text();
|
| 23 |
-
const
|
|
|
|
|
|
|
| 24 |
|
| 25 |
if (torrentLinks.length === 0) {
|
| 26 |
console.log('β No torrents found for:', searchQuery);
|
|
@@ -29,75 +33,64 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 29 |
|
| 30 |
console.log(`Found ${torrentLinks.length} torrent links`);
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
};
|
| 77 |
-
})
|
| 78 |
-
);
|
| 79 |
-
|
| 80 |
-
const validStreams = torrent_results.filter(Boolean);
|
| 81 |
-
|
| 82 |
-
validStreams.sort((a, b) => {
|
| 83 |
const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
|
| 84 |
const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
|
| 85 |
-
|
| 86 |
-
return b.mainFileSize - a.mainFileSize;
|
| 87 |
-
}
|
| 88 |
-
return qualityDiff;
|
| 89 |
});
|
| 90 |
|
| 91 |
-
console.log(`β
Processed ${
|
| 92 |
-
|
| 93 |
-
return validStreams;
|
| 94 |
} catch (error) {
|
| 95 |
console.error('β Error fetching from RARBG:', error);
|
| 96 |
return [];
|
| 97 |
}
|
| 98 |
}
|
| 99 |
|
| 100 |
-
// Function to fetch the magnet link from a RARBG torrent page
|
| 101 |
async function fetchMagnetLink(pageUrl) {
|
| 102 |
try {
|
| 103 |
console.log(`π Fetching magnet link from: ${pageUrl}`);
|
|
@@ -114,12 +107,11 @@ async function fetchMagnetLink(pageUrl) {
|
|
| 114 |
}
|
| 115 |
}
|
| 116 |
|
|
|
|
| 117 |
function extractQuality(title) {
|
| 118 |
if (!title) return '';
|
| 119 |
-
|
| 120 |
-
// Match quality in title
|
| 121 |
let qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|hdr|dv|blu[- ]?ray|webrip|brrip|dvdrip|hdtv)\b/i);
|
| 122 |
return qualityMatch ? qualityMatch[1].toLowerCase().replace(/[- ]/g, '') : '';
|
| 123 |
}
|
| 124 |
|
| 125 |
-
export { fetchRSSFeeds };
|
|
|
|
| 1 |
+
import fetch from 'node-fetch';
|
| 2 |
import { XMLParser } from 'fast-xml-parser';
|
| 3 |
+
import * as cheerio from 'cheerio';
|
| 4 |
|
| 5 |
+
// Function to fetch RSS feeds and search torrents on RARBG
|
| 6 |
async function fetchRSSFeeds(searchQuery) {
|
| 7 |
const searchUrl = `https://rarbg.to/torrents.php?search=${encodeURIComponent(searchQuery)}&category=movies`;
|
| 8 |
+
|
| 9 |
console.log('\nπ Fetching RARBG search results for:', searchQuery);
|
| 10 |
|
| 11 |
try {
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
const pageHtml = await response.text();
|
| 25 |
+
const $ = cheerio.load(pageHtml);
|
| 26 |
+
|
| 27 |
+
const torrentLinks = $('a[href^="/torrent/"]').toArray(); // Convert to real array
|
| 28 |
|
| 29 |
if (torrentLinks.length === 0) {
|
| 30 |
console.log('β No torrents found for:', searchQuery);
|
|
|
|
| 33 |
|
| 34 |
console.log(`Found ${torrentLinks.length} torrent links`);
|
| 35 |
|
| 36 |
+
// Process torrents sequentially to avoid overwhelming requests
|
| 37 |
+
const torrent_results = [];
|
| 38 |
+
for (const link of torrentLinks) {
|
| 39 |
+
const href = $(link).attr('href');
|
| 40 |
+
const id = href.split('/')[2];
|
| 41 |
+
const target = $(link).attr('title') || $(link).text();
|
| 42 |
+
const ddhref = `http://rarbg.to/download.php?id=${id}&f=${target}-[rarbg.com].torrent`;
|
| 43 |
+
|
| 44 |
+
const torrentPageUrl = `https://rarbg.to${href}`;
|
| 45 |
+
const magnetLink = await fetchMagnetLink(torrentPageUrl); // Sequential request
|
| 46 |
+
|
| 47 |
+
if (!magnetLink) continue;
|
| 48 |
+
|
| 49 |
+
const sizeMatch = $(link).parent().next().text().match(/Size:\s*([\d.]+)\s*(MB|GB|TB)/i);
|
| 50 |
+
const size = sizeMatch ? `${sizeMatch[1]} ${sizeMatch[2]}` : 'Unknown';
|
| 51 |
+
|
| 52 |
+
let sizeInBytes = 0;
|
| 53 |
+
if (sizeMatch) {
|
| 54 |
+
const [, value, unit] = sizeMatch;
|
| 55 |
+
const multiplier = unit.toUpperCase() === 'TB' ? 1024 * 1024 * 1024 * 1024 :
|
| 56 |
+
unit.toUpperCase() === 'GB' ? 1024 * 1024 * 1024 :
|
| 57 |
+
1024 * 1024;
|
| 58 |
+
sizeInBytes = parseFloat(value) * multiplier;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
const infoHashMatch = magnetLink.match(/urn:btih:([A-Za-z0-9]+)/i);
|
| 62 |
+
const infoHash = infoHashMatch ? infoHashMatch[1] : null;
|
| 63 |
+
|
| 64 |
+
let websiteTitle = target.split(' - ')[0];
|
| 65 |
+
|
| 66 |
+
torrent_results.push({
|
| 67 |
+
magnetLink,
|
| 68 |
+
websiteTitle,
|
| 69 |
+
quality: extractQuality(target),
|
| 70 |
+
size,
|
| 71 |
+
source: 'RARBG',
|
| 72 |
+
infoHash,
|
| 73 |
+
mainFileSize: sizeInBytes,
|
| 74 |
+
categories: ['Movies'],
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
// Sort results based on quality and size
|
| 79 |
+
torrent_results.sort((a, b) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
|
| 81 |
const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
|
| 82 |
+
return qualityDiff === 0 ? b.mainFileSize - a.mainFileSize : qualityDiff;
|
|
|
|
|
|
|
|
|
|
| 83 |
});
|
| 84 |
|
| 85 |
+
console.log(`β
Processed ${torrent_results.length} valid streams`);
|
| 86 |
+
return torrent_results;
|
|
|
|
| 87 |
} catch (error) {
|
| 88 |
console.error('β Error fetching from RARBG:', error);
|
| 89 |
return [];
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
+
// Function to fetch the magnet link from a RARBG torrent page (Sequential)
|
| 94 |
async function fetchMagnetLink(pageUrl) {
|
| 95 |
try {
|
| 96 |
console.log(`π Fetching magnet link from: ${pageUrl}`);
|
|
|
|
| 107 |
}
|
| 108 |
}
|
| 109 |
|
| 110 |
+
// Function to extract quality from title
|
| 111 |
function extractQuality(title) {
|
| 112 |
if (!title) return '';
|
|
|
|
|
|
|
| 113 |
let qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|hdr|dv|blu[- ]?ray|webrip|brrip|dvdrip|hdtv)\b/i);
|
| 114 |
return qualityMatch ? qualityMatch[1].toLowerCase().replace(/[- ]/g, '') : '';
|
| 115 |
}
|
| 116 |
|
| 117 |
+
export { fetchRSSFeeds };
|