Update btsow.js
Browse files
btsow.js
CHANGED
|
@@ -1,163 +1,95 @@
|
|
| 1 |
import fetch from 'node-fetch';
|
| 2 |
import { JSDOM } from 'jsdom';
|
| 3 |
-
import xml2js from 'xml2js';
|
| 4 |
|
| 5 |
-
|
| 6 |
-
explicitArray: false,
|
| 7 |
-
ignoreAttrs: true
|
| 8 |
-
});
|
| 9 |
-
|
| 10 |
-
// Helper Functions
|
| 11 |
function extractQuality(title) {
|
| 12 |
if (!title) return '';
|
| 13 |
const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd)\b/i);
|
| 14 |
return qualityMatch ? qualityMatch[1].toLowerCase() : '';
|
| 15 |
}
|
| 16 |
|
|
|
|
| 17 |
function extractMagnetFromDescription(description) {
|
| 18 |
if (!description) return null;
|
| 19 |
-
const magnetMatch = description.match(/magnet:\?xt=urn:btih:[A-Za-z0-9]+[^"'\s]*/);
|
| 20 |
-
return magnetMatch ? magnetMatch[
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
function generateMagnetLinkFromHash(hash) {
|
| 24 |
-
if (!hash) return null;
|
| 25 |
-
return `magnet:?xt=urn:btih:${hash}`;
|
| 26 |
}
|
| 27 |
|
|
|
|
| 28 |
async function extractMagnetLinksFromPage(url) {
|
| 29 |
try {
|
| 30 |
const response = await fetch(url);
|
|
|
|
|
|
|
|
|
|
| 31 |
const html = await response.text();
|
| 32 |
|
| 33 |
const dom = new JSDOM(html);
|
| 34 |
const magnetLinks = dom.window.document.querySelectorAll('a[href^="magnet:?xt=urn:btih:"]');
|
| 35 |
-
const linksArray = Array.from(magnetLinks).map(link => link.href);
|
| 36 |
|
|
|
|
| 37 |
return linksArray.length > 0 ? linksArray : null;
|
| 38 |
} catch (error) {
|
| 39 |
-
console.error('❌ Error fetching
|
| 40 |
return null;
|
| 41 |
}
|
| 42 |
}
|
| 43 |
|
| 44 |
-
//
|
| 45 |
-
async function fetchRSSFeeds(searchQuery
|
| 46 |
-
console.log(`
|
| 47 |
|
| 48 |
try {
|
| 49 |
-
const
|
| 50 |
-
const
|
| 51 |
-
|
| 52 |
-
console.log('📡 Requesting RSS feed:', rssUrl);
|
| 53 |
-
|
| 54 |
-
const response = await fetch(rssUrl, {
|
| 55 |
-
headers: {
|
| 56 |
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
| 57 |
-
'Accept': 'application/rss+xml,application/xml,text/xml'
|
| 58 |
-
}
|
| 59 |
-
});
|
| 60 |
-
|
| 61 |
if (!response.ok) {
|
| 62 |
-
throw new Error(`Failed to fetch
|
| 63 |
}
|
|
|
|
| 64 |
|
| 65 |
-
const
|
| 66 |
-
const
|
| 67 |
-
|
| 68 |
-
if (!result?.rss?.channel?.item) {
|
| 69 |
-
console.log('⚠️ No items found in RSS feed.');
|
| 70 |
-
return [];
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
const items = Array.isArray(result.rss.channel.item) ? result.rss.channel.item : [result.rss.channel.item];
|
| 74 |
-
|
| 75 |
-
console.log(`✅ Found ${items.length} items in RSS feed.`);
|
| 76 |
-
|
| 77 |
-
// Process all items
|
| 78 |
-
const streams = await Promise.all(items.map(async (item) => {
|
| 79 |
-
if (!item || !item.title || !item.description) return null;
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
if (
|
| 84 |
-
console.log(`🔗 Magnet link found in description: ${magnetLink}`);
|
| 85 |
-
} else if (item.link) {
|
| 86 |
-
console.log(`🔄 No magnet in description. Extracting from page: ${item.link}`);
|
| 87 |
-
const extractedLinks = await extractMagnetLinksFromPage(item.link);
|
| 88 |
-
if (extractedLinks) {
|
| 89 |
-
magnetLink = extractedLinks[0];
|
| 90 |
-
console.log(`✅ Extracted magnet from page: ${magnetLink}`);
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
magnetLink = generateMagnetLinkFromHash(hash);
|
| 100 |
-
console.log(`🔑 Generated magnet from hash: ${magnetLink}`);
|
| 101 |
-
}
|
| 102 |
-
}
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
1024 * 1024;
|
| 118 |
-
sizeInBytes = parseFloat(value) * multiplier;
|
| 119 |
}
|
| 120 |
-
|
| 121 |
-
const categories = Array.isArray(item.category) ? item.category : [item.category];
|
| 122 |
-
|
| 123 |
-
return {
|
| 124 |
-
magnetLink,
|
| 125 |
-
websiteTitle: item.title,
|
| 126 |
-
quality: extractQuality(item.title),
|
| 127 |
-
size,
|
| 128 |
-
source: item.author || 'Unknown',
|
| 129 |
-
infoHash: hash || null,
|
| 130 |
-
mainFileSize: sizeInBytes,
|
| 131 |
-
pubDate: item.pubDate,
|
| 132 |
-
categories
|
| 133 |
-
};
|
| 134 |
}));
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
validStreams.sort((a, b) => {
|
| 139 |
-
const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
|
| 140 |
-
const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
|
| 141 |
-
return qualityDiff === 0 ? b.mainFileSize - a.mainFileSize : qualityDiff;
|
| 142 |
-
});
|
| 143 |
-
|
| 144 |
-
console.log(`🎉 Successfully processed ${validStreams.length} valid streams.`);
|
| 145 |
-
return validStreams;
|
| 146 |
|
| 147 |
} catch (error) {
|
| 148 |
-
console.error('❌ Error
|
| 149 |
return [];
|
| 150 |
}
|
| 151 |
}
|
| 152 |
|
| 153 |
-
//
|
| 154 |
-
(async () => {
|
| 155 |
-
try {
|
| 156 |
-
const results = await fetchRSSFeeds('Steins;Gate 0 S01E01');
|
| 157 |
-
console.log(results);
|
| 158 |
-
} catch (error) {
|
| 159 |
-
console.error('❌ Error executing fetchRSSFeeds:', error);
|
| 160 |
-
}
|
| 161 |
-
})();
|
| 162 |
-
|
| 163 |
export { fetchRSSFeeds };
|
|
|
|
| 1 |
import fetch from 'node-fetch';
|
| 2 |
import { JSDOM } from 'jsdom';
|
|
|
|
| 3 |
|
| 4 |
+
// Function to extract video quality from the title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
function extractQuality(title) {
|
| 6 |
if (!title) return '';
|
| 7 |
const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd)\b/i);
|
| 8 |
return qualityMatch ? qualityMatch[1].toLowerCase() : '';
|
| 9 |
}
|
| 10 |
|
| 11 |
+
// Function to extract magnet link from HTML description
|
| 12 |
function extractMagnetFromDescription(description) {
|
| 13 |
if (!description) return null;
|
| 14 |
+
const magnetMatch = description.match(/href="(magnet:\?xt=urn:btih:[A-Za-z0-9]+[^"'\s]*)"/);
|
| 15 |
+
return magnetMatch ? magnetMatch[1] : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
+
// Function to fetch and extract magnet links from a BTSOW page
|
| 19 |
async function extractMagnetLinksFromPage(url) {
|
| 20 |
try {
|
| 21 |
const response = await fetch(url);
|
| 22 |
+
if (!response.ok) {
|
| 23 |
+
throw new Error(`Failed to fetch page: ${response.status}`);
|
| 24 |
+
}
|
| 25 |
const html = await response.text();
|
| 26 |
|
| 27 |
const dom = new JSDOM(html);
|
| 28 |
const magnetLinks = dom.window.document.querySelectorAll('a[href^="magnet:?xt=urn:btih:"]');
|
|
|
|
| 29 |
|
| 30 |
+
const linksArray = Array.from(magnetLinks).map(link => link.href);
|
| 31 |
return linksArray.length > 0 ? linksArray : null;
|
| 32 |
} catch (error) {
|
| 33 |
+
console.error('❌ Error fetching magnet links:', error);
|
| 34 |
return null;
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
+
// Function to fetch and parse BTSOW search results
|
| 39 |
+
async function fetchRSSFeeds(searchQuery) {
|
| 40 |
+
console.log(`🔄 Searching BTSOW for: "${searchQuery}"`);
|
| 41 |
|
| 42 |
try {
|
| 43 |
+
const url = `https://btsow.motorcycles/search/${encodeURIComponent(searchQuery)}`;
|
| 44 |
+
const response = await fetch(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
if (!response.ok) {
|
| 46 |
+
throw new Error(`Failed to fetch BTSOW search page: ${response.status}`);
|
| 47 |
}
|
| 48 |
+
const html = await response.text();
|
| 49 |
|
| 50 |
+
const dom = new JSDOM(html);
|
| 51 |
+
const torrents = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
dom.window.document.querySelectorAll('.data-list .row').forEach(row => {
|
| 54 |
+
const magnetLinkElement = row.querySelector('a[href^="//btsow.motorcycles/magnet/detail/hash/"]');
|
| 55 |
+
const titleElement = row.querySelector('.file');
|
| 56 |
+
const sizeElement = row.querySelector('.size');
|
| 57 |
+
const dateElement = row.querySelector('.date');
|
| 58 |
|
| 59 |
+
if (!magnetLinkElement || !titleElement || !sizeElement || !dateElement) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
const detailUrl = 'https:' + magnetLinkElement.getAttribute('href');
|
| 62 |
+
const title = titleElement.textContent.trim();
|
| 63 |
+
const size = sizeElement.textContent.trim();
|
| 64 |
+
const date = dateElement.textContent.trim();
|
| 65 |
+
const quality = extractQuality(title);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
torrents.push({
|
| 68 |
+
title,
|
| 69 |
+
detailUrl,
|
| 70 |
+
size,
|
| 71 |
+
date,
|
| 72 |
+
quality,
|
| 73 |
+
magnetLinks: [],
|
| 74 |
+
});
|
| 75 |
+
});
|
| 76 |
|
| 77 |
+
// Fetch magnet links for each torrent entry
|
| 78 |
+
await Promise.all(torrents.map(async (torrent) => {
|
| 79 |
+
const magnetLinks = await extractMagnetLinksFromPage(torrent.detailUrl);
|
| 80 |
+
if (magnetLinks) {
|
| 81 |
+
torrent.magnetLinks = magnetLinks;
|
|
|
|
|
|
|
| 82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}));
|
| 84 |
|
| 85 |
+
console.log(`✅ Found ${torrents.length} torrents.`);
|
| 86 |
+
return torrents.filter(torrent => torrent.magnetLinks.length > 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
} catch (error) {
|
| 89 |
+
console.error('❌ Error fetching from BTSOW:', error);
|
| 90 |
return [];
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
| 94 |
+
// Export fetchRSSFeeds as the single function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
export { fetchRSSFeeds };
|