mirror of
https://github.com/mdtahseen7/AnimepaheApi.git
synced 2026-04-17 16:11:44 +00:00
Add /ids route to scrape AniList and MyAnimeList IDs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
15
index.js
15
index.js
@@ -23,6 +23,7 @@ app.get('/', (req, res) => {
|
||||
search: '/search?q=naruto',
|
||||
episodes: '/episodes?session=anime-session-id',
|
||||
sources: '/sources?anime_session=xxx&episode_session=yyy',
|
||||
ids: '/ids?session=anime-session-id (returns AniList and MyAnimeList IDs)',
|
||||
m3u8: '/m3u8?url=kwik-url (returns m3u8 URL with required referer)',
|
||||
proxy: '/proxy?url=m3u8-or-ts-url&referer=kwik-referer (Use this to play videos)',
|
||||
health: '/health'
|
||||
@@ -84,6 +85,20 @@ app.get('/sources', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/ids', async (req, res) => {
|
||||
try {
|
||||
const { session } = req.query;
|
||||
if (!session) {
|
||||
return res.status(400).json({ error: 'Query parameter "session" is required' });
|
||||
}
|
||||
const ids = await pahe.getIds(session);
|
||||
res.json(ids);
|
||||
} catch (error) {
|
||||
console.error('IDs error:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/m3u8', async (req, res) => {
|
||||
try {
|
||||
const { url } = req.query;
|
||||
|
||||
@@ -318,6 +318,31 @@ ${transformedScript}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get external IDs (AniList, MyAnimeList) for an anime
|
||||
* @param {string} animeSession - Anime session ID
|
||||
* @returns {Promise<Object>} Object with anilist and myanimelist IDs
|
||||
*/
|
||||
async getIds(animeSession) {
|
||||
try {
|
||||
const animePageUrl = `${this.base}/anime/${animeSession}`;
|
||||
const html = await cloudscraper.get(animePageUrl, {
|
||||
headers: this.getHeaders()
|
||||
});
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const anilistId = $('meta[name="anilist"]').attr('content') || null;
|
||||
const malId = $('meta[name="myanimelist"]').attr('content') || null;
|
||||
|
||||
return {
|
||||
anilist: anilistId ? parseInt(anilistId, 10) : null,
|
||||
myanimelist: malId ? parseInt(malId, 10) : null
|
||||
};
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to get IDs: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a Node.js script and capture output
|
||||
* @param {string} scriptPath - Path to script file
|
||||
|
||||
Reference in New Issue
Block a user