Update torlock.js
Browse files12345678925 unmodified lines353637383940414243446 unmodified lines5152535455563 unmodified lines60616263646566676869707172737475767723 unmodified lines10110210310410510611 unmodified lines1181191201211221231241258 unmodified lines134135136137138139140141142143144145146147148149150151152153154155156157158import fetch from 'node-fetch';import * as cheerio from 'cheerio';import express from 'express';const app = express();const PORT = process.env.PORT || 3000;// ==============================// extractQuality: Identify Quality from Title25 unmodified linesasync function extractMagnetLink(torrentPageUrl) {try {console.log(`π Fetching magnet link from: ${torrentPageUrl}`);const response = await fetch(torrentPageUrl, {headers: {'User-Agent': 'Mozilla/5.0','Referer': 'https://www.torlock.com/','Accept': 'text/html',}6 unmodified linesconst pageHtml = await response.text();const $ = cheerio.load(pageHtml);const magnetLink = $('a[href^="magnet:?xt=urn:btih:"]').attr('href');return magnetLink || null;} catch (error) {3 unmodified lines}// ==============================// fetchRSSFeeds: Main Function// ==============================async function fetchRSSFeeds(searchQuery) {console.log(`\nπ Fetching Torlock results for: ${searchQuery}`);const encodedQuery = encodeURIComponent(searchQuery);const searchUrl = `https://www.torlock.com/all/torrents/${encodedQuery}.html?sort=size&order=desc`;console.log(`π‘ Fetching: ${searchUrl}`);try {const response = await fetch(searchUrl, {headers: {'User-Agent': 'Mozilla/5.0','Accept': 'text/html','Referer': 'https://www.torlock.com/',}23 unmodified linesconsole.log(`β Found ${torrents.length} torrents, fetching magnet links...`);const completedTorrents = await Promise.all(torrents.map(async (torrent) => {const magnetLink = await extractMagnetLink(torrent.detailPageUrl);11 unmodified lines}));const validTorrents = completedTorrents.filter(Boolean);validTorrents.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);8 unmodified lines}}// ==============================// Express API Endpoint// ==============================app.get('/search', async (req, res) => {const query = req.query.q;if (!query) return res.status(400).json({ error: 'Missing search query' });const results = await fetchRSSFeeds(query);res.json(results);});// ==============================// Server Listener// ==============================app.listen(PORT, () => {console.log(`π Server running on http://localhost:${PORT}`);});// ==============================// Export for Server.js// ==============================export { fetchRSSFeeds };1234525 unmodified lines313233343536373839406 unmodified lines47484950515253543 unmodified lines585960616263646566676869707172737475767723 unmodified lines10110210310410510610711 unmodified lines1191201211221231241251261271288 unmodified lines137138139140141142143import fetch from 'node-fetch';import * as cheerio from 'cheerio';// ==============================// extractQuality: Identify Quality from Title25 unmodified linesasync function extractMagnetLink(torrentPageUrl) {try {console.log(`π Fetching magnet link from: ${torrentPageUrl}`);const response = await fetch(torrentPageUrl, {headers: {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/134.0.0.0 Safari/537.36','Referer': 'https://www.torlock.com/','Accept': 'text/html',}6 unmodified linesconst pageHtml = await response.text();const $ = cheerio.load(pageHtml);// Extract magnet linkconst magnetLink = $('a[href^="magnet:?xt=urn:btih:"]').attr('href');return magnetLink || null;} catch (error) {3 unmodified lines}// ==============================// fetchRSSFeeds: Main Export Function// ==============================async function fetchRSSFeeds(searchQuery) {console.log(`\nπ Fetching Torlock results for: ${searchQuery}`);const encodedQuery = encodeURIComponent(searchQuery);const searchUrl = `https://www.torlock.com/all/torrents/${encodedQuery}.html?sort=size&order=desc`;console.log(`π‘ Fetching: ${searchUrl}`);try {const response = await fetch(searchUrl, {headers: {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/134.0.0.0 Safari/537.36','Accept': 'text/html','Referer': 'https://www.torlock.com/',}23 unmodified linesconsole.log(`β Found ${torrents.length} torrents, fetching magnet links...`);// Fetch magnet links from detail pagesconst completedTorrents = await Promise.all(torrents.map(async (torrent) => {const magnetLink = await extractMagnetLink(torrent.detailPageUrl);11 unmodified lines}));// Remove null valuesconst validTorrents = completedTorrents.filter(Boolean);// Sorting: Highest Quality & Size FirstvalidTorrents.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);8 unmodified lines}}// ==============================// Export for Server.js// ==============================export { fetchRSSFeeds };
torlock.js+12-27