-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (56 loc) · 2.13 KB
/
index.js
File metadata and controls
67 lines (56 loc) · 2.13 KB
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
// File: server.js
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const app = express();
// -------- Anime List Endpoint --------
app.get('/api/anime/list', async (req, res) => {
try {
const response = await axios.get('https://watchanimeworld.in/');
const $ = cheerio.load(response.data);
const animeList = [];
// Example selector - adjust based on actual site structure
$('div.main_series a').each((i, el) => {
const title = $(el).attr('title') || $(el).text().trim();
const link = $(el).attr('href');
const id = link.split('/').pop(); // get last part of URL as ID
const thumbnail = $(el).find('img').attr('src');
animeList.push({ id, title, thumbnail, link });
});
res.json(animeList);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch anime list' });
}
});
// -------- Episode Details Endpoint --------
app.get('/api/anime/:animeId/:episodeNum', async (req, res) => {
const { animeId, episodeNum } = req.params;
try {
const url = `https://watchanimeworld.in/series/${animeId}/episode-${episodeNum}`;
const response = await axios.get(url);
const $ = cheerio.load(response.data);
const title = $('h1.entry-title').text().trim() || `Episode ${episodeNum}`;
const embedServers = {};
// Example: select all iframe servers
$('iframe').each((i, el) => {
const serverName = $(el).attr('data-server') || `server${i+1}`;
const embedUrl = $(el).attr('src');
embedServers[serverName] = embedUrl;
});
res.json({
anime_id: animeId,
episode: episodeNum,
title,
embed_servers: embedServers
});
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch episode details' });
}
});
// -------- Start Server --------
const PORT = 3000;
app.listen(PORT, () => {
console.log(`API server running on http://localhost:${PORT}`);
});