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:
Sʜɪɴᴇɪ Nᴏᴜᴢᴇɴ
2026-06-08 15:34:37 +05:30
parent cff5b394b3
commit 47789b2444
13 changed files with 632 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
import { extractAzList } from "../extractors/azList.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getAzList = async (req, res, next) => {
try {
const { letter = "all" } = req.params;
const { page = 1 } = req.query;
const cacheKey = `azlist_${letter}_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractAzList(letter, page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getAzList };
+38
View File
@@ -0,0 +1,38 @@
import { extractNewRelease, extractNewlyAdded } from "../extractors/newRelease.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getNewRelease = async (req, res, next) => {
try {
const { page = 1 } = req.query;
const cacheKey = `newrelease_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractNewRelease(page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
const getNewlyAdded = async (req, res, next) => {
try {
const { page = 1 } = req.query;
const cacheKey = `newlyadded_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractNewlyAdded(page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getNewRelease, getNewlyAdded };
+27
View File
@@ -0,0 +1,27 @@
import { extractStatus } from "../extractors/status.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getStatus = async (req, res, next) => {
try {
const { status } = req.params;
const { page = 1 } = req.query;
if (!status) {
return res.status(400).json({ success: false, message: "Status is required (currently-airing, finished-airing, not-yet-aired)" });
}
const cacheKey = `status_${status}_${page}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractStatus(status, page);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getStatus };
@@ -0,0 +1,20 @@
import { extractTrendingSidebar } from "../extractors/trendingSidebar.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getTrendingSidebar = async (req, res, next) => {
try {
const cacheKey = "trendingSidebar";
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractTrendingSidebar();
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getTrendingSidebar };
+26
View File
@@ -0,0 +1,26 @@
import { extractWatchPage } from "../extractors/watchPage.extractor.js";
import { getCache, setCache } from "../helper/cache.helper.js";
const getWatchPage = async (req, res, next) => {
try {
const { slug, ep } = req.query;
if (!slug || !ep) {
return res.status(400).json({ success: false, message: "Slug and episode number are required" });
}
const cacheKey = `watch_${slug}_${ep}`;
const cached = getCache(cacheKey);
if (cached) {
return res.json({ success: true, results: cached });
}
const data = await extractWatchPage(slug, ep);
setCache(cacheKey, data);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getWatchPage };
+47
View File
@@ -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 };
+82
View File
@@ -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 };
+47
View File
@@ -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 };
+126
View File
@@ -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 };
+53
View File
@@ -11,6 +11,11 @@ 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 { getWatchPage } from "../controllers/watchPage.controller.js";
import { getAzList } from "../controllers/azList.controller.js";
import { getNewRelease, getNewlyAdded } from "../controllers/newRelease.controller.js";
import { getStatus } from "../controllers/status.controller.js";
import { getTrendingSidebar } from "../controllers/trendingSidebar.controller.js";
import { categoryRoutes } from "./category.route.js";
const createApiRoutes = (app, jsonResponse, jsonError) => {
@@ -30,6 +35,14 @@ const createApiRoutes = (app, jsonResponse, jsonError) => {
}
});
app.get("/api/watch", async (req, res, next) => {
try {
await getWatchPage(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/search", async (req, res, next) => {
try {
await getSearchResults(req, res, next);
@@ -126,6 +139,46 @@ const createApiRoutes = (app, jsonResponse, jsonError) => {
}
});
app.get("/api/new-release", async (req, res, next) => {
try {
await getNewRelease(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/newly-added", async (req, res, next) => {
try {
await getNewlyAdded(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/trending-sidebar", async (req, res, next) => {
try {
await getTrendingSidebar(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/az-list/:letter", async (req, res, next) => {
try {
await getAzList(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
app.get("/api/status/:status", async (req, res, next) => {
try {
await getStatus(req, res, next);
} catch (error) {
jsonError(res, error.message);
}
});
categoryRoutes(app, jsonResponse, jsonError);
};