Update torr9.js
Browse files
torr9.js
CHANGED
|
@@ -102,15 +102,36 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 102 |
const hash = extractHash(detailUrl);
|
| 103 |
const magnetLink = hash ? createMagnetLink(hash) : null;
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
if (magnetLink) {
|
| 106 |
torrents.push({
|
| 107 |
-
|
| 108 |
-
|
| 109 |
quality,
|
| 110 |
size,
|
|
|
|
|
|
|
|
|
|
| 111 |
seeders,
|
| 112 |
leechers,
|
| 113 |
-
|
| 114 |
});
|
| 115 |
}
|
| 116 |
});
|
|
@@ -121,6 +142,11 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 121 |
const magnetLinks = await extractMagnetLinksFromPage(torrent.detailUrl);
|
| 122 |
if (magnetLinks.length > 0) {
|
| 123 |
torrent.magnetLink = magnetLinks[0]; // ✅ Assign first valid magnet link
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}));
|
|
@@ -128,6 +154,16 @@ async function fetchRSSFeeds(searchQuery) {
|
|
| 128 |
// ✅ Ensure only torrents with magnet links are returned
|
| 129 |
const validTorrents = torrents.filter(torrent => torrent.magnetLink);
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
console.log(`✅ Found ${validTorrents.length} torrents with magnet links.`);
|
| 132 |
return validTorrents;
|
| 133 |
|
|
|
|
| 102 |
const hash = extractHash(detailUrl);
|
| 103 |
const magnetLink = hash ? createMagnetLink(hash) : null;
|
| 104 |
|
| 105 |
+
// Convert size to bytes for sorting
|
| 106 |
+
let sizeInBytes = 0;
|
| 107 |
+
const sizeMatch = size.match(/([\d.]+)\s*(MB|GB|TB)/i);
|
| 108 |
+
if (sizeMatch) {
|
| 109 |
+
const [, value, unit] = sizeMatch;
|
| 110 |
+
const multiplier =
|
| 111 |
+
unit.toUpperCase() === 'TB'
|
| 112 |
+
? 1024 * 1024 * 1024 * 1024
|
| 113 |
+
: unit.toUpperCase() === 'GB'
|
| 114 |
+
? 1024 * 1024 * 1024
|
| 115 |
+
: 1024 * 1024;
|
| 116 |
+
sizeInBytes = parseFloat(value) * multiplier;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// Extract info hash from magnet link
|
| 120 |
+
const infoHashMatch = magnetLink ? magnetLink.match(/urn:btih:([A-Za-z0-9]+)/i) : null;
|
| 121 |
+
const infoHash = infoHashMatch ? infoHashMatch[1] : hash;
|
| 122 |
+
|
| 123 |
if (magnetLink) {
|
| 124 |
torrents.push({
|
| 125 |
+
magnetLink,
|
| 126 |
+
websiteTitle: title,
|
| 127 |
quality,
|
| 128 |
size,
|
| 129 |
+
source: 'Torrentz9',
|
| 130 |
+
infoHash,
|
| 131 |
+
mainFileSize: sizeInBytes,
|
| 132 |
seeders,
|
| 133 |
leechers,
|
| 134 |
+
detailUrl
|
| 135 |
});
|
| 136 |
}
|
| 137 |
});
|
|
|
|
| 142 |
const magnetLinks = await extractMagnetLinksFromPage(torrent.detailUrl);
|
| 143 |
if (magnetLinks.length > 0) {
|
| 144 |
torrent.magnetLink = magnetLinks[0]; // ✅ Assign first valid magnet link
|
| 145 |
+
// Update infoHash if we got a new magnet link
|
| 146 |
+
const infoHashMatch = torrent.magnetLink.match(/urn:btih:([A-Za-z0-9]+)/i);
|
| 147 |
+
if (infoHashMatch) {
|
| 148 |
+
torrent.infoHash = infoHashMatch[1];
|
| 149 |
+
}
|
| 150 |
}
|
| 151 |
}
|
| 152 |
}));
|
|
|
|
| 154 |
// ✅ Ensure only torrents with magnet links are returned
|
| 155 |
const validTorrents = torrents.filter(torrent => torrent.magnetLink);
|
| 156 |
|
| 157 |
+
// Sort torrents by quality and size (higher quality and larger size first)
|
| 158 |
+
validTorrents.sort((a, b) => {
|
| 159 |
+
const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
|
| 160 |
+
const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
|
| 161 |
+
if (qualityDiff === 0) {
|
| 162 |
+
return b.mainFileSize - a.mainFileSize;
|
| 163 |
+
}
|
| 164 |
+
return qualityDiff;
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
console.log(`✅ Found ${validTorrents.length} torrents with magnet links.`);
|
| 168 |
return validTorrents;
|
| 169 |
|