Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Stream Url Function #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion lib/anime_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -774,4 +870,4 @@ export const scrapeAnimeAZPage = async ({ aph, page = 1 }) => {
console.log(err);
return { error: err };
}
};
};
35 changes: 34 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import {
scrapeSeason,
scrapeCompletedAnime,
scrapeWatchAnime,
scrapeM3U8,
scrapeStreamSB,
scrapeFembed,
scrapeThread,
DownloadReferer,
} from './anime_parser.js';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
});
});