Merge pull request #1 from Pal-droid/main

Added ID route
This commit is contained in:
Tahseen
2026-03-18 23:49:50 +05:30
committed by GitHub
2 changed files with 40 additions and 0 deletions

View File

@@ -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;

View File

@@ -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