feat: initial project setup for AniKatoAPI

- Express.js server with Vercel deployment support
- Complete API endpoints for anikototv.to anime data
- Home, search, info, episodes, stream, schedule endpoints
- Category filtering and genre support
- Caching system with 5-minute TTL
- CORS configuration
- Public documentation page
- Docker and Render deployment configs
- MIT License
This commit is contained in:
Sʜɪɴᴇɪ Nᴏᴜᴢᴇɴ
2026-06-08 15:08:22 +05:30
commit 3815521b0d
47 changed files with 1846 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { BASE_URL } from "../configs/dataUrl.js";
const extractAnimeInfo = async (id) => {
try {
const url = `${BASE_URL}/anime/${id}`;
const { data } = await axios.get(url, { headers });
const $ = cheerio.load(data);
const title = $(".film-name h1, .anisc-detail .film-name").text().trim() || "";
const japaneseTitle = $(".film-name .alternate-title, .anisc-detail .film-name small").text().trim() || "";
const poster = $(".film-poster img").attr("src") || "";
const showType = $(".film-info .row .col1 .item:first-child .name").text().trim() || "";
const quality = $(".film-info .row .col1 .item:nth-child(2) .name").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 overview = $(".anisc-detail .description, .film-description .text").text().trim() || "";
const genres = [];
$(".anisc-info .item:last-child a, .genres a").each((i, el) => {
const genre = $(el).text().trim();
if (genre) genres.push(genre);
});
const seasons = [];
$(".seasons .season-item, .ss-list a").each((i, el) => {
const seasonId = $(el).attr("href")?.split("/").pop() || "";
const seasonTitle = $(el).text().trim() || "";
const seasonPoster = $(el).find("img").attr("src") || "";
if (seasonId) {
seasons.push({
id: seasonId,
title: seasonTitle,
poster: seasonPoster
});
}
});
const relatedData = [];
$(".related-content .film-detail, .film-list-block .film-detail").each((i, el) => {
const relId = $(el).find("a").attr("href")?.split("/").pop() || "";
const relPoster = $(el).find("img").attr("src") || "";
const relTitle = $(el).find(".film-name a").text().trim() || "";
const relType = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
if (relId) {
relatedData.push({
id: relId,
poster: relPoster,
title: relTitle,
type: relType
});
}
});
const recommendedData = [];
$(".recommend-content .film-detail, .film-list-block .film-detail").each((i, el) => {
const recId = $(el).find("a").attr("href")?.split("/").pop() || "";
const recPoster = $(el).find("img").attr("src") || "";
const recTitle = $(el).find(".film-name a").text().trim() || "";
const recType = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
if (recId) {
recommendedData.push({
id: recId,
poster: recPoster,
title: recTitle,
type: recType
});
}
});
return {
id,
title,
japaneseTitle,
poster,
showType,
quality,
overview,
animeInfo,
genres,
seasons,
relatedData,
recommendedData
};
} catch (error) {
throw error;
}
};
export { extractAnimeInfo };
+44
View File
@@ -0,0 +1,44 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
import { countPages } from "../helper/countPages.helper.js";
import { extractPages } from "../helper/extractPages.helper.js";
const extractCategory = async (category, page = 1) => {
try {
const url = URLS.category(category);
const $ = await extractPages(url, page);
const totalPages = countPages($);
const results = [];
$(".film_list-wrap .flw-item, .film-detail").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const showType = $(el).find(".fd-infor .fdi-item:nth-child(2)").text().trim() || "";
const sub = parseInt($(el).find(".tick-sub").text().trim()) || 0;
const dub = parseInt($(el).find(".tick-dub").text().trim()) || 0;
const eps = parseInt($(el).find(".tick-eps").text().trim()) || 0;
const adultContent = $(el).find(".tick-adult, .adult-badge").length > 0;
if (id) {
results.push({
id,
poster,
title,
japaneseTitle,
tvInfo: { showType, sub, dub, eps },
adultContent
});
}
});
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
export { extractCategory };
+40
View File
@@ -0,0 +1,40 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { BASE_URL } from "../configs/dataUrl.js";
const extractEpisodeList = async (id) => {
try {
const url = `${BASE_URL}/anime/${id}`;
const { data } = await axios.get(url, { headers });
const $ = cheerio.load(data);
const episodes = [];
$(".episodes-list .ep-item, .ss-list a").each((i, el) => {
const epId = $(el).attr("data-id") || $(el).attr("href")?.split("/").pop() || "";
const epNumber = parseInt($(el).find(".ep-number, .ep-num").text().trim()) || i + 1;
const title = $(el).find(".ep-title, .ep-name").text().trim() || "";
const japaneseTitle = $(el).find(".ep-jp").text().trim() || "";
const filler = $(el).hasClass("filler") || false;
if (epId) {
episodes.push({
id: epId,
episode_no: epNumber,
title,
japaneseTitle,
filler
});
}
});
return {
totalEpisodes: episodes.length,
episodes
};
} catch (error) {
throw error;
}
};
export { extractEpisodeList };
+60
View File
@@ -0,0 +1,60 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { BASE_URL } from "../configs/dataUrl.js";
import { countPages } from "../helper/countPages.helper.js";
import { extractPages } from "../helper/extractPages.helper.js";
const extractFilter = async (params) => {
try {
const queryParams = new URLSearchParams();
if (params.type) queryParams.set("type", params.type);
if (params.status) queryParams.set("status", params.status);
if (params.rated) queryParams.set("rated", params.rated);
if (params.score) queryParams.set("score", params.score);
if (params.season) queryParams.set("season", params.season);
if (params.language) queryParams.set("language", params.language);
if (params.genres) queryParams.set("genres", params.genres);
if (params.sort) queryParams.set("sort", params.sort);
if (params.sy) queryParams.set("sy", params.sy);
if (params.sm) queryParams.set("sm", params.sm);
if (params.sd) queryParams.set("sd", params.sd);
if (params.ey) queryParams.set("ey", params.ey);
if (params.em) queryParams.set("em", params.em);
if (params.ed) queryParams.set("ed", params.ed);
if (params.keyword) queryParams.set("keyword", params.keyword);
const url = `${BASE_URL}/filter?${queryParams.toString()}`;
const $ = await extractPages(url, params.page || 1);
const totalPages = countPages($);
const results = [];
$(".film_list-wrap .flw-item, .film-detail").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const showType = $(el).find(".fd-infor .fdi-item:nth-child(2)").text().trim() || "";
const sub = parseInt($(el).find(".tick-sub").text().trim()) || 0;
const dub = parseInt($(el).find(".tick-dub").text().trim()) || 0;
const eps = parseInt($(el).find(".tick-eps").text().trim()) || 0;
if (id) {
results.push({
id,
poster,
title,
japaneseTitle,
tvInfo: { showType, sub, dub, eps }
});
}
});
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
export { extractFilter };
+124
View File
@@ -0,0 +1,124 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
const extractHomeInfo = async () => {
try {
const { data } = await axios.get(URLS.home, { headers });
const $ = cheerio.load(data);
const spotlights = [];
$(".swiper-slide, .spotlight-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fdi-item:nth-child(1)").text().trim() || "";
const description = $(el).find(".fd-infor .desc, .film-description").text().trim() || "";
const showType = $(el).find(".fdi-item:nth-child(2)").text().trim() || "";
const duration = $(el).find(".fdi-item:nth-child(3)").text().trim() || "";
const releaseDate = $(el).find(".fdi-item:nth-child(4)").text().trim() || "";
if (id) {
spotlights.push({
id,
poster,
title,
japaneseTitle,
description,
tvInfo: { showType, duration, releaseDate }
});
}
});
const trending = [];
$(".trending-list .film-detail, .trending-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const number = parseInt($(el).find(".number").text().trim()) || i + 1;
if (id) {
trending.push({ id, number, poster, title });
}
});
const topAiring = [];
$(".section-id-02 .film-detail, .top-airing .film-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
if (id) {
topAiring.push({ id, poster, title, japaneseTitle });
}
});
const mostPopular = [];
$(".section-id-03 .film-detail, .popular .film-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
if (id) {
mostPopular.push({ id, poster, title });
}
});
const mostFavorite = [];
$(".section-id-04 .film-detail, .favorite .film-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
if (id) {
mostFavorite.push({ id, poster, title });
}
});
const latestCompleted = [];
$(".section-id-05 .film-detail, .completed .film-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
if (id) {
latestCompleted.push({ id, poster, title });
}
});
const latestEpisode = [];
$(".section-id-06 .film-detail, .latest .film-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const episode = $(el).find(".tick-eps, .tick-sub").text().trim() || "";
if (id) {
latestEpisode.push({ id, poster, title, episode });
}
});
const genres = [];
$(".genre-item, .genres a").each((i, el) => {
const genre = $(el).text().trim();
if (genre) genres.push(genre);
});
return {
spotlights,
trending,
topAiring,
mostPopular,
mostFavorite,
latestCompleted,
latestEpisode,
genres
};
} catch (error) {
throw error;
}
};
export { extractHomeInfo };
+41
View File
@@ -0,0 +1,41 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
import { countPages } from "../helper/countPages.helper.js";
import { extractPages } from "../helper/extractPages.helper.js";
const extractPopular = async (page = 1) => {
try {
const $ = await extractPages(URLS.mostPopular, page);
const totalPages = countPages($);
const results = [];
$(".film_list-wrap .flw-item, .film-detail").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const showType = $(el).find(".fd-infor .fdi-item:nth-child(2)").text().trim() || "";
const sub = parseInt($(el).find(".tick-sub").text().trim()) || 0;
const dub = parseInt($(el).find(".tick-dub").text().trim()) || 0;
const eps = parseInt($(el).find(".tick-eps").text().trim()) || 0;
if (id) {
results.push({
id,
poster,
title,
japaneseTitle,
tvInfo: { showType, sub, dub, eps }
});
}
});
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
export { extractPopular };
+40
View File
@@ -0,0 +1,40 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { BASE_URL } from "../configs/dataUrl.js";
const extractRandom = async () => {
try {
const { data } = await axios.get(`${BASE_URL}/random`, {
headers,
maxRedirects: 5
});
const $ = cheerio.load(data);
const title = $(".film-name h1, .anisc-detail .film-name").text().trim() || "";
const japaneseTitle = $(".film-name .alternate-title, .anisc-detail .film-name small").text().trim() || "";
const poster = $(".film-poster img").attr("src") || "";
const showType = $(".film-info .row .col1 .item:first-child .name").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;
}
});
return {
title,
japaneseTitle,
poster,
showType,
animeInfo
};
} catch (error) {
throw error;
}
};
export { extractRandom };
+39
View File
@@ -0,0 +1,39 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
const extractSchedule = async (date) => {
try {
const url = URLS.schedule(date);
const { data } = await axios.get(url, { headers });
const $ = cheerio.load(data);
const schedule = [];
$(".schedule-item, .anime-schedule .item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const time = $(el).find(".time, .schedule-time").text().trim() || "";
const episodeNo = parseInt($(el).find(".episode-no, .ep-num").text().trim()) || 0;
const releaseDate = $(el).find(".date, .release-date").text().trim() || "";
if (id) {
schedule.push({
id,
title,
japaneseTitle,
time,
episode_no: episodeNo,
releaseDate
});
}
});
return schedule;
} catch (error) {
throw error;
}
};
export { extractSchedule };
+67
View File
@@ -0,0 +1,67 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
import { countPages } from "../helper/countPages.helper.js";
import { extractPages } from "../helper/extractPages.helper.js";
const extractSearchResults = async (keyword, page = 1) => {
try {
const url = `${URLS.search}?keyword=${encodeURIComponent(keyword)}`;
const $ = await extractPages(url, page);
const totalPages = countPages($);
const results = [];
$(".film_list-wrap .flw-item, .search-list .film-detail").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const showType = $(el).find(".fd-infor .fdi-item:nth-child(2)").text().trim() || "";
const sub = parseInt($(el).find(".tick-sub").text().trim()) || 0;
const dub = parseInt($(el).find(".tick-dub").text().trim()) || 0;
const eps = parseInt($(el).find(".tick-eps").text().trim()) || 0;
if (id) {
results.push({
id,
poster,
title,
japaneseTitle,
tvInfo: { showType, sub, dub, eps }
});
}
});
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
const extractSearchSuggestions = async (keyword) => {
try {
const url = `${URLS.search}?keyword=${encodeURIComponent(keyword)}`;
const { data } = await axios.get(url, { headers });
const $ = cheerio.load(data);
const suggestions = [];
$(".search-suggest .film-detail, .nav-item a").each((i, el) => {
const id = $(el).attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name, .dynamic-name").text().trim() || "";
const showType = $(el).find(".fdi-item:first-child").text().trim() || "";
if (id) {
suggestions.push({ id, poster, title, showType });
}
});
return suggestions;
} catch (error) {
throw error;
}
};
export { extractSearchResults, extractSearchSuggestions };
+40
View File
@@ -0,0 +1,40 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
const extractSpotlight = async () => {
try {
const { data } = await axios.get(URLS.home, { headers });
const $ = cheerio.load(data);
const spotlights = [];
$(".swiper-slide, .spotlight-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fdi-item:nth-child(1)").text().trim() || "";
const description = $(el).find(".fd-infor .desc, .film-description").text().trim() || "";
const showType = $(el).find(".fdi-item:nth-child(2)").text().trim() || "";
const duration = $(el).find(".fdi-item:nth-child(3)").text().trim() || "";
const releaseDate = $(el).find(".fdi-item:nth-child(4)").text().trim() || "";
if (id) {
spotlights.push({
id,
poster,
title,
japaneseTitle,
description,
tvInfo: { showType, duration, releaseDate }
});
}
});
return spotlights;
} catch (error) {
throw error;
}
};
export { extractSpotlight };
+58
View File
@@ -0,0 +1,58 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { BASE_URL } from "../configs/dataUrl.js";
const extractStreamInfo = async (episodeId, server = "hd-1", type = "sub") => {
try {
const url = `${BASE_URL}/watch/${episodeId}`;
const { data } = await axios.get(url, { headers });
const $ = cheerio.load(data);
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 sources = [];
$(".player-source .source-item, .embed-source").each((i, el) => {
const sourceId = $(el).attr("data-id") || "";
const sourceUrl = $(el).attr("data-src") || $(el).find("iframe").attr("src") || "";
const sourceType = $(el).attr("data-type") || "hls";
if (sourceId || sourceUrl) {
sources.push({ id: sourceId, url: sourceUrl, type: sourceType });
}
});
const subtitles = [];
$(".player-sub .sub-item, .subtitle-item").each((i, el) => {
const subUrl = $(el).attr("data-url") || $(el).attr("src") || "";
const subLabel = $(el).text().trim() || "";
const subLang = $(el).attr("data-lang") || "en";
if (subUrl) {
subtitles.push({ url: subUrl, label: subLabel, language: subLang });
}
});
return {
episodeId,
server,
type,
servers,
sources,
subtitles
};
} catch (error) {
throw error;
}
};
export { extractStreamInfo };
+32
View File
@@ -0,0 +1,32 @@
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 = [];
$(".search-suggest .film-detail, .nav-item a").each((i, el) => {
const id = $(el).attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const showType = $(el).find(".fdi-item:first-child").text().trim() || "";
const releaseDate = $(el).find(".fdi-item:nth-child(2)").text().trim() || "";
if (id) {
suggestions.push({ id, poster, title, japaneseTitle, showType, releaseDate });
}
});
return suggestions;
} catch (error) {
throw error;
}
};
export { extractSuggestions };
+57
View File
@@ -0,0 +1,57 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
const extractTopTen = async () => {
try {
const { data } = await axios.get(URLS.topTen, { headers });
const $ = cheerio.load(data);
const today = [];
const week = [];
const month = [];
$(".top-ten-list.today .top-ten-item, #top-viewed-day .top-list-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const name = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const number = parseInt($(el).find(".number").text().trim()) || i + 1;
const showType = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
if (id) {
today.push({ id, number, name, poster, tvInfo: { showType } });
}
});
$(".top-ten-list.week .top-ten-item, #top-viewed-week .top-list-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const name = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const number = parseInt($(el).find(".number").text().trim()) || i + 1;
const showType = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
if (id) {
week.push({ id, number, name, poster, tvInfo: { showType } });
}
});
$(".top-ten-list.month .top-ten-item, #top-viewed-month .top-list-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const name = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const number = parseInt($(el).find(".number").text().trim()) || i + 1;
const showType = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
if (id) {
month.push({ id, number, name, poster, tvInfo: { showType } });
}
});
return { today, week, month };
} catch (error) {
throw error;
}
};
export { extractTopTen };
+30
View File
@@ -0,0 +1,30 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
import { URLS } from "../configs/dataUrl.js";
const extractTrending = async () => {
try {
const { data } = await axios.get(URLS.home, { headers });
const $ = cheerio.load(data);
const trending = [];
$(".trending-list .film-detail, .trending-item").each((i, el) => {
const id = $(el).find("a").attr("href")?.split("/").pop() || "";
const poster = $(el).find("img").attr("src") || "";
const title = $(el).find(".film-name a, .dynamic-name").text().trim() || "";
const japaneseTitle = $(el).find(".fd-infor .fdi-item:first-child").text().trim() || "";
const number = parseInt($(el).find(".number").text().trim()) || i + 1;
if (id) {
trending.push({ id, number, poster, title, japaneseTitle });
}
});
return trending;
} catch (error) {
throw error;
}
};
export { extractTrending };