diff --git a/index.js b/index.js index cbfcb13..433e4d6 100644 --- a/index.js +++ b/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; diff --git a/lib/animepahe.js b/lib/animepahe.js index 142d71c..2704009 100644 --- a/lib/animepahe.js +++ b/lib/animepahe.js @@ -318,6 +318,31 @@ ${transformedScript} } } + /** + * Get external IDs (AniList, MyAnimeList) for an anime + * @param {string} animeSession - Anime session ID + * @returns {Promise} 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