Update animelib/animelib.js
This commit is contained in:
+8
-57
@@ -1,7 +1,7 @@
|
||||
async function searchResults(keyword) {
|
||||
const results = [];
|
||||
try {
|
||||
const response = await fetchv2("https://api.cdnlibs.org/api/anime?fields[]=rate_avg&fields[]=rate&fields[]=releaseDate&q=" + keyword);
|
||||
const response = await fetchv2("https://hapi.hentaicdn.org/api/anime?fields[]=rate_avg&fields[]=rate&fields[]=releaseDate&q=" + keyword);
|
||||
const json = await response.json();
|
||||
|
||||
if (json && Array.isArray(json.data)) {
|
||||
@@ -18,7 +18,7 @@ async function searchResults(keyword) {
|
||||
return JSON.stringify(results);
|
||||
} catch (err) {
|
||||
return JSON.stringify([{
|
||||
title: "Error",
|
||||
title: err.message,
|
||||
image: "Error",
|
||||
href: "Error"
|
||||
}]);
|
||||
@@ -28,7 +28,7 @@ async function searchResults(keyword) {
|
||||
async function extractDetails(slug) {
|
||||
try {
|
||||
const response = await fetchv2(
|
||||
"https://api.cdnlibs.org/api/anime/" + slug +
|
||||
"https://hapi.hentaicdn.org/api/anime/" + slug +
|
||||
"?fields[]=background&fields[]=eng_name&fields[]=otherNames&fields[]=summary&fields[]=releaseDate&fields[]=type_id&fields[]=caution&fields[]=views&fields[]=close_view&fields[]=rate_avg&fields[]=rate&fields[]=genres&fields[]=tags&fields[]=teams&fields[]=user&fields[]=franchise&fields[]=authors&fields[]=publisher&fields[]=userRating&fields[]=moderated&fields[]=metadata&fields[]=metadata.count&fields[]=metadata.close_comments&fields[]=anime_status_id&fields[]=time&fields[]=episodes&fields[]=episodes_count&fields[]=episodesSchedule&fields[]=shiki_rate"
|
||||
);
|
||||
const json = await response.json();
|
||||
@@ -51,7 +51,7 @@ async function extractDetails(slug) {
|
||||
async function extractEpisodes(slug) {
|
||||
const results = [];
|
||||
try {
|
||||
const response = await fetchv2("https://api.cdnlibs.org/api/episodes?anime_id=" + slug);
|
||||
const response = await fetchv2("https://hapi.hentaicdn.org/api/episodes?anime_id=" + slug);
|
||||
const json = await response.json();
|
||||
|
||||
if (json && Array.isArray(json.data)) {
|
||||
@@ -74,54 +74,11 @@ async function extractEpisodes(slug) {
|
||||
|
||||
async function extractStreamUrl(ID) {
|
||||
try {
|
||||
const response = await fetchv2("https://api.cdnlibs.org/api/episodes/" + ID);
|
||||
const response = await fetchv2("https://hapi.hentaicdn.org/api/episodes/" + ID);
|
||||
const json = await response.json();
|
||||
|
||||
const data = json.data || {};
|
||||
const players = data.players || [];
|
||||
|
||||
// const parserPromises = players
|
||||
// .filter(player => player.src && player.team && player.team.name)
|
||||
// .map(async (player) => {
|
||||
// try {
|
||||
// const kodikUrl = "https:" + player.src;
|
||||
// const qualitiesJson = await kodikParser(kodikUrl);
|
||||
// const qualities = JSON.parse(qualitiesJson);
|
||||
|
||||
// let highestQuality = null;
|
||||
// let highestQualityNum = 0;
|
||||
|
||||
// for (const quality in qualities) {
|
||||
// if (qualities[quality].src) {
|
||||
// const qualityNum = parseInt(quality.replace('p', '')) || 0;
|
||||
// if (qualityNum > highestQualityNum) {
|
||||
// highestQualityNum = qualityNum;
|
||||
// highestQuality = qualities[quality].src;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (highestQuality) {
|
||||
|
||||
// if (highestQuality.startsWith('//')) {
|
||||
// highestQuality = 'https:' + highestQuality;
|
||||
// }
|
||||
|
||||
// return {
|
||||
// title: player.team.name,
|
||||
// streamUrl: highestQuality,
|
||||
// headers: {
|
||||
// "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
||||
// "Referer": "https://kodik.info/"
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// return null;
|
||||
// } catch (err) {
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
|
||||
players.sort((a, b) => {
|
||||
const order = { Animelib: 0, Kodik: 1 };
|
||||
return (order[a.player] ?? 99) - (order[b.player] ?? 99);
|
||||
@@ -137,22 +94,16 @@ async function extractStreamUrl(ID) {
|
||||
if (player.player === "Animelib" && player.video && player.video.quality) {
|
||||
const qualities = player.video.quality;
|
||||
|
||||
console.log(qualities);
|
||||
|
||||
for (const qualityItem of qualities) {
|
||||
if (qualityItem.href && qualityItem.quality > highestQualityNum) {
|
||||
highestQualityNum = qualityItem.quality;
|
||||
streamUrl = qualityItem.href;
|
||||
|
||||
console.log("Found Animelib quality: " + qualityItem.quality + " URL: " + streamUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// Animelib URLs are relative, prepend base URL
|
||||
if (streamUrl && !streamUrl.startsWith('http')) {
|
||||
// https://video1.cdnlibs.org/.аs/
|
||||
// https://video2.anilib.me/.аs/
|
||||
// https://video3.anilib.me/.аs/
|
||||
streamUrl = 'https://video1.cdnlibs.org/.%D0%B0s/' + streamUrl;
|
||||
}
|
||||
} else if (player.player === "Kodik" && player.src) {
|
||||
@@ -218,9 +169,9 @@ async function kodikParser(url) {
|
||||
const htmlText = await response.text();
|
||||
|
||||
const urlParamsMatch = htmlText.match(/var\s+urlParams\s*=\s*'([^']+)'/);
|
||||
const videoInfoTypeMatch = htmlText.match(/videoInfo\.type\s*=\s*'([^']+)'/);
|
||||
const videoInfoHashMatch = htmlText.match(/videoInfo\.hash\s*=\s*'([^']+)'/);
|
||||
const videoInfoIdMatch = htmlText.match(/videoInfo\.id\s*=\s*'([^']+)'/);
|
||||
const videoInfoTypeMatch = htmlText.match(/vInfo\.type\s*=\s*'([^']+)'/);
|
||||
const videoInfoHashMatch = htmlText.match(/vInfo\.hash\s*=\s*'([^']+)'/);
|
||||
const videoInfoIdMatch = htmlText.match(/vInfo\.id\s*=\s*'([^']+)'/);
|
||||
|
||||
const urlParams = urlParamsMatch ? JSON.parse(urlParamsMatch[1]) : {};
|
||||
const videoInfo_type = videoInfoTypeMatch ? videoInfoTypeMatch[1] : '';
|
||||
|
||||
Reference in New Issue
Block a user