Download server.js from ReikerXx/animedl: direct link, hf CLI and curl.
- Browser
- Download file 3.26 kB
-
https://huggingface.co/spaces/ReikerXx/animedl/resolve/main/server.js
- Command line
-
hf download hf://spaces/ReikerXx/animedl/server.js
-
curl -L -o server.js https://huggingface.co/spaces/ReikerXx/animedl/resolve/main/server.js
3.26 kB
| const express = require('express'); | |
| const axios = require('axios'); | |
| const crypto = require('crypto'); | |
| const cheerio = require('cheerio'); | |
| const app = express(); | |
| const PORT = 7860; | |
| // Enable CORS | |
| const cors = require('cors'); | |
| app.use(cors()); | |
| app.get('/anime/:title/:episode', async (req, res) => { | |
| const animeTitle = req.params.title; | |
| const episodeNumber = req.params.episode; | |
| console.log(`Requested: ${animeTitle} Episode ${episodeNumber}`); | |
| try { | |
| const episodeData = await searchGogoanime(animeTitle, episodeNumber); | |
| res.json(episodeData); | |
| } catch (error) { | |
| res.status(500).json({ error: "Failed to fetch episode data", details: error.message }); | |
| } | |
| }); | |
| async function searchGogoanime(animeTitle, episodeNumber) { | |
| try { | |
| console.log(`Searching for: ${animeTitle} Episode ${episodeNumber}`); | |
| // Search Gogoanime | |
| const searchUrl = `https://www31.gogoanimes.fi/search?keyword=${encodeURIComponent(animeTitle)}`; | |
| const searchResponse = await axios.get(searchUrl); | |
| const $ = cheerio.load(searchResponse.data); | |
| // Find first result | |
| const firstResult = $('.items li a').first(); | |
| const animeSlug = firstResult.attr('href')?.split('/')[2]; | |
| if (!animeSlug) throw new Error("Anime not found"); | |
| console.log(`Anime Found: ${animeTitle} (${animeSlug})`); | |
| // Episode page URL | |
| const episodeUrl = `https://www31.gogoanimes.fi/${animeSlug}-episode-${episodeNumber}`; | |
| console.log(`Episode URL: ${episodeUrl}`); | |
| return { | |
| anime: animeTitle, | |
| episode: episodeNumber, | |
| owner: "Reiker", | |
| episodeUrl: episodeUrl | |
| }; | |
| } catch (error) { | |
| throw new Error("Error searching Gogoanime: " + error.message); | |
| } | |
| } | |
| const urlMap = new Map(); // Stores random path -> original Filemoon URL | |
| app.get('/q', (req, res) => { | |
| const filemoonUrl = req.query.q; | |
| if (!filemoonUrl || !filemoonUrl.startsWith('https://filemoon.')) { | |
| return res.status(400).json({ error: 'Invalid or missing Filemoon URL.' }); | |
| } | |
| // Generate a random 16-character hex path | |
| const randomPath = crypto.randomBytes(8).toString('hex'); | |
| urlMap.set(randomPath, filemoonUrl); | |
| const fullUrl = `${req.protocol}://${req.get('host')}/vid/${randomPath}`; | |
| res.json({ url: fullUrl }); | |
| }); | |
| // Dynamic route to serve the embedded Filemoon player | |
| app.get('/vid/:id', (req, res) => { | |
| const filemoonUrl = urlMap.get(req.params.id); | |
| if (!filemoonUrl) { | |
| return res.status(404).send('Not found'); | |
| } | |
| // Convert /s/ URL to /e/ for embedding | |
| const embedUrl = filemoonUrl.replace('/s/', '/e/'); | |
| res.send(` | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Filemoon Embed</title> | |
| <style> | |
| body, html { | |
| margin: 0; | |
| padding: 0; | |
| height: 100%; | |
| background-color: #000; | |
| } | |
| iframe { | |
| width: 100%; | |
| height: 100%; | |
| border: none; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <iframe src="${embedUrl}" allowfullscreen></iframe> | |
| </body> | |
| </html> | |
| `); | |
| }); | |
| // Start API Server | |
| app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`)); |