mikmc5 commited on
Commit
a8d84df
·
verified ·
1 Parent(s): c629e03

Update btsow.js

Browse files
Files changed (1) hide show
  1. btsow.js +9 -10
btsow.js CHANGED
@@ -1,18 +1,17 @@
1
  import axios from 'axios';
2
  import * as cheerio from 'cheerio';
3
 
4
- // Helper functions
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 formatSize(sizeText) {
12
- if (!sizeText) return 'Unknown'; // Add a default in case sizeText is undefined or empty
13
- const sizeMatch = sizeText.match(/([\d.]+)\s*(MB|GB|TB)/i);
14
- if (!sizeMatch) return 'Unknown'; // Return a fallback if the regex does not match
15
- return `${sizeMatch[1]} ${sizeMatch[2]}`;
16
  }
17
 
18
  function extractYear(title) {
@@ -26,7 +25,7 @@ function isRelevantTitle(title, searchQuery) {
26
  return normalizedTitle.includes(normalizedQuery);
27
  }
28
 
29
- // Main function to process RSS feed and magnet links
30
  async function fetchRSSFeeds(searchQuery) {
31
  console.log('\n🔄 Fetching results for:', searchQuery);
32
  const url = `https://btsow.motorcycles/search/${encodeURIComponent(searchQuery)}`;
@@ -44,7 +43,7 @@ async function fetchRSSFeeds(searchQuery) {
44
  const magnetLink = `magnet:?xt=urn:btih:${hash}`;
45
  const title = $(element).find('.file').text().trim();
46
  const sizeText = $(element).siblings('.size-date').text().match(/Size:(.*?)\//i);
47
- const size = sizeText ? formatSize(sizeText[1].trim()) : 'Unknown'; // Handle case where sizeText might be undefined
48
  const year = extractYear(title);
49
  const quality = extractQuality(title);
50
 
@@ -85,7 +84,7 @@ async function fetchRSSFeeds(searchQuery) {
85
 
86
  // Sort by quality and size
87
  streams.sort((a, b) => {
88
- const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 };
89
  const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
90
  if (qualityDiff === 0) {
91
  return b.mainFileSize - a.mainFileSize;
 
1
  import axios from 'axios';
2
  import * as cheerio from 'cheerio';
3
 
4
+ // Helper function to handle the extraction of quality
5
  function extractQuality(title) {
6
  if (!title) return '';
7
+ const qualityMatch = title.match(/\b(1080p|720p|4k|2160p|WEBRip|x265|HDRip|HDTV)\b/i);
8
+ return qualityMatch ? qualityMatch[0].toLowerCase() : ''; // First match will be the quality
9
  }
10
 
11
  function formatSize(sizeText) {
12
+ if (!sizeText) return 'Unknown'; // Avoid `replace` if sizeText is undefined
13
+ const sizeMatch = sizeText.match(/Size:\s*([\d.]+)\s*(MB|GB|TB)/i);
14
+ return sizeMatch ? `${sizeMatch[1]} ${sizeMatch[2]}` : 'Unknown'; // Default to 'Unknown' if no match
 
15
  }
16
 
17
  function extractYear(title) {
 
25
  return normalizedTitle.includes(normalizedQuery);
26
  }
27
 
28
+ // Main function to fetch RSS feed and process magnet links
29
  async function fetchRSSFeeds(searchQuery) {
30
  console.log('\n🔄 Fetching results for:', searchQuery);
31
  const url = `https://btsow.motorcycles/search/${encodeURIComponent(searchQuery)}`;
 
43
  const magnetLink = `magnet:?xt=urn:btih:${hash}`;
44
  const title = $(element).find('.file').text().trim();
45
  const sizeText = $(element).siblings('.size-date').text().match(/Size:(.*?)\//i);
46
+ const size = sizeText ? formatSize(sizeText[1].trim()) : 'Unknown'; // Check if sizeText exists
47
  const year = extractYear(title);
48
  const quality = extractQuality(title);
49
 
 
84
 
85
  // Sort by quality and size
86
  streams.sort((a, b) => {
87
+ const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2, 'webRip': 1, 'x265': 1 };
88
  const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0);
89
  if (qualityDiff === 0) {
90
  return b.mainFileSize - a.mainFileSize;