Update mpeer.js
Browse files12345624 unmodified lines3132333435363738394041424344454647481 unmodified line505152535455565758594 unmodified lines6465666768697071727374757615 unmodified lines929394959697989910010110210310410510610710 unmodified lines11811912012112212312444 unmodified lines169170171172import fetch from 'node-fetch';import * as cheerio from 'cheerio';// ==============================// fetchMegapeerTorrents: Main Export Function// ==============================24 unmodified lines$('tr.table_fon').each((_, element) => {const titleElement = $(element).find('a.url');const websiteTitle = titleElement.text().trim();const torrentPage = titleElement.attr('href');const downloadLink = $(element).find('a[href^="/download/"]').attr('href');const size = $(element).find('td[align="right"]').text().trim();const dateElement = $(element).find('td').first();const date = dateElement.text().trim();// Find the seeds and leechersconst seedLeechCell = $(element).find('td[align="center"]');const seedsMatch = seedLeechCell.html().match(/<font color="#008000"[^>]*>(\d+)<\/font>/i);const leechesMatch = seedLeechCell.html().match(/<font color="#8b0000"[^>]*>(\d+)<\/font>/i);const seeds = seedsMatch ? parseInt(seedsMatch[1]) : 0;const leeches = leechesMatch ? parseInt(leechesMatch[1]) : 0;1 unmodified lineconst torrentPageUrl = `https://megapeer.vip${torrentPage}`;const directDownloadUrl = `https://megapeer.vip${downloadLink}`;const quality = extractQuality(websiteTitle);torrents.push({title: websiteTitle,quality,size,date,4 unmodified lines});});// Process and get magnet links (if available)const completedTorrents = await Promise.all(torrents.map(async (torrent) => {try {// For Megapeer, we might need to extract magnet links from each torrent pageconst magnetLink = await extractMagnetLink(torrent.torrentPageUrl);return {websiteTitle: torrent.title,quality: torrent.quality,15 unmodified linesconst validTorrents = completedTorrents.filter(Boolean);// Sorting: Highest Seeds, Quality & SizevalidTorrents.sort((a, b) => {// Primary sort by seedsif (b.seeds !== a.seeds) return b.seeds - a.seeds;// Secondary sort by qualityconst qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);// Tertiary sort by sizereturn qualityDiff === 0 ? b.mainFileSize - a.mainFileSize : qualityDiff;});10 unmodified lines// ==============================async function extractMagnetLink(torrentPageUrl) {try {await new Promise(resolve => setTimeout(resolve, Math.random() * 2000 + 1000)); // 1-3 sec delayconst response = await fetch(torrentPageUrl, {headers: {44 unmodified lines// ==============================// Export for Server.js// ==============================export { fetchMegapeerTorrents };1234567891011121314151617181920212224 unmodified lines474849505152535455565758596061626364651 unmodified line676869707172737475764 unmodified lines8182838485868788899015 unmodified lines10610710810911011111211311411511611710 unmodified lines12812913013113213313444 unmodified lines179180181182import fetch from 'node-fetch';import * as cheerio from 'cheerio';// ==============================// sanitizeTitle: Clean Cyrillic & Noise// ==============================function sanitizeTitle(rawTitle) {return rawTitle.replace(/[\u0400-\u04FF]+/g, '') // Remove Cyrillic.replace(/[^\x00-\x7F]+/g, '') // Remove non-ASCII remnants.replace(/\[\s*[\u0400-\u04FF\d]+\s*[\u0400-\u04FF]*\]/g, match => {const digits = match.match(/\d+/);return digits ? `[${digits[0]}]` : '';}).replace(/\s{2,}/g, ' ') // Collapse multiple spaces.replace(/^\/\s*/, '') // Trim leading slashes.trim();}// ==============================// fetchMegapeerTorrents: Main Export Function// ==============================24 unmodified lines$('tr.table_fon').each((_, element) => {const titleElement = $(element).find('a.url');const rawTitle = titleElement.text().trim();const sanitizedTitle = sanitizeTitle(rawTitle);const torrentPage = titleElement.attr('href');const downloadLink = $(element).find('a[href^="/download/"]').attr('href');const size = $(element).find('td[align="right"]').text().trim();const dateElement = $(element).find('td').first();const date = dateElement.text().trim();const seedLeechCell = $(element).find('td[align="center"]');const seedsMatch = seedLeechCell.html().match(/<font color="#008000"[^>]*>(\d+)<\/font>/i);const leechesMatch = seedLeechCell.html().match(/<font color="#8b0000"[^>]*>(\d+)<\/font>/i);const seeds = seedsMatch ? parseInt(seedsMatch[1]) : 0;const leeches = leechesMatch ? parseInt(leechesMatch[1]) : 0;1 unmodified lineconst torrentPageUrl = `https://megapeer.vip${torrentPage}`;const directDownloadUrl = `https://megapeer.vip${downloadLink}`;const quality = extractQuality(sanitizedTitle);torrents.push({title: sanitizedTitle,quality,size,date,4 unmodified lines});});const completedTorrents = await Promise.all(torrents.map(async (torrent) => {try {const magnetLink = await extractMagnetLink(torrent.torrentPageUrl);return {websiteTitle: torrent.title,quality: torrent.quality,15 unmodified linesconst validTorrents = completedTorrents.filter(Boolean);validTorrents.sort((a, b) => {if (b.seeds !== a.seeds) return b.seeds - a.seeds;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;});10 unmodified lines// ==============================async function extractMagnetLink(torrentPageUrl) {try {await new Promise(resolve => setTimeout(resolve, Math.random() * 2000 + 1000));const response = await fetch(torrentPageUrl, {headers: {44 unmodified lines// ==============================// Export for Server.js// ==============================export { fetchMegapeerTorrents };
mpeer.js+27-17