mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
feat: add complete API endpoints for full website
- Add /api/watch endpoint for watch page data - Add /api/az-list for alphabetical browsing - Add /api/new-release and /api/newly-added - Add /api/status for ongoing/completed lists - Add /api/trending-sidebar for sidebar data - Update README with all new endpoints - Update CHANGELOG
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
import { extractPages } from "../helper/extractPages.helper.js";
|
||||
import { countPages } from "../helper/countPages.helper.js";
|
||||
|
||||
const extractAzList = async (letter = "all", page = 1) => {
|
||||
try {
|
||||
const url = URLS.azList(letter);
|
||||
const $ = await extractPages(url, page);
|
||||
const totalPages = countPages($);
|
||||
|
||||
const results = [];
|
||||
$(".film_list-wrap .flw-item, .film-detail, .item").each((i, el) => {
|
||||
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find("img").attr("src") || "";
|
||||
const title = $(el).find(".film-name a, .name.d-title").text().trim() || "";
|
||||
const japaneseTitle = $(el).find(".name.d-title").attr("data-jp") || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const total = parseInt($(el).find(".ep-status.total span").text().trim()) || 0;
|
||||
const type = $(el).find(".meta .inner .right, .fdi-item:nth-child(2)").text().trim() || "";
|
||||
const rating = $(el).find(".rating, .fdi-item:nth-child(3)").text().trim() || "";
|
||||
|
||||
if (slug) {
|
||||
results.push({
|
||||
slug,
|
||||
poster,
|
||||
title,
|
||||
japaneseTitle,
|
||||
sub,
|
||||
dub,
|
||||
total,
|
||||
type,
|
||||
rating
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { totalPages, letter, data: results };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export { extractAzList };
|
||||
@@ -0,0 +1,82 @@
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
import { extractPages } from "../helper/extractPages.helper.js";
|
||||
import { countPages } from "../helper/countPages.helper.js";
|
||||
|
||||
const extractNewRelease = async (page = 1) => {
|
||||
try {
|
||||
const $ = await extractPages(URLS.newRelease, page);
|
||||
const totalPages = countPages($);
|
||||
|
||||
const results = [];
|
||||
$(".film_list-wrap .flw-item, .film-detail, .item").each((i, el) => {
|
||||
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find("img").attr("src") || "";
|
||||
const title = $(el).find(".film-name a, .name.d-title").text().trim() || "";
|
||||
const japaneseTitle = $(el).find(".name.d-title").attr("data-jp") || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const total = parseInt($(el).find(".ep-status.total span").text().trim()) || 0;
|
||||
const type = $(el).find(".meta .inner .right, .fdi-item:nth-child(2)").text().trim() || "";
|
||||
const rating = $(el).find(".rating, .fdi-item:nth-child(3)").text().trim() || "";
|
||||
|
||||
if (slug) {
|
||||
results.push({
|
||||
slug,
|
||||
poster,
|
||||
title,
|
||||
japaneseTitle,
|
||||
sub,
|
||||
dub,
|
||||
total,
|
||||
type,
|
||||
rating
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { totalPages, data: results };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const extractNewlyAdded = async (page = 1) => {
|
||||
try {
|
||||
const $ = await extractPages(`${URLS.latestUpdated}?sort=added`, page);
|
||||
const totalPages = countPages($);
|
||||
|
||||
const results = [];
|
||||
$(".film_list-wrap .flw-item, .film-detail, .item").each((i, el) => {
|
||||
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find("img").attr("src") || "";
|
||||
const title = $(el).find(".film-name a, .name.d-title").text().trim() || "";
|
||||
const japaneseTitle = $(el).find(".name.d-title").attr("data-jp") || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const total = parseInt($(el).find(".ep-status.total span").text().trim()) || 0;
|
||||
const type = $(el).find(".meta .inner .right, .fdi-item:nth-child(2)").text().trim() || "";
|
||||
|
||||
if (slug) {
|
||||
results.push({
|
||||
slug,
|
||||
poster,
|
||||
title,
|
||||
japaneseTitle,
|
||||
sub,
|
||||
dub,
|
||||
total,
|
||||
type
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { totalPages, data: results };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export { extractNewRelease, extractNewlyAdded };
|
||||
@@ -0,0 +1,47 @@
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
import { extractPages } from "../helper/extractPages.helper.js";
|
||||
import { countPages } from "../helper/countPages.helper.js";
|
||||
|
||||
const extractStatus = async (status, page = 1) => {
|
||||
try {
|
||||
const url = URLS.status(status);
|
||||
const $ = await extractPages(url, page);
|
||||
const totalPages = countPages($);
|
||||
|
||||
const results = [];
|
||||
$(".film_list-wrap .flw-item, .film-detail, .item").each((i, el) => {
|
||||
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find("img").attr("src") || "";
|
||||
const title = $(el).find(".film-name a, .name.d-title").text().trim() || "";
|
||||
const japaneseTitle = $(el).find(".name.d-title").attr("data-jp") || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const total = parseInt($(el).find(".ep-status.total span").text().trim()) || 0;
|
||||
const type = $(el).find(".meta .inner .right, .fdi-item:nth-child(2)").text().trim() || "";
|
||||
const rating = $(el).find(".rating, .fdi-item:nth-child(3)").text().trim() || "";
|
||||
|
||||
if (slug) {
|
||||
results.push({
|
||||
slug,
|
||||
poster,
|
||||
title,
|
||||
japaneseTitle,
|
||||
sub,
|
||||
dub,
|
||||
total,
|
||||
type,
|
||||
rating
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { totalPages, status, data: results };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export { extractStatus };
|
||||
@@ -0,0 +1,79 @@
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
|
||||
const extractTrendingSidebar = async () => {
|
||||
try {
|
||||
const { data } = await axios.get(URLS.home, { headers });
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const day = [];
|
||||
const week = [];
|
||||
const month = [];
|
||||
|
||||
$("#top-anime .tab-content[data-name='day'] a.item").each((i, el) => {
|
||||
const slug = $(el).attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find(".poster img").attr("src") || "";
|
||||
const name = $(el).find(".name").text().trim() || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const type = $(el).find(".type").text().trim() || "";
|
||||
const rank = i + 1;
|
||||
|
||||
if (slug) {
|
||||
day.push({ slug, rank, name, poster, sub, dub, type });
|
||||
}
|
||||
});
|
||||
|
||||
$("#top-anime .tab-content[data-name='week'] a.item").each((i, el) => {
|
||||
const slug = $(el).attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find(".poster img").attr("src") || "";
|
||||
const name = $(el).find(".name").text().trim() || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const type = $(el).find(".type").text().trim() || "";
|
||||
const rank = i + 1;
|
||||
|
||||
if (slug) {
|
||||
week.push({ slug, rank, name, poster, sub, dub, type });
|
||||
}
|
||||
});
|
||||
|
||||
$("#top-anime .tab-content[data-name='month'] a.item").each((i, el) => {
|
||||
const slug = $(el).attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find(".poster img").attr("src") || "";
|
||||
const name = $(el).find(".name").text().trim() || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const type = $(el).find(".type").text().trim() || "";
|
||||
const rank = i + 1;
|
||||
|
||||
if (slug) {
|
||||
month.push({ slug, rank, name, poster, sub, dub, type });
|
||||
}
|
||||
});
|
||||
|
||||
const latestEpisodes = [];
|
||||
$("#recent-update .item, .section-updated .item").each((i, el) => {
|
||||
const slug = $(el).find("a.name.d-title").attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find(".poster img").attr("src") || "";
|
||||
const title = $(el).find("a.name.d-title").text().trim() || "";
|
||||
const japaneseTitle = $(el).find("a.name.d-title").attr("data-jp") || "";
|
||||
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
||||
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
||||
const total = parseInt($(el).find(".ep-status.total span").text().trim()) || 0;
|
||||
const type = $(el).find(".meta .inner .right").text().trim() || "";
|
||||
|
||||
if (slug) {
|
||||
latestEpisodes.push({ slug, poster, title, japaneseTitle, sub, dub, total, type });
|
||||
}
|
||||
});
|
||||
|
||||
return { day, week, month, latestEpisodes };
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export { extractTrendingSidebar };
|
||||
@@ -0,0 +1,126 @@
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
|
||||
const extractWatchPage = async (slug, ep) => {
|
||||
try {
|
||||
const url = URLS.episode(slug, ep);
|
||||
const { data } = await axios.get(url, { headers });
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const title = $(".heading-name a").text().trim() || "";
|
||||
const japaneseTitle = $(".heading-name .alternate-title").text().trim() || "";
|
||||
const animeId = $(".heading-name a").attr("href")?.split("/watch/").pop()?.split("/")[0] || "";
|
||||
|
||||
const episodeNumber = parseInt($(".heading-name .episode").text().trim()) || parseInt(ep) || 0;
|
||||
|
||||
const synopsis = $(".anisc-detail .description, .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();
|
||||
if (label && value) {
|
||||
animeInfo[label] = value;
|
||||
}
|
||||
});
|
||||
|
||||
const genres = [];
|
||||
$(".anisc-info .item:last-child a, .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";
|
||||
|
||||
if (serverId) {
|
||||
servers.push({ id: serverId, name: serverName, type: serverType });
|
||||
}
|
||||
});
|
||||
|
||||
const episodeList = [];
|
||||
$(".episodes-list .ep-item, .ss-list a").each((i, el) => {
|
||||
const epId = $(el).attr("data-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;
|
||||
|
||||
if (epId || epNum) {
|
||||
episodeList.push({
|
||||
id: epId,
|
||||
episode_no: epNum,
|
||||
title: epTitle,
|
||||
active: isActive
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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 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 });
|
||||
}
|
||||
});
|
||||
|
||||
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") || "";
|
||||
const trendTitle = $(el).find(".name").text().trim() || "";
|
||||
const trendType = $(el).find(".type").text().trim() || "";
|
||||
|
||||
if (trendSlug) {
|
||||
trending.push({ slug: trendSlug, poster: trendPoster, title: trendTitle, type: trendType });
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
slug,
|
||||
title: title || slug,
|
||||
japaneseTitle,
|
||||
animeId,
|
||||
episodeNumber,
|
||||
synopsis,
|
||||
animeInfo,
|
||||
genres,
|
||||
servers,
|
||||
episodeList,
|
||||
nextEpisodeDate,
|
||||
prevEpisode,
|
||||
nextEpisode,
|
||||
relatedData,
|
||||
recommendedData,
|
||||
trending
|
||||
};
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export { extractWatchPage };
|
||||
Reference in New Issue
Block a user