Download kick.js from mikmc5/gemlog: direct link, hf CLI and curl.
- Browser
- Download file 4.53 kB
-
https://huggingface.co/spaces/mikmc5/gemlog/resolve/main/kick.js
- Command line
-
hf download hf://spaces/mikmc5/gemlog/kick.js
-
curl -L -o kick.js https://huggingface.co/spaces/mikmc5/gemlog/resolve/main/kick.js
4.53 kB
| import fetch from 'node-fetch'; | |
| // β Extracts video quality from title | |
| function extractQuality(title) { | |
| if (!title) return ''; | |
| const qualityMatch = title.match(/\b(2160p|1080p|720p|4k|uhd|WEBRip|BluRay|REMUX)\b/i); | |
| return qualityMatch ? qualityMatch[1].toLowerCase() : ''; | |
| } | |
| // β Formats size into human-readable format | |
| function formatSize(bytes) { | |
| const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; | |
| if (bytes === 0) return '0 B'; | |
| const i = Math.floor(Math.log(bytes) / Math.log(1024)); | |
| return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`; | |
| } | |
| // β Extracts magnet link from "Guid" | |
| function extractMagnetFromGuid(guid) { | |
| if (!guid) return null; | |
| const magnetMatch = guid.match(/magnet:\?xt=urn:btih:[A-Za-z0-9]+[^"'\s]*/); | |
| return magnetMatch ? magnetMatch[0] : null; | |
| } | |
| // β Removes the year from queries | |
| function cleanQuery(query) { | |
| return query.replace(/\(\d{4}\)/g, '').trim(); // Removes (YYYY) | |
| } | |
| // β Caches results to prevent duplicate requests | |
| const cache = new Map(); | |
| // β Fetch data from Jackett API (KickassTorrents) | |
| async function fetchRSSFeeds(searchQuery, type = 'movie') { | |
| const cleanedQuery = cleanQuery(searchQuery); | |
| console.log(`π Fetching RSS feed for: "${cleanedQuery}"`); | |
| if (cache.has(cleanedQuery)) { | |
| console.log(`β‘ Using cached results for: "${cleanedQuery}"`); | |
| return cache.get(cleanedQuery); | |
| } | |
| const API_URL = `http://167.86.78.215:9117/api/v2.0/indexers/all/results?apikey=a6q3edvwsd4pl9155lyu0lrwmngq4awu&Query=${encodeURIComponent(cleanedQuery)}&Tracker%5B%5D=kickasstorrents-ws&Category%5B%5D=2000&Category%5B%5D=5000&Category%5B%5D=8000&Category%5B%5D=103583&Category%5B%5D=112696&Category%5B%5D=13809&cache=false`; | |
| try { | |
| await new Promise(resolve => setTimeout(resolve, 2000)); // Prevents bot detection | |
| const response = await fetch(API_URL, { | |
| headers: { | |
| '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', | |
| 'Accept-Language': 'en-US,en;q=0.9', | |
| 'Connection': 'keep-alive', | |
| 'Cookie': 'Jackett=your_cookie_here' // β Use your Jackett cookie if required | |
| } | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`β Failed to fetch Jackett API: ${response.status}`); | |
| } | |
| const jsonResponse = await response.text(); | |
| const data = JSON.parse(jsonResponse); | |
| const results = data.Results || []; | |
| const streams = results.map((item) => { | |
| if (!item || !item.Title || !item.Guid) return null; | |
| // β Extract magnet link from "Guid" | |
| const magnetLink = extractMagnetFromGuid(item.Guid); | |
| if (!magnetLink) return null; | |
| // β Extract size | |
| const size = item.Size ? formatSize(item.Size) : 'Unknown'; | |
| // β Convert size to bytes for sorting | |
| let sizeInBytes = item.Size || 0; | |
| // β Extract IMDb ID if available | |
| const imdbId = item.Imdb ? `tt${item.Imdb}` : null; | |
| return { | |
| magnetLink, | |
| websiteTitle: item.Title, | |
| quality: extractQuality(item.Title), | |
| size, | |
| source: item.Tracker || 'Unknown', | |
| infoHash: item.InfoHash || null, | |
| seeders: item.Seeders || 0, | |
| peers: item.Peers || 0, | |
| imdbId, | |
| mainFileSize: sizeInBytes, | |
| pubDate: item.PublishDate, | |
| categories: Array.isArray(item.CategoryDesc) ? item.CategoryDesc : [item.CategoryDesc] | |
| }; | |
| }).filter(Boolean); | |
| // β Sort by quality and size | |
| streams.sort((a, b) => { | |
| const qualityOrder = { '2160p': 4, '4k': 4, 'uhd': 4, '1080p': 3, '720p': 2 }; | |
| const qualityDiff = (qualityOrder[b.quality] || 0) - (qualityOrder[a.quality] || 0); | |
| if (qualityDiff === 0) { | |
| return b.mainFileSize - a.mainFileSize; | |
| } | |
| return qualityDiff; | |
| }); | |
| console.log(`β Processed ${streams.length} valid streams`); | |
| // β Store result in cache | |
| cache.set(cleanedQuery, streams); | |
| return streams; | |
| } catch (error) { | |
| console.error('β Error fetching from Jackett:', error); | |
| return []; | |
| } | |
| } | |
| // β Export function for Stremio addon | |
| export { fetchRSSFeeds }; | |