mikmc5 commited on
Commit
db5f8ee
Β·
verified Β·
1 Parent(s): b5fb971

Update anime.js

Browse files
Files changed (1) hide show
  1. anime.js +23 -15
anime.js CHANGED
@@ -46,22 +46,28 @@ async function fetchRSSFeeds(searchQuery) {
46
  const dom = new JSDOM(html);
47
  const torrents = [];
48
 
 
49
  dom.window.document.querySelectorAll('.data-list .row').forEach(row => {
50
- const magnetLinkElement = row.querySelector('a[href^="//btsow.motorcycles/magnet/detail/hash/"]');
 
51
  const titleElement = row.querySelector('.file');
52
  const metaElement = row.querySelector('.size-date');
53
 
54
- if (!magnetLinkElement || !titleElement || !metaElement) return;
55
 
56
- const detailUrl = 'https:' + magnetLinkElement.getAttribute('href');
57
  const title = titleElement.textContent.trim();
 
58
  const quality = extractQuality(title);
59
 
60
- // βœ… Extract hash and generate magnet link
61
- const hash = extractHash(detailUrl);
62
- const directMagnet = hash ? createMagnetLink(hash) : '';
63
 
64
- // βœ… Extract size information
 
 
 
 
 
 
65
  const metaText = metaElement.textContent.trim();
66
  const sizeMatch = metaText.match(/Size:([^/]+)/);
67
  const size = sizeMatch ? sizeMatch[1].trim() : 'Unknown';
@@ -69,25 +75,27 @@ async function fetchRSSFeeds(searchQuery) {
69
  torrents.push({
70
  title,
71
  detailUrl,
72
- hash,
73
- size,
74
  quality,
75
- magnetLink: directMagnet // βœ… Ensure magnetLink is always included
 
76
  });
77
  });
78
 
79
- // βœ… If no magnet links are found, try fetching from detail pages
80
  await Promise.all(torrents.map(async (torrent) => {
81
- if (!torrent.magnetLink) {
82
  const magnetLinks = await extractMagnetLinksFromPage(torrent.detailUrl);
83
  if (magnetLinks.length > 0) {
84
- torrent.magnetLink = magnetLinks[0]; // βœ… Use the first valid magnet link
85
  }
86
  }
87
  }));
88
 
89
- console.log(`βœ… Found ${torrents.length} torrents.`);
90
- return torrents.filter(torrent => torrent.magnetLink); // βœ… Ensure only torrents with magnet links are returned
 
 
 
91
 
92
  } catch (error) {
93
  console.error('❌ Error fetching from BTSOW:', error);
 
46
  const dom = new JSDOM(html);
47
  const torrents = [];
48
 
49
+ // βœ… Extract magnet links from the search page first
50
  dom.window.document.querySelectorAll('.data-list .row').forEach(row => {
51
+ const magnetElement = row.querySelector('a[href^="magnet:?xt=urn:btih:"]');
52
+ const detailElement = row.querySelector('a[href^="//btsow.motorcycles/magnet/detail/hash/"]');
53
  const titleElement = row.querySelector('.file');
54
  const metaElement = row.querySelector('.size-date');
55
 
56
+ if (!titleElement || !metaElement || (!magnetElement && !detailElement)) return;
57
 
 
58
  const title = titleElement.textContent.trim();
59
+ const detailUrl = detailElement ? 'https:' + detailElement.getAttribute('href') : null;
60
  const quality = extractQuality(title);
61
 
62
+ let magnetLink = magnetElement ? magnetElement.getAttribute('href') : null;
 
 
63
 
64
+ // βœ… Extract hash to generate magnet link if not found in the search page
65
+ if (!magnetLink && detailUrl) {
66
+ const hash = extractHash(detailUrl);
67
+ if (hash) magnetLink = createMagnetLink(hash);
68
+ }
69
+
70
+ // βœ… Extract meta info (size)
71
  const metaText = metaElement.textContent.trim();
72
  const sizeMatch = metaText.match(/Size:([^/]+)/);
73
  const size = sizeMatch ? sizeMatch[1].trim() : 'Unknown';
 
75
  torrents.push({
76
  title,
77
  detailUrl,
 
 
78
  quality,
79
+ size,
80
+ magnetLink
81
  });
82
  });
83
 
84
+ // βœ… If magnet links are still missing, fetch from detail pages
85
  await Promise.all(torrents.map(async (torrent) => {
86
+ if (!torrent.magnetLink && torrent.detailUrl) {
87
  const magnetLinks = await extractMagnetLinksFromPage(torrent.detailUrl);
88
  if (magnetLinks.length > 0) {
89
+ torrent.magnetLink = magnetLinks[0]; // βœ… Assign first valid magnet link
90
  }
91
  }
92
  }));
93
 
94
+ // βœ… Ensure only torrents with magnet links are returned
95
+ const validTorrents = torrents.filter(torrent => torrent.magnetLink);
96
+
97
+ console.log(`βœ… Found ${validTorrents.length} torrents with magnet links.`);
98
+ return validTorrents;
99
 
100
  } catch (error) {
101
  console.error('❌ Error fetching from BTSOW:', error);