From 5c17dc19f2085865c91fe5e2e9b46b2968d4b100 Mon Sep 17 00:00:00 2001 From: ibro Date: Sun, 21 Dec 2025 02:55:04 +0000 Subject: [PATCH] added animelib when extracting streams in animelib module --- animelib/animelib.js | 114 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 22 deletions(-) diff --git a/animelib/animelib.js b/animelib/animelib.js index b34b130..e0b35a8 100644 --- a/animelib/animelib.js +++ b/animelib/animelib.js @@ -80,42 +80,112 @@ async function extractStreamUrl(ID) { 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); + }); + const parserPromises = players - .filter(player => player.src && player.team && player.team.name) + .filter(player => 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 streamUrl = 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 (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); } } - } - - if (highestQuality) { - - if (highestQuality.startsWith('//')) { - highestQuality = 'https:' + highestQuality; + + // 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) { + const kodikUrl = "https:" + player.src; + const qualitiesJson = await kodikParser(kodikUrl); + const qualities = JSON.parse(qualitiesJson); + + for (const quality in qualities) { + if (qualities[quality].src) { + const qualityNum = parseInt(quality.replace('p', '')) || 0; + if (qualityNum > highestQualityNum) { + highestQualityNum = qualityNum; + streamUrl = qualities[quality].src; + } + } } + if (streamUrl && streamUrl.startsWith('//')) { + streamUrl = 'https:' + streamUrl; + } + } + + if (streamUrl) { return { - title: player.team.name, - streamUrl: highestQuality, + title: player.team.name + (highestQualityNum ? ` (${highestQualityNum}p)` : '') + (player.player === "Animelib" ? " (Animelib)" : " (Kodik)"), + streamUrl, headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", - "Referer": "https://kodik.info/" + "Referer": player.player === "Kodik" ? "https://kodik.info/" : "https://v3.animelib.org/" } }; } + return null; } catch (err) { return null;