Files
AniKotoAPI/src/extractors/spotlight.extractor.js
T
Shinei Nouzen a8f1917ce7 feat: v2.2.0 — Modularize codebase, unify mirror fallback, harden security
Major Changes:
- Add shared parseListItem.helper.js for unified list parsing (DRY)
- Migrate all 22 extractors to use fetchWithMirror() for consistent mirror fallback
- Remove unused cors dependency (custom CORS middleware handles it)
- Fix middleware ordering: timeout now registered before routes
- Fix CORS to allow POST for /api/mirrors/reset endpoint
- Remove redundant cache check in homeInfo extractor

New Features:
- Request ID tracking (X-Request-Id header) for debugging
- Graceful shutdown handling (SIGTERM/SIGINT) with 10s timeout
- CSP and HSTS security headers
- Rate limiter cleanup interval (every 5 min) to prevent memory leak
- Request body size limits (10kb) via express.json()

Security:
- Content-Security-Policy header for XSS protection
- Strict-Transport-Security for HTTPS enforcement
- X-Permitted-Cross-Domain-Policies: none
- Body size limits to prevent large payload attacks

Code Quality:
- All files follow strict documentation style (box headers, section separators,
  feature markers, JSDoc params/returns, inline notes, module footers)
- Eliminated ~200 lines of duplicated code across 8+ extractors
- Updated CHANGELOG.md with comprehensive change history
2026-07-28 19:28:21 +05:30

92 lines
3.4 KiB
JavaScript

/*
* ======= • ======= • ======= • ======= • =======• =======
* AniKotoAPI — spotlight.extractor.js
* Repository: https://github.com/Shineii86/AniKotoAPI
*
* @description
* Extracts spotlight/featured anime items from the homepage.
* Scrapes the "hottest" carousel section for trending anime.
*
* @exports
* extractSpotlight
*
* @author Shinei Nouzen
* @license MIT
* ======= • ======= • ======= • ======= • =======• =======
*/
import * as cheerio from "cheerio";
import { URLS } from "../configs/dataUrl.js";
import { fetchWithMirror } from "../helper/mirror.helper.js";
// ══════════════════════════════════════════════════════════════
// SPOTLIGHT EXTRACTION
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Extract featured/spotlight anime from homepage ----
/**
* Fetches and parses the spotlight carousel from the homepage.
* Returns an array of featured anime with metadata like poster, title,
* rating, quality, and episode counts.
*
* @returns {Promise<Array<Object>>} Array of spotlight anime objects
* @returns {string} return.slug - URL slug for the anime
* @returns {string} return.poster - Poster image URL
* @returns {string} return.title - English title
* @returns {string} return.japaneseTitle - Japanese title
* @returns {string} return.description - Short description
* @returns {string} return.rating - Anime rating
* @returns {string} return.quality - Video quality (e.g., HD)
* @returns {number} return.sub - Subbed episode count
* @returns {number} return.dub - Dubbed episode count
* @returns {string} return.date - Release date
*
* @example
* const spotlights = await extractSpotlight();
* console.log(spotlights[0].title);
*/
const extractSpotlight = async () => {
try {
const { data } = await fetchWithMirror("/home");
const $ = cheerio.load(data);
const spotlights = [];
$("#hotest .swiper-slide.item").each((i, el) => {
const slug = $(el).find("a.play").attr("href")?.split("/watch/").pop() || "";
const poster = $(el).find(".image div").attr("style")?.match(/url\(['"]?(.+?)['"]?\)/)?.[1] || "";
const title = $(el).find("h2.title.d-title").text().trim() || "";
const japaneseTitle = $(el).find("h2.title.d-title").attr("data-jp") || "";
const description = $(el).find(".desc").text().trim() || "";
const rating = $(el).find("i.rating").text().trim() || "";
const quality = $(el).find("i.quality").text().trim() || "";
const sub = parseInt($(el).find("i.sub").text().trim()) || 0;
const dub = parseInt($(el).find("i.dub").text().trim()) || 0;
const date = $(el).find("i.date").text().trim() || "";
if (slug) {
spotlights.push({
slug,
poster,
title,
japaneseTitle,
description,
rating,
quality,
sub,
dub,
date
});
}
});
return spotlights;
} catch (error) {
throw error;
}
};
export { extractSpotlight };
// ══════════════════════════════════════════════════════════════ END: spotlight.extractor.js