File size: 3,261 Bytes
11fe9b3 68d8f3c 11fe9b3 5f5395c 11fe9b3 5f5395c 11fe9b3 af55b1e 11fe9b3 af55b1e 11fe9b3 c7e66a1 68d8f3c fc76d1e 68d8f3c fc76d1e 68d8f3c 11fe9b3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
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}`)); |