Update solid.js
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081 unmodified line110111112113114115116117118119120121122123124125126127128129130131import fetch from 'node-fetch';import { JSDOM } from 'jsdom';// Function to extract video quality from the titlefunction extractQuality(title) {if (!title) return '';const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd)\b/i);return qualityMatch ? qualityMatch[1].toLowerCase() : '';}// Function to extract hash from magnet linksfunction extractHash(magnetLink) {const hashMatch = magnetLink.match(/btih:([A-Fa-f0-9]{40})/);return hashMatch ? hashMatch[1] : '';}// Function to generate a direct magnet link from a hashfunction createMagnetLink(hash) {return `magnet:?xt=urn:btih:${hash}`;}// Function to format size from raw textfunction formatSize(sizeText) {return sizeText.replace('Size', '').trim();}// Function to test token validityasync function testTokenValidity(magnetLink, token) {if (!token) {console.log("⚠️ No token provided, skipping token test.");return;}console.log(`🔍 Testing token for magnet link: ${magnetLink}`);try {const url = new URL(magnetLink);url.searchParams.append('token', token);const response = await fetch(url.toString(), {headers: {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36','Referer': 'https://solidtorrents.to/','Accept-Language': 'en-US,en;q=0.9','Connection': 'keep-alive','DNT': '1','Upgrade-Insecure-Requests': '1'}});if (response.ok) {console.log("✅ Token is valid! Magnet link works with the token.");} else {console.log("❌ Token might not be necessary or is invalid.");}} catch (error) {console.error("❌ Error testing token validity:", error);}}// Function to fetch and parse search results from SolidTorrentsasync function fetchRSSFeeds(searchQuery) {console.log(`🔄 Searching SolidTorrents for: "${searchQuery}"`);try {const url = `https://solidtorrents.to/search?q=${encodeURIComponent(searchQuery)}`;const response = await fetch(url, {headers: {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36','Referer': 'https://solidtorrents.to/','Accept-Language': 'en-US,en;q=0.9','Connection': 'keep-alive','DNT': '1','Upgrade-Insecure-Requests': '1'}});if (!response.ok) {throw new Error(`Failed to fetch search page: ${response.status}`);}const html = await response.text();const dom = new JSDOM(html);const torrents = [];dom.window.document.querySelectorAll('.search-result').forEach(item => {const titleElement = item.querySelector('h5.title a');const magnetElement = item.querySelector('a[href^="magnet:?xt=urn:btih:"]');const sizeElement = item.querySelector('.stats div:nth-child(2)');const seedersElement = item.querySelector('.stats div:nth-child(3) font');const leechersElement = item.querySelector('.stats div:nth-child(4) font');const tokenElement = magnetElement ? magnetElement.getAttribute('data-token') : null;if (!titleElement || !magnetElement) return;const title = titleElement.textContent.trim();const magnetLink = magnetElement.getAttribute('href');const hash = extractHash(magnetLink);const quality = extractQuality(title);const size = sizeElement ? formatSize(sizeElement.textContent) : 'Unknown';const seeders = seedersElement ? parseInt(seedersElement.textContent) : 0;const leechers = leechersElement ? parseInt(leechersElement.textContent) : 0;const token = tokenElement ? tokenElement.trim() : null;torrents.push({title,magnetLink,hash,1 unmodified linesize,seeders,leechers,token});});console.log(`✅ Found ${torrents.length} torrents with magnet links.`);// Test token validity for the first result (if available)if (torrents.length > 0) {await testTokenValidity(torrents[0].magnetLink, torrents[0].token);}return torrents;} catch (error) {console.error('❌ Error fetching from SolidTorrents:', error);return [];}}export { fetchRSSFeeds };123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475761 unmodified line78798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138import fetch from 'node-fetch';import { JSDOM } from 'jsdom';const SITE_CONFIG = {baseUrl: 'https://solidtorrents.to',fallbackUrls: ['https://solidtorrents.cc','https://solidtorrents.me']};function extractQuality(title) {if (!title) return '';const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd)\b/i);return qualityMatch ? qualityMatch[1].toLowerCase() : '';}function extractHash(magnetLink) {const hashMatch = magnetLink.match(/btih:([A-Fa-f0-9]{40})/);return hashMatch ? hashMatch[1] : '';}function createMagnetLink(hash) {return `magnet:?xt=urn:btih:${hash}`;}function parseSize(sizeStr) {if (!sizeStr) return 0;const match = sizeStr.match(/([\d.]+)\s*(B|KB|MB|GB|TB)/i);if (!match) return 0;const [, value, unit] = match;const multipliers = {'B': 1,'KB': 1024,'MB': 1024 * 1024,'GB': 1024 * 1024 * 1024,'TB': 1024 * 1024 * 1024 * 1024};return parseFloat(value) * multipliers[unit.toUpperCase()];}function parseSearchResults(html) {if (!html) {console.log('No HTML content to parse');return [];}const results = [];const dom = new JSDOM(html);dom.window.document.querySelectorAll('.search-result').forEach(item => {try {const titleElement = item.querySelector('h5.title a');const magnetElement = item.querySelector('a[href^="magnet:?xt=urn:btih:"]');const sizeElement = item.querySelector('.stats div:nth-child(2)');const seedersElement = item.querySelector('.stats div:nth-child(3) font');const leechersElement = item.querySelector('.stats div:nth-child(4) font');const tokenElement = magnetElement ? magnetElement.getAttribute('data-token') : null;if (!titleElement || !magnetElement) return;const title = titleElement.textContent.trim();const magnetLink = magnetElement.getAttribute('href');const hash = extractHash(magnetLink);const quality = extractQuality(title);const size = sizeElement ? sizeElement.textContent.trim() : 'Unknown';const seeders = seedersElement ? parseInt(seedersElement.textContent) : 0;const leechers = leechersElement ? parseInt(leechersElement.textContent) : 0;const token = tokenElement ? tokenElement.trim() : null;results.push({title,magnetLink,hash,1 unmodified linesize,seeders,leechers,token,mainFileSize: parseSize(size)});} catch (error) {console.error('Error parsing result:', error);}});return results;}async function searchTorrents(searchQuery) {if (!searchQuery) {console.log('No search query provided');return [];}console.log(`\n🔄 Searching SolidTorrents for: "${searchQuery}"`);try {const url = `${SITE_CONFIG.baseUrl}/search?q=${encodeURIComponent(searchQuery)}`;console.log('Request URL:', url);const response = await fetch(url, {headers: {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36','Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7','Referer': `${SITE_CONFIG.baseUrl}/search?q=${encodeURIComponent(searchQuery)}`}});if (!response.ok) {throw new Error(`Search request failed: ${response.status}`);}const html = await response.text();const results = parseSearchResults(html);console.log(`✅ Found ${results.length} raw results`);results.sort((a, b) => {const qualityOrder = { '2160p': 4, '4k': 4, '1080p': 3, '720p': 2 };const aQuality = qualityOrder[a.quality] || 0;const bQuality = qualityOrder[b.quality] || 0;if (aQuality !== bQuality) {return bQuality - aQuality;}return b.seeders - a.seeders;});return results;} catch (error) {console.error('❌ Error searching SolidTorrents:', error);return [];}}export { searchTorrents };
solid.js+83-76