Files
AniKotoAPI/src/extractors/newRelease.extractor.js
T
Shinei Nouzen 7df5bbcc54 docs: Add box-style headers, section headers, feature markers, JSDoc, inline notes, footers
Added comprehensive documentation following project conventions:

Box-style headers (added/fixed where missing):
- All 17 files now have standard Project/Author/License headers

Section headers (// == == SECTION == ==):
- cache.helper.js: LRU CACHE CLASS, TTL CONFIGURATION, SINGLETON, EXPORTED HELPERS
- download.controller.js: DOWNLOAD LINKS HANDLER
- download.extractor.js: BASE64 DECODER, REDIRECT FOLLOWER, DOWNLOAD LINKS EXTRACTOR
- seasons.extractor.js: SEASONS EXTRACTOR
- watchOrder.extractor.js: WATCH ORDER EXTRACTOR
- extractPages.helper.js: PAGE EXTRACTOR
- pagination.helper.js: PAGINATION METADATA

Feature markers (// --- FEATURE: XYZ ---):
- cache.helper.js: LRU Cache, Per-Endpoint TTL, Cache Get/Set/Clear
- download.controller.js: Download Links
- download.extractor.js: Base64 Download Data Decoder, Redirect Chain Resolver, Download Links Extraction
- seasons.extractor.js: Season Information Extraction
- watchOrder.extractor.js: Watch Order / Related Anime Extraction
- streamResolver.extractor.js: Server Name Normalization, Stream URL Resolution, Batch Stream URL Resolution, M3U8 Quality Parser, Subtitle Track Extractor
- mirror.helper.js: Mirror Domain Configuration, Mirror Health Check, Working Mirror Discovery, Mirror Cache Reset, URL Builder, Resilient Fetch with Mirror Fallback, Mirror Status Reporter
- pagination.helper.js: Pagination Metadata Generator
- creatorInfo.js: Creator Attribution Object, Response Creator Injection Middleware

Function-level JSDoc (added/fixed):
- cache.helper.js: Full JSDoc on all 6 class methods (constructor, get, set, delete, clear, getStats, has) and 4 exported helpers

Inline notes for non-obvious logic:
- cache.helper.js: Lazy expiration, LRU re-insertion, singleton pattern
- download.extractor.js: HTML/JSON hybrid response handling, multiple selectors for different mirrors, redirect fallback
- random.extractor.js: maxRedirects, validateStatus, responseURL extraction
- schedule.extractor.js: Dual selector pattern for different mirror layouts
- animeInfo.extractor.js: Positional .bmeta selector fragility
- homeInfo.extractor.js: Dual selector for different layouts
- mirror.helper.js: 404 vs connection error handling
- animeInfo.controller.js: Accept both id and slug params

Footers (added where missing):
- cache.helper.js, download.controller.js, download.extractor.js, seasons.extractor.js, watchOrder.extractor.js, extractPages.helper.js, mirror.helper.js

All 68 source files now have complete documentation coverage (6/6 checks).
2026-07-28 21:55:14 +05:30

136 lines
5.8 KiB
JavaScript

/*
* ======= • ======= • ======= • ======= • =======• =======
* AniKotoAPI — newRelease.extractor.js
* Repository: https://github.com/Shineii86/AniKotoAPI
*
* @description
* Extracts newly released and newly added anime with pagination.
* Provides both new releases and sorted by addition date.
*
* @exports
* extractNewRelease
* extractNewlyAdded
* extractLatestUpdated
*
* @author Shinei Nouzen
* @license MIT
* ======= • ======= • ======= • ======= • =======• =======
*/
import { URLS } from "../configs/dataUrl.js";
import { extractPages } from "../helper/extractPages.helper.js";
import { countPages } from "../helper/countPages.helper.js";
import { parseListItems } from "../helper/parseListItem.helper.js";
// ══════════════════════════════════════════════════════════════
// NEW RELEASE EXTRACTION
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Extract newly released anime with pagination ----
/**
* Fetches and parses newly released anime with pagination.
* Returns paginated results with total page count.
*
* @param {number} page - Page number to fetch (default: 1)
* @returns {Promise<Object>} Object containing totalPages and data array
* @returns {number} return.totalPages - Total number of pages available
* @returns {Array<Object>} return.data - Array of anime objects
* @returns {string} return.data[].slug - URL slug for the anime
* @returns {string} return.data[].poster - Poster image URL
* @returns {string} return.data[].title - English title
* @returns {string} return.data[].japaneseTitle - Japanese title
* @returns {number} return.data[].sub - Subbed episode count
* @returns {number} return.data[].dub - Dubbed episode count
* @returns {number} return.data[].total - Total episode count
* @returns {string} return.data[].type - Anime type (TV, Movie, etc.)
* @returns {string} return.data[].rating - Anime rating
*
* @example
* const newRelease = await extractNewRelease(1);
* console.log(newRelease.totalPages);
* console.log(newRelease.data[0].title);
*/
const extractNewRelease = async (page = 1) => {
try {
const $ = await extractPages(URLS.newRelease, page);
const totalPages = countPages($);
const results = parseListItems($);
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
// ══════════════════════════════════════════════════════════════
// NEWLY ADDED EXTRACTION
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Extract newly added anime sorted by addition date ----
/**
* Fetches and parses newly added anime sorted by addition date.
* Uses the latestUpdated endpoint with sort=added parameter.
*
* @param {number} page - Page number to fetch (default: 1)
* @returns {Promise<Object>} Object containing totalPages and data array
* @returns {number} return.totalPages - Total number of pages available
* @returns {Array<Object>} return.data - Array of anime objects
* @returns {string} return.data[].slug - URL slug for the anime
* @returns {string} return.data[].poster - Poster image URL
* @returns {string} return.data[].title - English title
* @returns {string} return.data[].japaneseTitle - Japanese title
* @returns {number} return.data[].sub - Subbed episode count
* @returns {number} return.data[].dub - Dubbed episode count
* @returns {number} return.data[].total - Total episode count
* @returns {string} return.data[].type - Anime type (TV, Movie, etc.)
*
* @example
* const newlyAdded = await extractNewlyAdded(1);
* console.log(newlyAdded.totalPages);
* console.log(newlyAdded.data[0].title);
*/
const extractNewlyAdded = async (page = 1) => {
try {
const $ = await extractPages(`${URLS.latestUpdated}?sort=added`, page);
const totalPages = countPages($);
const results = parseListItems($);
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
// ══════════════════════════════════════════════════════════════
// LATEST UPDATED EXTRACTION
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Latest Updated Extraction ----
/**
* Fetches and parses recently updated anime with pagination.
* Uses the /latest-updated page which shows anime sorted by last update time.
*
* @param {number} page - Page number to fetch (default: 1)
* @returns {Promise<Object>} Object containing totalPages and data array
*
* @example
* const latest = await extractLatestUpdated(1);
* console.log(latest.totalPages);
* console.log(latest.data[0].title);
*/
const extractLatestUpdated = async (page = 1) => {
try {
const $ = await extractPages("/latest-updated", page);
const totalPages = countPages($);
const results = parseListItems($, ".item");
return { totalPages, data: results };
} catch (error) {
throw error;
}
};
export { extractNewRelease, extractNewlyAdded, extractLatestUpdated };
// ══════════════════════════════════════════════════════════════ END: newRelease.extractor.js