mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
- Fixed ALL CSS selectors to match actual anikototv.to HTML - Fixed search results returning empty data array - Fixed anime info returning empty fields - Fixed episode list returning 0 episodes - Fixed most-popular returning empty data - Fixed random endpoint 500 error - Fixed filter endpoint 500 error - Fixed suggestions returning empty array - Added /api/genre/:name and /api/type/:name routes - Fixed watch page server/episode extraction - Fixed rating field to return clean value
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import * as cheerio from "cheerio";
|
|
import axios from "axios";
|
|
import { headers } from "../configs/header.config.js";
|
|
import { URLS } from "../configs/dataUrl.js";
|
|
|
|
const extractSuggestions = async (keyword) => {
|
|
try {
|
|
const url = `${URLS.search}?keyword=${encodeURIComponent(keyword)}`;
|
|
const { data } = await axios.get(url, { headers });
|
|
const $ = cheerio.load(data);
|
|
|
|
const suggestions = [];
|
|
$("#list-items > .item").each((i, el) => {
|
|
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
|
const poster = $(el).find(".ani.poster.tip > a > img").attr("src") || "";
|
|
const title = $(el).find(".info .b1 a.name.d-title").text().trim() || "";
|
|
const japaneseTitle = $(el).find(".info .b1 a.name.d-title").attr("data-jp") || "";
|
|
const type = $(el).find(".info .meta .m-item:nth-child(2) label").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;
|
|
|
|
if (slug) {
|
|
suggestions.push({ slug, poster, title, japaneseTitle, type, sub, dub });
|
|
}
|
|
});
|
|
|
|
return suggestions.slice(0, 10);
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export { extractSuggestions }; |