mikmc5 commited on
Commit
9cc293f
·
verified ·
1 Parent(s): 9c18ebd

Update btsow.js

Browse files
Files changed (1) hide show
  1. btsow.js +12 -8
btsow.js CHANGED
@@ -55,7 +55,8 @@ async function fetchRSSFeeds(searchQuery) {
55
  let results = [];
56
 
57
  // Parsing magnet links and associated data
58
- $('a[href*="/magnet/detail/hash/"]').each(async (_, element) => {
 
59
  const href = $(element).attr('href');
60
  const hashMatch = href.match(/hash\/([A-F0-9]{40})/i);
61
  if (hashMatch) {
@@ -68,7 +69,7 @@ async function fetchRSSFeeds(searchQuery) {
68
  const quality = extractQuality(title);
69
 
70
  if (isRelevantTitle(title, searchQuery)) {
71
- results.push({
72
  magnetLink,
73
  title,
74
  quality,
@@ -80,16 +81,19 @@ async function fetchRSSFeeds(searchQuery) {
80
  }
81
  });
82
 
83
- // Fetching metadata for each result
84
- for (let i = 0; i < results.length; i++) {
85
- const meta = await fetchMeta(results[i].magnetLink);
86
  if (meta) {
87
- results[i] = { ...results[i], ...meta };
88
  }
89
- }
 
 
 
90
 
91
  // Sorting results by quality and size
92
- const streams = results.map(item => {
93
  if (!item || !item.title || !item.size) return null;
94
 
95
  // Convert size to bytes for sorting
 
55
  let results = [];
56
 
57
  // Parsing magnet links and associated data
58
+ const magnetLinks = [];
59
+ $('a[href*="/magnet/detail/hash/"]').each((_, element) => {
60
  const href = $(element).attr('href');
61
  const hashMatch = href.match(/hash\/([A-F0-9]{40})/i);
62
  if (hashMatch) {
 
69
  const quality = extractQuality(title);
70
 
71
  if (isRelevantTitle(title, searchQuery)) {
72
+ magnetLinks.push({
73
  magnetLink,
74
  title,
75
  quality,
 
81
  }
82
  });
83
 
84
+ // Fetching metadata for each result in parallel
85
+ const fetchMetadataPromises = magnetLinks.map(async (link) => {
86
+ const meta = await fetchMeta(link.magnetLink);
87
  if (meta) {
88
+ return { ...link, ...meta };
89
  }
90
+ return link;
91
+ });
92
+
93
+ const resultsWithMeta = await Promise.all(fetchMetadataPromises);
94
 
95
  // Sorting results by quality and size
96
+ const streams = resultsWithMeta.map(item => {
97
  if (!item || !item.title || !item.size) return null;
98
 
99
  // Convert size to bytes for sorting