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
+34
View File
@@ -0,0 +1,34 @@
const BASE_URL = "https://anikototv.to";
const ALT_DOMAINS = [
"https://anikoto.cz",
"https://anikoto.me",
"https://anikototv.to",
"https://anikoto.net",
"https://anikoto.se"
];
const URLS = {
home: `${BASE_URL}/home`,
search: `${BASE_URL}/search`,
genre: (genre) => `${BASE_URL}/genre/${genre}`,
azList: (letter) => `${BASE_URL}/az-list/${letter}`,
category: (cat) => `${BASE_URL}/${cat}`,
anime: (id) => `${BASE_URL}/anime/${id}`,
episode: (id) => `${BASE_URL}/episode/${id}`,
schedule: (date) => `${BASE_URL}/schedule/${date}`,
topTen: `${BASE_URL}/top-ten`,
mostPopular: `${BASE_URL}/most-popular`,
mostFavorite: `${BASE_URL}/most-favorite`,
recentlyUpdated: `${BASE_URL}/recently-updated`,
recentlyAdded: `${BASE_URL}/recently-added`,
subbedAnime: `${BASE_URL}/subbed-anime`,
dubbedAnime: `${BASE_URL}/dubbed-anime`,
movie: `${BASE_URL}/movie`,
ova: `${BASE_URL}/ova`,
ona: `${BASE_URL}/ona`,
special: `${BASE_URL}/special`,
tv: `${BASE_URL}/tv`,
music: `${BASE_URL}/music`
};
export { BASE_URL, ALT_DOMAINS, URLS };
+10
View File
@@ -0,0 +1,10 @@
const headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1"
};
export { headers };
+25
View File
@@ -0,0 +1,25 @@
import { extractAnimeInfo } from "../extractors/animeInfo.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getAnimeInfo = async (req, res, next) => {
try {
const { id } = req.query;
if (!id) {
return res.status(400).json({ success: false, message: "Anime ID is required" });
}
const cacheKey = `anime_${id}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractAnimeInfo(id);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getAnimeInfo };
+27
View File
@@ -0,0 +1,27 @@
import { extractCategory } from "../extractors/category.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getCategory = async (req, res, next) => {
try {
const { category } = req.params;
const { page = 1 } = req.query;
if (!category) {
return res.status(400).json({ success: false, message: "Category is required" });
}
const cacheKey = `category_${category}_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractCategory(category, page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getCategory };
+26
View File
@@ -0,0 +1,26 @@
import { extractEpisodeList } from "../extractors/episodeList.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getEpisodeList = async (req, res, next) => {
try {
const { id } = req.params;
if (!id) {
return res.status(400).json({ success: false, message: "Anime ID is required" });
}
const cacheKey = `episodes_${id}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractEpisodeList(id);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getEpisodeList };
+21
View File
@@ -0,0 +1,21 @@
import { extractFilter } from "../extractors/filter.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getFilter = async (req, res, next) => {
try {
const params = req.query;
const cacheKey = `filter_${JSON.stringify(params)}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractFilter(params);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getFilter };
+20
View File
@@ -0,0 +1,20 @@
import { extractHomeInfo } from "../extractors/homeInfo.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getHomeInfo = async (req, res, next) => {
try {
const cacheKey = "home";
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractHomeInfo();
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getHomeInfo };
+21
View File
@@ -0,0 +1,21 @@
import { extractPopular } from "../extractors/popular.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getPopular = async (req, res, next) => {
try {
const { page = 1 } = req.query;
const cacheKey = `popular_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractPopular(page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getPopular };
+20
View File
@@ -0,0 +1,20 @@
import { extractRandom } from "../extractors/random.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getRandom = async (req, res, next) => {
try {
const cacheKey = "random";
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractRandom();
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getRandom };
+26
View File
@@ -0,0 +1,26 @@
import { extractSchedule } from "../extractors/schedule.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getSchedule = async (req, res, next) => {
try {
const { date } = req.query;
if (!date) {
return res.status(400).json({ success: false, message: "Date is required (YYYY-MM-DD)" });
}
const cacheKey = `schedule_${date}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractSchedule(date);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getSchedule };
+46
View File
@@ -0,0 +1,46 @@
import { extractSearchResults, extractSearchSuggestions } from "../extractors/search.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getSearchResults = async (req, res, next) => {
try {
const { keyword, page = 1 } = req.query;
if (!keyword) {
return res.status(400).json({ success: false, message: "Keyword is required" });
}
const cacheKey = `search_${keyword}_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractSearchResults(keyword, page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
const getSearchSuggestions = async (req, res, next) => {
try {
const { keyword } = req.query;
if (!keyword) {
return res.status(400).json({ success: false, message: "Keyword is required" });
}
const cacheKey = `suggest_${keyword}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractSearchSuggestions(keyword);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getSearchResults, getSearchSuggestions };
+20
View File
@@ -0,0 +1,20 @@
import { extractSpotlight } from "../extractors/spotlight.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getSpotlight = async (req, res, next) => {
try {
const cacheKey = "spotlight";
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractSpotlight();
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getSpotlight };
+26
View File
@@ -0,0 +1,26 @@
import { extractStreamInfo } from "../extractors/streamInfo.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getStreamInfo = async (req, res, next) => {
try {
const { id, server = "hd-1", type = "sub" } = req.query;
if (!id) {
return res.status(400).json({ success: false, message: "Episode ID is required" });
}
const cacheKey = `stream_${id}_${server}_${type}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractStreamInfo(id, server, type);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getStreamInfo };
+26
View File
@@ -0,0 +1,26 @@
import { extractSuggestions } from "../extractors/suggestion.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getSuggestions = async (req, res, next) => {
try {
const { keyword } = req.query;
if (!keyword) {
return res.status(400).json({ success: false, message: "Keyword is required" });
}
const cacheKey = `suggest_${keyword}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractSuggestions(keyword);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getSuggestions };
+20
View File
@@ -0,0 +1,20 @@
import { extractTopTen } from "../extractors/topten.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getTopTen = async (req, res, next) => {
try {
const cacheKey = "topTen";
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractTopTen();
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getTopTen };
+20
View File
@@ -0,0 +1,20 @@
import { extractTrending } from "../extractors/trending.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getTrending = async (req, res, next) => {
try {
const cacheKey = "trending";
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractTrending();
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getTrending };
+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 };
+21
View File
@@ -0,0 +1,21 @@
const cache = new Map();
const CACHE_TTL = 5 * 60 * 1000;
const getCache = (key) => {
const item = cache.get(key);
if (item && Date.now() - item.timestamp < CACHE_TTL) {
return item.data;
}
cache.delete(key);
return null;
};
const setCache = (key, data) => {
cache.set(key, { data, timestamp: Date.now() });
};
const clearCache = () => {
cache.clear();
};
export { getCache, setCache, clearCache };
+12
View File
@@ -0,0 +1,12 @@
const countPages = ($) => {
const pages = [];
$(".pagination li a").each((i, el) => {
const text = $(el).text().trim();
if (!isNaN(text) && text !== "") {
pages.push(parseInt(text));
}
});
return pages.length > 0 ? Math.max(...pages) : 1;
};
export { countPages };
+16
View File
@@ -0,0 +1,16 @@
import * as cheerio from "cheerio";
import axios from "axios";
import { headers } from "../configs/header.config.js";
const extractPages = async (url, page = 1) => {
try {
const finalUrl = page > 1 ? `${url}?page=${page}` : url;
const { data } = await axios.get(finalUrl, { headers });
const $ = cheerio.load(data);
return $;
} catch (error) {
throw error;
}
};
export { extractPages };
+9
View File
@@ -0,0 +1,9 @@
const formatTitle = (title) => {
if (!title) return "";
return title
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "");
};
export { formatTitle };
+132
View File
@@ -0,0 +1,132 @@
import { getHomeInfo } from "../controllers/homeInfo.controller.js";
import { getAnimeInfo } from "../controllers/animeInfo.controller.js";
import { getSearchResults, getSearchSuggestions } from "../controllers/search.controller.js";
import { getEpisodeList } from "../controllers/episodeList.controller.js";
import { getStreamInfo } from "../controllers/streamInfo.controller.js";
import { getSchedule } from "../controllers/schedule.controller.js";
import { getSpotlight } from "../controllers/spotlight.controller.js";
import { getTrending } from "../controllers/trending.controller.js";
import { getTopTen } from "../controllers/topten.controller.js";
import { getSuggestions } from "../controllers/suggestion.controller.js";
import { getRandom } from "../controllers/random.controller.js";
import { getPopular } from "../controllers/popular.controller.js";
import { getFilter } from "../controllers/filter.controller.js";
import { categoryRoutes } from "./category.route.js";
const createApiRoutes = (app, jsonResponse, jsonError) => {
app.get("/api/", async (req, res, next) => {
try {
await getHomeInfo(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/info", async (req, res, next) => {
try {
await getAnimeInfo(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/search", async (req, res, next) => {
try {
await getSearchResults(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/search/suggest", async (req, res, next) => {
try {
await getSearchSuggestions(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/episodes/:id", async (req, res, next) => {
try {
await getEpisodeList(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/stream", async (req, res, next) => {
try {
await getStreamInfo(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/schedule", async (req, res, next) => {
try {
await getSchedule(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/spotlight", async (req, res, next) => {
try {
await getSpotlight(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/trending", async (req, res, next) => {
try {
await getTrending(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/top-ten", async (req, res, next) => {
try {
await getTopTen(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/suggestions", async (req, res, next) => {
try {
await getSuggestions(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/random", async (req, res, next) => {
try {
await getRandom(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/most-popular", async (req, res, next) => {
try {
await getPopular(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/filter", async (req, res, next) => {
try {
await getFilter(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
categoryRoutes(app, jsonResponse, jsonError);
};
export { createApiRoutes };
+13
View File
@@ -0,0 +1,13 @@
import { getCategory } from "../controllers/category.controller.js";
const categoryRoutes = (app, jsonResponse, jsonError) => {
app.get("/api/:category", async (req, res, next) => {
try {
await getCategory(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
};
export { categoryRoutes };