Update torlock.js
Browse files- torlock.js +12 -27
torlock.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
| 1 |
import fetch from 'node-fetch';
|
| 2 |
import * as cheerio from 'cheerio';
|
| 3 |
-
import express from 'express';
|
| 4 |
-
|
| 5 |
-
const app = express();
|
| 6 |
-
const PORT = process.env.PORT || 3000;
|
| 7 |
|
| 8 |
// ==============================
|
| 9 |
// extractQuality: Identify Quality from Title
|
|
@@ -35,10 +31,10 @@ function parseSizeToBytes(size) {
|
|
| 35 |
async function extractMagnetLink(torrentPageUrl) {
|
| 36 |
try {
|
| 37 |
console.log(`π Fetching magnet link from: ${torrentPageUrl}`);
|
| 38 |
-
|
| 39 |
const response = await fetch(torrentPageUrl, {
|
| 40 |
headers: {
|
| 41 |
-
'User-Agent': 'Mozilla/5.0',
|
| 42 |
'Referer': 'https://www.torlock.com/',
|
| 43 |
'Accept': 'text/html',
|
| 44 |
}
|
|
@@ -51,6 +47,8 @@ async function extractMagnetLink(torrentPageUrl) {
|
|
| 51 |
|
| 52 |
const pageHtml = await response.text();
|
| 53 |
const $ = cheerio.load(pageHtml);
|
|
|
|
|
|
|
| 54 |
const magnetLink = $('a[href^="magnet:?xt=urn:btih:"]').attr('href');
|
| 55 |
return magnetLink || null;
|
| 56 |
} catch (error) {
|
|
@@ -60,18 +58,20 @@ async function extractMagnetLink(torrentPageUrl) {
|
|
| 60 |
}
|
| 61 |
|
| 62 |
// ==============================
|
| 63 |
-
// fetchRSSFeeds: Main Function
|
| 64 |
// ==============================
|
| 65 |
async function fetchRSSFeeds(searchQuery) {
|
| 66 |
console.log(`\nπ Fetching Torlock results for: ${searchQuery}`);
|
|
|
|
| 67 |
const encodedQuery = encodeURIComponent(searchQuery);
|
| 68 |
const searchUrl = `https://www.torlock.com/all/torrents/${encodedQuery}.html?sort=size&order=desc`;
|
|
|
|
| 69 |
console.log(`π‘ Fetching: ${searchUrl}`);
|
| 70 |
|
| 71 |
try {
|
| 72 |
const response = await fetch(searchUrl, {
|
| 73 |
headers: {
|
| 74 |
-
'User-Agent': 'Mozilla/5.0',
|
| 75 |
'Accept': 'text/html',
|
| 76 |
'Referer': 'https://www.torlock.com/',
|
| 77 |
}
|
|
@@ -101,6 +101,7 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 101 |
|
| 102 |
console.log(`β
Found ${torrents.length} torrents, fetching magnet links...`);
|
| 103 |
|
|
|
|
| 104 |
const completedTorrents = await Promise.all(
|
| 105 |
torrents.map(async (torrent) => {
|
| 106 |
const magnetLink = await extractMagnetLink(torrent.detailPageUrl);
|
|
@@ -118,8 +119,10 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 118 |
})
|
| 119 |
);
|
| 120 |
|
|
|
|
| 121 |
const validTorrents = completedTorrents.filter(Boolean);
|
| 122 |
|
|
|
|
| 123 |
validTorrents.sort((a, b) => {
|
| 124 |
const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
|
| 125 |
const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
|
|
@@ -134,25 +137,7 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 134 |
}
|
| 135 |
}
|
| 136 |
|
| 137 |
-
// ==============================
|
| 138 |
-
// Express API Endpoint
|
| 139 |
-
// ==============================
|
| 140 |
-
app.get('/search', async (req, res) => {
|
| 141 |
-
const query = req.query.q;
|
| 142 |
-
if (!query) return res.status(400).json({ error: 'Missing search query' });
|
| 143 |
-
|
| 144 |
-
const results = await fetchRSSFeeds(query);
|
| 145 |
-
res.json(results);
|
| 146 |
-
});
|
| 147 |
-
|
| 148 |
-
// ==============================
|
| 149 |
-
// Server Listener
|
| 150 |
-
// ==============================
|
| 151 |
-
app.listen(PORT, () => {
|
| 152 |
-
console.log(`π Server running on http://localhost:${PORT}`);
|
| 153 |
-
});
|
| 154 |
-
|
| 155 |
// ==============================
|
| 156 |
// Export for Server.js
|
| 157 |
// ==============================
|
| 158 |
-
export { fetchRSSFeeds };
|
|
|
|
| 1 |
import fetch from 'node-fetch';
|
| 2 |
import * as cheerio from 'cheerio';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
// ==============================
|
| 5 |
// extractQuality: Identify Quality from Title
|
|
|
|
| 31 |
async function extractMagnetLink(torrentPageUrl) {
|
| 32 |
try {
|
| 33 |
console.log(`π Fetching magnet link from: ${torrentPageUrl}`);
|
| 34 |
+
|
| 35 |
const response = await fetch(torrentPageUrl, {
|
| 36 |
headers: {
|
| 37 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/134.0.0.0 Safari/537.36',
|
| 38 |
'Referer': 'https://www.torlock.com/',
|
| 39 |
'Accept': 'text/html',
|
| 40 |
}
|
|
|
|
| 47 |
|
| 48 |
const pageHtml = await response.text();
|
| 49 |
const $ = cheerio.load(pageHtml);
|
| 50 |
+
|
| 51 |
+
// Extract magnet link
|
| 52 |
const magnetLink = $('a[href^="magnet:?xt=urn:btih:"]').attr('href');
|
| 53 |
return magnetLink || null;
|
| 54 |
} catch (error) {
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
// ==============================
|
| 61 |
+
// fetchRSSFeeds: Main Export Function
|
| 62 |
// ==============================
|
| 63 |
async function fetchRSSFeeds(searchQuery) {
|
| 64 |
console.log(`\nπ Fetching Torlock results for: ${searchQuery}`);
|
| 65 |
+
|
| 66 |
const encodedQuery = encodeURIComponent(searchQuery);
|
| 67 |
const searchUrl = `https://www.torlock.com/all/torrents/${encodedQuery}.html?sort=size&order=desc`;
|
| 68 |
+
|
| 69 |
console.log(`π‘ Fetching: ${searchUrl}`);
|
| 70 |
|
| 71 |
try {
|
| 72 |
const response = await fetch(searchUrl, {
|
| 73 |
headers: {
|
| 74 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/134.0.0.0 Safari/537.36',
|
| 75 |
'Accept': 'text/html',
|
| 76 |
'Referer': 'https://www.torlock.com/',
|
| 77 |
}
|
|
|
|
| 101 |
|
| 102 |
console.log(`β
Found ${torrents.length} torrents, fetching magnet links...`);
|
| 103 |
|
| 104 |
+
// Fetch magnet links from detail pages
|
| 105 |
const completedTorrents = await Promise.all(
|
| 106 |
torrents.map(async (torrent) => {
|
| 107 |
const magnetLink = await extractMagnetLink(torrent.detailPageUrl);
|
|
|
|
| 119 |
})
|
| 120 |
);
|
| 121 |
|
| 122 |
+
// Remove null values
|
| 123 |
const validTorrents = completedTorrents.filter(Boolean);
|
| 124 |
|
| 125 |
+
// Sorting: Highest Quality & Size First
|
| 126 |
validTorrents.sort((a, b) => {
|
| 127 |
const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
|
| 128 |
const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
|
|
|
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
// ==============================
|
| 141 |
// Export for Server.js
|
| 142 |
// ==============================
|
| 143 |
+
export { fetchRSSFeeds };
|