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,14 +1,57 @@
|
||||
/*
|
||||
* ======= • ======= • ======= • ======= • =======• =======
|
||||
* AniKatoAPI — trending.extractor.js
|
||||
* Repository: https://github.com/Shineii86/AniKatoAPI
|
||||
*
|
||||
* @description
|
||||
* Extracts trending and recently updated anime from the homepage.
|
||||
* Scrapes both the updated section and recent updates section.
|
||||
*
|
||||
* @exports
|
||||
* extractTrending
|
||||
*
|
||||
* @author Shinei Nouzen
|
||||
* @license MIT
|
||||
* ======= • ======= • ======= • ======= • =======• =======
|
||||
*/
|
||||
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// TRENDING EXTRACTION
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
|
||||
// ---- FEATURE: Extract trending and recently updated anime ----
|
||||
/**
|
||||
* Fetches and parses trending anime from the homepage.
|
||||
* Combines results from both the updated section and recent updates section.
|
||||
*
|
||||
* @returns {Promise<Array<Object>>} Array of trending 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 {number} return.sub - Subbed episode count
|
||||
* @returns {number} return.dub - Dubbed episode count
|
||||
* @returns {number} return.total - Total episode count
|
||||
* @returns {string} return.type - Anime type (TV, Movie, etc.)
|
||||
*
|
||||
* @example
|
||||
* const trending = await extractTrending();
|
||||
* console.log(trending[0].title);
|
||||
*/
|
||||
const extractTrending = async () => {
|
||||
try {
|
||||
// NOTE: Trending data is split across multiple sections on the homepage
|
||||
const { data } = await axios.get(URLS.home, { headers });
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const trending = [];
|
||||
|
||||
// NOTE: This selector targets both the updated section and recent updates
|
||||
$(".section-updated .item, #recent-update .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") || "";
|
||||
@@ -19,6 +62,7 @@ const extractTrending = async () => {
|
||||
const total = parseInt($(el).find(".ep-status.total span").text().trim()) || 0;
|
||||
const type = $(el).find(".meta .inner .right").text().trim() || "";
|
||||
|
||||
// NOTE: Only include items with valid slugs
|
||||
if (slug) {
|
||||
trending.push({
|
||||
slug,
|
||||
@@ -39,4 +83,6 @@ const extractTrending = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
export { extractTrending };
|
||||
export { extractTrending };
|
||||
|
||||
// ══════════════════════════════════════════════════════════════ END: trending.extractor.js
|
||||
|
||||
Reference in New Issue
Block a user