mikmc5 commited on
Commit
ef2ad72
ยท
verified ยท
1 Parent(s): 65289a3

Update solid.js

Browse files
Files changed (1) hide show
  1. solid.js +75 -110
solid.js CHANGED
@@ -1,76 +1,108 @@
1
  import fetch from 'node-fetch';
2
  import { JSDOM } from 'jsdom';
3
 
4
- const SITE_CONFIG = {
5
- baseUrl: 'https://solidtorrents.to',
6
- fallbackUrls: [
7
- 'https://solidtorrents.cc',
8
- 'https://solidtorrents.me'
9
- ]
10
- };
11
-
12
  function extractQuality(title) {
13
  if (!title) return '';
14
  const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd)\b/i);
15
  return qualityMatch ? qualityMatch[1].toLowerCase() : '';
16
  }
17
 
 
18
  function extractHash(magnetLink) {
19
  const hashMatch = magnetLink.match(/btih:([A-Fa-f0-9]{40})/);
20
  return hashMatch ? hashMatch[1] : '';
21
  }
22
 
 
23
  function createMagnetLink(hash) {
24
  return `magnet:?xt=urn:btih:${hash}`;
25
  }
26
 
27
- function parseSize(sizeStr) {
28
- if (!sizeStr) return 0;
29
- const match = sizeStr.match(/([\d.]+)\s*(B|KB|MB|GB|TB)/i);
30
- if (!match) return 0;
31
-
32
- const [, value, unit] = match;
33
- const multipliers = {
34
- 'B': 1,
35
- 'KB': 1024,
36
- 'MB': 1024 * 1024,
37
- 'GB': 1024 * 1024 * 1024,
38
- 'TB': 1024 * 1024 * 1024 * 1024
39
- };
40
-
41
- return parseFloat(value) * multipliers[unit.toUpperCase()];
42
  }
43
 
44
- function parseSearchResults(html) {
45
- if (!html) {
46
- console.log('No HTML content to parse');
47
- return [];
 
48
  }
49
 
50
- const results = [];
51
- const dom = new JSDOM(html);
52
-
53
- dom.window.document.querySelectorAll('.search-result').forEach(item => {
54
- try {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  const titleElement = item.querySelector('h5.title a');
56
  const magnetElement = item.querySelector('a[href^="magnet:?xt=urn:btih:"]');
57
  const sizeElement = item.querySelector('.stats div:nth-child(2)');
58
  const seedersElement = item.querySelector('.stats div:nth-child(3) font');
59
  const leechersElement = item.querySelector('.stats div:nth-child(4) font');
60
  const tokenElement = magnetElement ? magnetElement.getAttribute('data-token') : null;
61
-
62
  if (!titleElement || !magnetElement) return;
63
 
64
  const title = titleElement.textContent.trim();
65
  const magnetLink = magnetElement.getAttribute('href');
66
  const hash = extractHash(magnetLink);
67
  const quality = extractQuality(title);
68
- const size = sizeElement ? sizeElement.textContent.trim() : 'Unknown';
69
  const seeders = seedersElement ? parseInt(seedersElement.textContent) : 0;
70
  const leechers = leechersElement ? parseInt(leechersElement.textContent) : 0;
71
  const token = tokenElement ? tokenElement.trim() : null;
72
 
73
- results.push({
74
  title,
75
  magnetLink,
76
  hash,
@@ -78,89 +110,22 @@ function parseSearchResults(html) {
78
  size,
79
  seeders,
80
  leechers,
81
- token,
82
- mainFileSize: parseSize(size)
83
  });
84
- } catch (error) {
85
- console.error('Error parsing result:', error);
86
- }
87
- });
88
-
89
- return results;
90
- }
91
-
92
- async function fetchWithTimeout(url, options = {}, timeout = 30000) {
93
- const controller = new AbortController();
94
- const timeoutId = setTimeout(() => controller.abort(), timeout);
95
-
96
- try {
97
- const response = await fetch(url, {
98
- ...options,
99
- signal: controller.signal,
100
- headers: {
101
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
102
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9',
103
- 'Accept-Language': 'en-US,en;q=0.9',
104
- ...options.headers
105
- }
106
  });
107
- clearTimeout(timeoutId);
108
- return response;
109
- } catch (error) {
110
- clearTimeout(timeoutId);
111
- throw error;
112
- }
113
- }
114
 
115
- async function searchTorrents(searchQuery) {
116
- if (!searchQuery) {
117
- console.log('No search query provided');
118
- return [];
119
- }
120
 
121
- console.log(`\n๐Ÿ”„ Searching SolidTorrents for: "${searchQuery}"`);
122
-
123
- try {
124
- const formattedQuery = searchQuery.replace(/\s+/g, '+').toLowerCase();
125
- const url = `${SITE_CONFIG.baseUrl}/search?q=${encodeURIComponent(formattedQuery)}`;
126
- console.log('Request URL:', url);
127
-
128
- const response = await fetchWithTimeout(url);
129
- if (!response.ok) {
130
- throw new Error(`Search request failed: ${response.status}`);
131
  }
132
 
133
- const html = await response.text();
134
- const results = parseSearchResults(html);
135
- console.log(`โœ… Found ${results.length} raw results`);
136
-
137
- results.sort((a, b) => {
138
- const qualityOrder = { '2160p': 4, '4k': 4, '1080p': 3, '720p': 2 };
139
- const aQuality = qualityOrder[a.quality] || 0;
140
- const bQuality = qualityOrder[b.quality] || 0;
141
-
142
- if (aQuality !== bQuality) {
143
- return bQuality - aQuality;
144
- }
145
- return b.seeders - a.seeders;
146
- });
147
-
148
- return results;
149
  } catch (error) {
150
- console.error('โŒ Error searching SolidTorrents:', error);
151
-
152
- for (const fallbackUrl of SITE_CONFIG.fallbackUrls) {
153
- try {
154
- console.log(`Trying fallback URL: ${fallbackUrl}`);
155
- SITE_CONFIG.baseUrl = fallbackUrl;
156
- return await searchTorrents(searchQuery);
157
- } catch (fallbackError) {
158
- console.error(`Fallback ${fallbackUrl} also failed:`, fallbackError);
159
- }
160
- }
161
-
162
  return [];
163
  }
164
  }
165
 
166
- export { searchTorrents };
 
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 hash from magnet links
12
  function extractHash(magnetLink) {
13
  const hashMatch = magnetLink.match(/btih:([A-Fa-f0-9]{40})/);
14
  return hashMatch ? hashMatch[1] : '';
15
  }
16
 
17
+ // Function to generate a direct magnet link from a hash
18
  function createMagnetLink(hash) {
19
  return `magnet:?xt=urn:btih:${hash}`;
20
  }
21
 
22
+ // Function to format size from raw text
23
+ function formatSize(sizeText) {
24
+ return sizeText.replace('Size', '').trim();
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
26
 
27
+ // Function to test token validity
28
+ async function testTokenValidity(magnetLink, token) {
29
+ if (!token) {
30
+ console.log("โš ๏ธ No token provided, skipping token test.");
31
+ return;
32
  }
33
 
34
+ console.log(`๐Ÿ” Testing token for magnet link: ${magnetLink}`);
35
+
36
+ try {
37
+ const url = new URL(magnetLink);
38
+ url.searchParams.append('token', token);
39
+
40
+ const response = await fetch(url.toString(), {
41
+ headers: {
42
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
43
+ 'Referer': 'https://solidtorrents.to/',
44
+ 'Accept-Language': 'en-US,en;q=0.9',
45
+ 'Connection': 'keep-alive',
46
+ 'DNT': '1',
47
+ 'Upgrade-Insecure-Requests': '1'
48
+ }
49
+ });
50
+
51
+ if (response.ok) {
52
+ console.log("โœ… Token is valid! Magnet link works with the token.");
53
+ } else {
54
+ console.log("โŒ Token might not be necessary or is invalid.");
55
+ }
56
+ } catch (error) {
57
+ console.error("โŒ Error testing token validity:", error);
58
+ }
59
+ }
60
+
61
+ // Function to fetch and parse search results from SolidTorrents
62
+ async function fetchRSSFeeds(searchQuery) {
63
+ console.log(`๐Ÿ”„ Searching SolidTorrents for: "${searchQuery}"`);
64
+
65
+ try {
66
+ const url = `https://solidtorrents.to/search?q=${encodeURIComponent(searchQuery)}`;
67
+ const response = await fetch(url, {
68
+ headers: {
69
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
70
+ 'Referer': 'https://solidtorrents.to/',
71
+ 'Accept-Language': 'en-US,en;q=0.9',
72
+ 'Connection': 'keep-alive',
73
+ 'DNT': '1',
74
+ 'Upgrade-Insecure-Requests': '1'
75
+ }
76
+ });
77
+
78
+ if (!response.ok) {
79
+ throw new Error(`Failed to fetch search page: ${response.status}`);
80
+ }
81
+
82
+ const html = await response.text();
83
+ const dom = new JSDOM(html);
84
+ const torrents = [];
85
+
86
+ dom.window.document.querySelectorAll('.search-result').forEach(item => {
87
  const titleElement = item.querySelector('h5.title a');
88
  const magnetElement = item.querySelector('a[href^="magnet:?xt=urn:btih:"]');
89
  const sizeElement = item.querySelector('.stats div:nth-child(2)');
90
  const seedersElement = item.querySelector('.stats div:nth-child(3) font');
91
  const leechersElement = item.querySelector('.stats div:nth-child(4) font');
92
  const tokenElement = magnetElement ? magnetElement.getAttribute('data-token') : null;
93
+
94
  if (!titleElement || !magnetElement) return;
95
 
96
  const title = titleElement.textContent.trim();
97
  const magnetLink = magnetElement.getAttribute('href');
98
  const hash = extractHash(magnetLink);
99
  const quality = extractQuality(title);
100
+ const size = sizeElement ? formatSize(sizeElement.textContent) : 'Unknown';
101
  const seeders = seedersElement ? parseInt(seedersElement.textContent) : 0;
102
  const leechers = leechersElement ? parseInt(leechersElement.textContent) : 0;
103
  const token = tokenElement ? tokenElement.trim() : null;
104
 
105
+ torrents.push({
106
  title,
107
  magnetLink,
108
  hash,
 
110
  size,
111
  seeders,
112
  leechers,
113
+ token
 
114
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  });
 
 
 
 
 
 
 
116
 
117
+ console.log(`โœ… Found ${torrents.length} torrents with magnet links.`);
 
 
 
 
118
 
119
+ // Test token validity for the first result (if available)
120
+ if (torrents.length > 0) {
121
+ await testTokenValidity(torrents[0].magnetLink, torrents[0].token);
 
 
 
 
 
 
 
122
  }
123
 
124
+ return torrents;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  } catch (error) {
126
+ console.error('โŒ Error fetching from SolidTorrents:', error);
 
 
 
 
 
 
 
 
 
 
 
127
  return [];
128
  }
129
  }
130
 
131
+ export { fetchRSSFeeds };