mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 19:05:11 +00:00
feat: complete streaming and AJAX endpoint support
- Add stream URL extraction via /ajax/server?get={linkId}
- Add mapper API integration for gogoanime/anivibe servers
- Add /api/seasons/:id endpoint
- Add /api/watch-order/:id endpoint
- Add /api/episodes-ajax/:id endpoint
- Add /api/servers endpoint
- Add genre/type/status/rating ID mappings
- Fix filter to use correct numeric IDs
- Fix watch page data attribute extraction
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
import { URLS, BASE_URL } from "../configs/dataUrl.js";
|
||||
|
||||
const extractWatchPage = async (slug, ep) => {
|
||||
try {
|
||||
@@ -9,43 +9,41 @@ const extractWatchPage = async (slug, ep) => {
|
||||
const { data } = await axios.get(url, { headers });
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const title = $(".heading-name a").text().trim() || "";
|
||||
const animeId = parseInt($("#watch-main").attr("data-id")) || parseInt($("div[data-id]").attr("data-id")) || 0;
|
||||
const animeUrl = $("#watch-main").attr("data-url") || "";
|
||||
const title = $(".heading-name a").text().trim() || slug;
|
||||
const japaneseTitle = $(".heading-name .alternate-title").text().trim() || "";
|
||||
const animeId = $(".heading-name a").attr("href")?.split("/watch/").pop()?.split("/")[0] || "";
|
||||
const episodeNumber = parseInt(ep) || 0;
|
||||
|
||||
const episodeNumber = parseInt($(".heading-name .episode").text().trim()) || parseInt(ep) || 0;
|
||||
|
||||
const synopsis = $(".anisc-detail .description, .film-description .text").text().trim() || "";
|
||||
const synopsis = $(".synopsis .content, .film-description .text").text().trim() || "";
|
||||
|
||||
const animeInfo = {};
|
||||
$(".anisc-info .item").each((i, el) => {
|
||||
const label = $(el).find(".name").text().trim().replace(":", "");
|
||||
const value = $(el).find(".text").text().trim();
|
||||
$(".bmeta .meta div").each((i, el) => {
|
||||
const label = $(el).find("strong, b").text().trim().replace(":", "");
|
||||
const value = $(el).find("span, a").text().trim();
|
||||
if (label && value) {
|
||||
animeInfo[label] = value;
|
||||
}
|
||||
});
|
||||
|
||||
const genres = [];
|
||||
$(".anisc-info .item:last-child a, .genres a").each((i, el) => {
|
||||
$(".bmeta .meta div:contains('Genres') a").each((i, el) => {
|
||||
const genre = $(el).text().trim();
|
||||
if (genre) genres.push(genre);
|
||||
});
|
||||
|
||||
const servers = [];
|
||||
$(".servers .server-item, .type-list .server-item").each((i, el) => {
|
||||
const serverId = $(el).attr("data-id") || $(el).attr("data-server-id") || "";
|
||||
const serverName = $(el).text().trim() || "";
|
||||
const serverType = $(el).hasClass("sub") ? "sub" : "dub";
|
||||
const rating = $(".brating .score .value, #w-rating .score").text().trim() || "";
|
||||
const MALScore = $(".bmeta .meta div:contains('MAL') span").text().trim() || "";
|
||||
|
||||
if (serverId) {
|
||||
servers.push({ id: serverId, name: serverName, type: serverType });
|
||||
}
|
||||
});
|
||||
const poster = $(".poster img[itemprop='image'], .binfo .poster img").attr("src") || "";
|
||||
const backgroundImage = $("#player").css("background-image")?.match(/url\(['"]?(.+?)['"]?\)/)?.[1] || "";
|
||||
|
||||
const nextEpisodeDate = $(".next-episode, .alert.next-episode").text().trim() || "";
|
||||
const nextEpisodeTimestamp = parseInt($(".count-down").attr("data-target")) || 0;
|
||||
|
||||
const episodeList = [];
|
||||
$(".episodes-list .ep-item, .ss-list a").each((i, el) => {
|
||||
const epId = $(el).attr("data-id") || "";
|
||||
$("#w-episodes .ep-item, .episodes-list a, .ss-list a").each((i, el) => {
|
||||
const epId = $(el).attr("data-id") || $(el).attr("data-ep-id") || "";
|
||||
const epNum = parseInt($(el).find(".ep-number, .ep-num").text().trim()) || i + 1;
|
||||
const epTitle = $(el).find(".ep-title, .ep-name").text().trim() || "";
|
||||
const isActive = $(el).hasClass("active") || $(el).hasClass("selected") || false;
|
||||
@@ -60,63 +58,83 @@ const extractWatchPage = async (slug, ep) => {
|
||||
}
|
||||
});
|
||||
|
||||
const nextEpisodeDate = $(".next-episode, .schedule-next").text().trim() || "";
|
||||
const prevEpisode = $(".ep-prev a").attr("href")?.split("/ep-").pop() || "";
|
||||
const nextEpisode = $(".ep-next a").attr("href")?.split("/ep-").pop() || "";
|
||||
const servers = [];
|
||||
$("#w-servers .servers .type li, #w-servers li").each((i, el) => {
|
||||
const linkId = $(el).attr("data-link-id") || "";
|
||||
const epId = $(el).attr("data-ep-id") || "";
|
||||
const cmId = $(el).attr("data-cmid") || "";
|
||||
const svId = $(el).attr("data-sv-id") || "";
|
||||
const serverName = $(el).text().trim() || "";
|
||||
const serverType = $(el).closest(".type").attr("data-type") || "";
|
||||
|
||||
const relatedData = [];
|
||||
$(".related-content .item, .film-list-block .item").each((i, el) => {
|
||||
const relSlug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const relPoster = $(el).find("img").attr("src") || "";
|
||||
const relTitle = $(el).find(".name, .film-name a").text().trim() || "";
|
||||
const relType = $(el).find(".type, .fdi-item:first-child").text().trim() || "";
|
||||
|
||||
if (relSlug) {
|
||||
relatedData.push({ slug: relSlug, poster: relPoster, title: relTitle, type: relType });
|
||||
}
|
||||
});
|
||||
|
||||
const recommendedData = [];
|
||||
$(".recommend-content .item, .film-list-block .item").each((i, el) => {
|
||||
const recSlug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const recPoster = $(el).find("img").attr("src") || "";
|
||||
const recTitle = $(el).find(".name, .film-name a").text().trim() || "";
|
||||
const recType = $(el).find(".type, .fdi-item:first-child").text().trim() || "";
|
||||
|
||||
if (recSlug) {
|
||||
recommendedData.push({ slug: recSlug, poster: recPoster, title: recTitle, type: recType });
|
||||
if (linkId) {
|
||||
servers.push({
|
||||
linkId,
|
||||
epId,
|
||||
cmId,
|
||||
svId,
|
||||
name: serverName,
|
||||
type: serverType
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const trending = [];
|
||||
$(".trending-list .item, .top-tables .item").each((i, el) => {
|
||||
const trendSlug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const trendPoster = $(el).find("img").attr("src") || "";
|
||||
$(".w-side-section .scaff.side.items a.item").each((i, el) => {
|
||||
const trendSlug = $(el).attr("href")?.split("/watch/").pop() || "";
|
||||
const trendPoster = $(el).find(".poster img").attr("src") || "";
|
||||
const trendTitle = $(el).find(".name").text().trim() || "";
|
||||
const trendType = $(el).find(".type").text().trim() || "";
|
||||
const trendType = $(el).find(".dot:last-child").text().trim() || "";
|
||||
const trendScore = $(el).find(".score").text().trim() || "";
|
||||
|
||||
if (trendSlug) {
|
||||
trending.push({ slug: trendSlug, poster: trendPoster, title: trendTitle, type: trendType });
|
||||
trending.push({
|
||||
slug: trendSlug,
|
||||
poster: trendPoster,
|
||||
title: trendTitle,
|
||||
type: trendType,
|
||||
score: trendScore
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const recommended = [];
|
||||
$(".w-side-section:has(.title:contains('Recommended')) a.item, aside.sidebar:last .w-side-section a.item").each((i, el) => {
|
||||
const recSlug = $(el).attr("href")?.split("/watch/").pop() || "";
|
||||
const recPoster = $(el).find(".poster img").attr("src") || "";
|
||||
const recTitle = $(el).find(".name").text().trim() || "";
|
||||
const recType = $(el).find(".dot:last-child").text().trim() || "";
|
||||
|
||||
if (recSlug) {
|
||||
recommended.push({
|
||||
slug: recSlug,
|
||||
poster: recPoster,
|
||||
title: recTitle,
|
||||
type: recType
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
slug,
|
||||
title: title || slug,
|
||||
japaneseTitle,
|
||||
animeId,
|
||||
animeUrl,
|
||||
title,
|
||||
japaneseTitle,
|
||||
episodeNumber,
|
||||
synopsis,
|
||||
animeInfo,
|
||||
genres,
|
||||
servers,
|
||||
episodeList,
|
||||
rating,
|
||||
MALScore,
|
||||
poster,
|
||||
backgroundImage,
|
||||
nextEpisodeDate,
|
||||
prevEpisode,
|
||||
nextEpisode,
|
||||
relatedData,
|
||||
recommendedData,
|
||||
trending
|
||||
nextEpisodeTimestamp,
|
||||
episodeList,
|
||||
servers,
|
||||
trending,
|
||||
recommended
|
||||
};
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user