Update solid.js
Browse files
solid.js
CHANGED
|
@@ -6,6 +6,7 @@ const SITE_CONFIG = {
|
|
| 6 |
]
|
| 7 |
};
|
| 8 |
|
|
|
|
| 9 |
async function getCinemetaMetadata(imdbId) {
|
| 10 |
try {
|
| 11 |
if (!imdbId.startsWith('tt')) {
|
|
@@ -24,6 +25,7 @@ async function getCinemetaMetadata(imdbId) {
|
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
|
|
|
| 27 |
async function fetchWithTimeout(url, options = {}, timeout = 30000) {
|
| 28 |
const controller = new AbortController();
|
| 29 |
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
@@ -47,6 +49,7 @@ async function fetchWithTimeout(url, options = {}, timeout = 30000) {
|
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
|
|
|
| 50 |
function parseSize(sizeStr) {
|
| 51 |
if (!sizeStr) return 0;
|
| 52 |
const match = sizeStr.match(/([\d.]+)\s*(B|KB|MB|GB|TB)/i);
|
|
@@ -64,6 +67,7 @@ function parseSize(sizeStr) {
|
|
| 64 |
return parseFloat(value) * multipliers[unit.toUpperCase()];
|
| 65 |
}
|
| 66 |
|
|
|
|
| 67 |
function parseSearchResults(html) {
|
| 68 |
if (!html) {
|
| 69 |
console.log('No HTML content to parse');
|
|
@@ -109,22 +113,27 @@ function parseSearchResults(html) {
|
|
| 109 |
return results;
|
| 110 |
}
|
| 111 |
|
|
|
|
| 112 |
function extractQuality(title) {
|
| 113 |
if (!title) return '';
|
| 114 |
const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|hdr|dv|blu[- ]?ray)\b/i);
|
| 115 |
return qualityMatch ? qualityMatch[1].toLowerCase().replace(/[- ]/g, '') : '';
|
| 116 |
}
|
| 117 |
|
|
|
|
| 118 |
async function searchTorrents(searchQuery, type = 'movie') {
|
| 119 |
if (!searchQuery) {
|
| 120 |
console.log('No search query provided');
|
| 121 |
return [];
|
| 122 |
}
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
try {
|
| 127 |
-
const formattedQuery =
|
| 128 |
const url = `${SITE_CONFIG.baseUrl}/search?q=${encodeURIComponent(formattedQuery)}&sort=relevance&category=1&subcat=2&order=desc`;
|
| 129 |
|
| 130 |
console.log('Request URL:', url);
|
|
@@ -138,6 +147,7 @@ async function searchTorrents(searchQuery, type = 'movie') {
|
|
| 138 |
const results = parseSearchResults(html);
|
| 139 |
console.log(`✅ Found ${results.length} raw results`);
|
| 140 |
|
|
|
|
| 141 |
results.sort((a, b) => {
|
| 142 |
const qualityOrder = { '2160p': 5, '4k': 5, 'hdr': 4, 'dv': 4, '1080p': 3, '720p': 2 };
|
| 143 |
const aQuality = qualityOrder[a.quality] || 0;
|
|
@@ -155,5 +165,4 @@ async function searchTorrents(searchQuery, type = 'movie') {
|
|
| 155 |
return [];
|
| 156 |
}
|
| 157 |
}
|
| 158 |
-
|
| 159 |
export { searchTorrents };
|
|
|
|
| 6 |
]
|
| 7 |
};
|
| 8 |
|
| 9 |
+
// Helper function to fetch Cinemeta metadata (optional, for movie details)
|
| 10 |
async function getCinemetaMetadata(imdbId) {
|
| 11 |
try {
|
| 12 |
if (!imdbId.startsWith('tt')) {
|
|
|
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
+
// Timeout function to prevent hanging requests
|
| 29 |
async function fetchWithTimeout(url, options = {}, timeout = 30000) {
|
| 30 |
const controller = new AbortController();
|
| 31 |
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
|
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
+
// Parse the file size from a string (e.g., "1.2 GB")
|
| 53 |
function parseSize(sizeStr) {
|
| 54 |
if (!sizeStr) return 0;
|
| 55 |
const match = sizeStr.match(/([\d.]+)\s*(B|KB|MB|GB|TB)/i);
|
|
|
|
| 67 |
return parseFloat(value) * multipliers[unit.toUpperCase()];
|
| 68 |
}
|
| 69 |
|
| 70 |
+
// Parse search results from HTML
|
| 71 |
function parseSearchResults(html) {
|
| 72 |
if (!html) {
|
| 73 |
console.log('No HTML content to parse');
|
|
|
|
| 113 |
return results;
|
| 114 |
}
|
| 115 |
|
| 116 |
+
// Extract the video quality from the title (e.g., "1080p", "4k")
|
| 117 |
function extractQuality(title) {
|
| 118 |
if (!title) return '';
|
| 119 |
const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|hdr|dv|blu[- ]?ray)\b/i);
|
| 120 |
return qualityMatch ? qualityMatch[1].toLowerCase().replace(/[- ]/g, '') : '';
|
| 121 |
}
|
| 122 |
|
| 123 |
+
// Search for torrents while ignoring the year in the search query
|
| 124 |
async function searchTorrents(searchQuery, type = 'movie') {
|
| 125 |
if (!searchQuery) {
|
| 126 |
console.log('No search query provided');
|
| 127 |
return [];
|
| 128 |
}
|
| 129 |
|
| 130 |
+
// Step 1: Remove year-like patterns (e.g., "2021", "2022") from the search query
|
| 131 |
+
const queryWithoutYear = searchQuery.replace(/\s*(\d{4})\s*/g, '').trim();
|
| 132 |
+
|
| 133 |
+
console.log('\n🔄 Searching BitSearch for:', queryWithoutYear);
|
| 134 |
|
| 135 |
try {
|
| 136 |
+
const formattedQuery = queryWithoutYear.replace(/\s+/g, '+').toLowerCase();
|
| 137 |
const url = `${SITE_CONFIG.baseUrl}/search?q=${encodeURIComponent(formattedQuery)}&sort=relevance&category=1&subcat=2&order=desc`;
|
| 138 |
|
| 139 |
console.log('Request URL:', url);
|
|
|
|
| 147 |
const results = parseSearchResults(html);
|
| 148 |
console.log(`✅ Found ${results.length} raw results`);
|
| 149 |
|
| 150 |
+
// Sort results based on quality and seeders
|
| 151 |
results.sort((a, b) => {
|
| 152 |
const qualityOrder = { '2160p': 5, '4k': 5, 'hdr': 4, 'dv': 4, '1080p': 3, '720p': 2 };
|
| 153 |
const aQuality = qualityOrder[a.quality] || 0;
|
|
|
|
| 165 |
return [];
|
| 166 |
}
|
| 167 |
}
|
|
|
|
| 168 |
export { searchTorrents };
|