diff --git a/lib/anime_parser.js b/lib/anime_parser.js index 6fcae51..d3948d5 100644 --- a/lib/anime_parser.js +++ b/lib/anime_parser.js @@ -83,7 +83,103 @@ const Genres = [ 'isekai', ]; +//added +const cachedDownloadLinks = {}; +export const scrapeFembed = async ({ id }) => { + try { + const epPage = await axios.get(BASE_URL2 + id); + const $ = cheerio.load(epPage.data); + + const server = $('.xstreamcdn > a:nth-child(1)').attr('data-video'); + const serverUrl = new URL(server); + + const sources = await extractFembed(serverUrl.href); + + if (!sources) return { error: 'No sources found!! Try different source.' }; + + return sources; + } catch (e) { + return { error: e.message }; + } +}; + +export const scrapeStreamSB = async ({ id }) => { + try { + const epPage = await axios.get(BASE_URL2 + id); + const $ = cheerio.load(epPage.data); + + const server = $( + 'div.anime_video_body > div.anime_muti_link > ul > li.streamsb > a' + ).attr('data-video'); + const serverUrl = new URL(server); + + const res = await extractStreamSB(serverUrl.href); + + if (!res.stream_data) return { error: 'No sources found!! Try different source.' }; + + return { + headers: { Referer: serverUrl.href, 'User-Agent': USER_AGENT }, + data: [{ file: res.stream_data.file }, { backup: res.stream_data.backup }], + }; + } catch (err) { + console.log(err); + return { error: err.message }; + } +}; + +export const scrapeM3U8 = async ({ id }) => { + let sources = []; + let sources_bk = []; + try { + let epPage, server, $, serverUrl; + + if (id) { + epPage = await axios.get(BASE_URL2 + id); + $ = cheerio.load(epPage.data); + + server = $('#load_anime > div > div > iframe').attr('src'); + serverUrl = new URL(server); + } else throw Error('Episode id not found'); + + const goGoServerPage = await axios.get(serverUrl.href, { + headers: { 'User-Agent': USER_AGENT }, + }); + const $$ = cheerio.load(goGoServerPage.data); + + const params = await generateEncryptAjaxParameters( + $$, + serverUrl.searchParams.get('id') + ); + + const fetchRes = await axios.get( + ` + ${serverUrl.protocol}//${serverUrl.hostname}/encrypt-ajax.php?${params}`, + { + headers: { + 'User-Agent': USER_AGENT, + 'X-Requested-With': 'XMLHttpRequest', + }, + } + ); + + const res = decryptEncryptAjaxResponse(fetchRes.data); + + if (!res.source) return { error: 'No sources found!! Try different source.' }; + + res.source.forEach((source) => sources.push(source)); + res.source_bk.forEach((source) => sources_bk.push(source)); + + return { + Referer: serverUrl.href, + sources: sources, + sources_bk: sources_bk, + }; + } catch (err) { + return { error: err }; + } +}; +//end export const scrapeSearch = async ({ list = [], keyw, page = 1 }) => { try { const searchPage = await axios.get( @@ -774,4 +870,4 @@ export const scrapeAnimeAZPage = async ({ aph, page = 1 }) => { console.log(err); return { error: err }; } -}; \ No newline at end of file +}; diff --git a/lib/api.js b/lib/api.js index fc510d3..af2aef8 100644 --- a/lib/api.js +++ b/lib/api.js @@ -30,6 +30,9 @@ import { scrapeSeason, scrapeCompletedAnime, scrapeWatchAnime, + scrapeM3U8, + scrapeStreamSB, + scrapeFembed, scrapeThread, DownloadReferer, } from './anime_parser.js'; @@ -512,9 +515,39 @@ app.get('/getEpisode/:id', async (req, res) => { } }); +//added +app.get('/vidcdn/watch/:id', async(req, res) => { + try { + const id = req.params.id; + const data = await scrapeM3U8({ id: id }); + res.status(200).json(data); + } catch (err) { + res.status(500).json({ + status: 500, + error: 'Internal Error', + message: err, + }); + } +}); +app.get('/streamsb/watch/:id', async(req, res) => { + try { + const id = req.params.id; + + const data = await scrapeStreamSB({ id: id }); + + res.status(200).json(data); + } catch (err) { + res.status(500).json({ + status: 500, + error: 'Internal Error', + message: err, + }); + } +}); +//end app.get('/thread/:episodeId', async (req, res) => { try { @@ -599,4 +632,4 @@ app.use((req, res) => { app.listen(port, () => { console.log('Express server listening on port %d in %s mode', port, app.settings.env); -}); \ No newline at end of file +});