Download src/fetchFromModules.js from mikmc5/magnetai2: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/mikmc5/magnetai2/resolve/main/src/fetchFromModules.js
- Command line
-
hf download hf://spaces/mikmc5/magnetai2/src/fetchFromModules.js
-
curl -L -o fetchFromModules.js https://huggingface.co/spaces/mikmc5/magnetai2/resolve/main/src/fetchFromModules.js
1.26 kB
| // src/fetchFromModules.js | |
| import { STREAM_SOURCES } from './const.js'; | |
| export async function fetchFromModules({ type, query }) { | |
| const results = []; | |
| const seenHashes = new Set(); | |
| await Promise.all(Object.entries(STREAM_SOURCES).map(async ([key, source]) => { | |
| try { | |
| const url = `${source.url}/api/search?type=${type}&query=${encodeURIComponent(query)}`; | |
| const response = await fetch(url); | |
| if (!response.ok) { | |
| console.warn(`⚠️ ${source.name} failed: ${response.status}`); | |
| return; | |
| } | |
| const json = await response.json(); | |
| const streams = json.results || []; | |
| for (const item of streams) { | |
| const hash = item.magnetLink?.match(/btih:([a-f0-9]+)/i)?.[1]?.toLowerCase(); | |
| if (!hash || seenHashes.has(hash)) continue; | |
| seenHashes.add(hash); | |
| results.push({ | |
| hash, | |
| filename: item.filename || item.title || 'Unknown', | |
| quality: item.quality || '', | |
| size: item.size || '', | |
| source: source.name, | |
| magnetLink: item.magnetLink | |
| }); | |
| } | |
| } catch (err) { | |
| console.warn(`❌ Error fetching from ${source.name}:`, err.message); | |
| } | |
| })); | |
| return results; | |
| } | |