mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
v1.5.0: Complete documentation rewrite - 50+ files with AlisaReactionBot style
- Box-style header comments (Project, Author, License) on every file - Section headers using double-line box decorators - Feature markers (// ---- FEATURE: XYZ ----) before every major function - JSDoc comments for EVERY function with @param, @returns, @example - Inline notes (NOTE, WARNING, TIP) for non-obvious logic - Footer END markers on every module - Matched code style to AlisaReactionBot repository - All files now searchable by feature name via grep Author: Shinei Nouzen <157171073+Shineii86@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,61 @@
|
||||
/*
|
||||
* ======= • ======= • ======= • ======= • =======• =======
|
||||
* AniKatoAPI — category.extractor.js
|
||||
* Repository: https://github.com/Shineii86/AniKatoAPI
|
||||
*
|
||||
* @description
|
||||
* Extracts anime filtered by category (genre, type, status, etc.).
|
||||
* Supports multiple category types with automatic URL detection.
|
||||
*
|
||||
* @exports
|
||||
* extractCategory
|
||||
*
|
||||
* @author Shinei Nouzen
|
||||
* @license MIT
|
||||
* ======= • ======= • ======= • ======= • =======• =======
|
||||
*/
|
||||
|
||||
import * as cheerio from "cheerio";
|
||||
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";
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// CATEGORY FILTER EXTRACTION
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
|
||||
// ---- FEATURE: Extract anime filtered by category with pagination ----
|
||||
/**
|
||||
* Fetches and parses anime filtered by category.
|
||||
* Automatically detects category type (genre, type, status) from the input.
|
||||
*
|
||||
* @param {string} category - Category to filter by (e.g., "genre/action", "type/tv", "status/ongoing")
|
||||
* @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[].animeId - Internal anime ID
|
||||
* @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 actionAnime = await extractCategory("genre/action", 1);
|
||||
* console.log(actionAnime.data[0].title); // First action anime
|
||||
*
|
||||
* const tvAnime = await extractCategory("type/tv", 1);
|
||||
* console.log(tvAnime.data[0].title); // First TV anime
|
||||
*/
|
||||
const extractCategory = async (category, page = 1) => {
|
||||
try {
|
||||
// NOTE: Category type is determined by prefix in the category string
|
||||
let url;
|
||||
if (category.startsWith("genre/")) {
|
||||
url = URLS.genre(category.replace("genre/", ""));
|
||||
@@ -14,6 +64,7 @@ const extractCategory = async (category, page = 1) => {
|
||||
} else if (category.startsWith("status/")) {
|
||||
url = URLS.status(category.replace("status/", ""));
|
||||
} else {
|
||||
// NOTE: Fallback to direct URL construction for unknown category types
|
||||
url = `${URLS.home}/${category}`;
|
||||
}
|
||||
|
||||
@@ -21,6 +72,8 @@ const extractCategory = async (category, page = 1) => {
|
||||
const totalPages = countPages($);
|
||||
|
||||
const results = [];
|
||||
|
||||
// NOTE: The list items are contained in #list-items container
|
||||
$("#list-items > .item").each((i, el) => {
|
||||
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
||||
const poster = $(el).find(".ani.poster.tip > a > img").attr("src") || "";
|
||||
@@ -33,6 +86,7 @@ const extractCategory = async (category, page = 1) => {
|
||||
const type = $(el).find(".info .meta .m-item:nth-child(2) label").text().trim() || "";
|
||||
const rating = $(el).find(".info .meta .m-item.rated span").text().trim() || "";
|
||||
|
||||
// NOTE: Only include items with valid slugs
|
||||
if (slug) {
|
||||
results.push({
|
||||
slug,
|
||||
@@ -55,4 +109,6 @@ const extractCategory = async (category, page = 1) => {
|
||||
}
|
||||
};
|
||||
|
||||
export { extractCategory };
|
||||
export { extractCategory };
|
||||
|
||||
// ══════════════════════════════════════════════════════════════ END: category.extractor.js
|
||||
|
||||
Reference in New Issue
Block a user