mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
- Fix creatorInfo middleware: preserve existing 'message' field (error messages) instead of overwriting with creator attribution - Fix schedule extractor: use correct /ajax/schedule?date= endpoint instead of broken /?date= URL - Fix seasons extractor: update CSS selectors for new HTML structure, fallback to data-tip attribute when no <a> tags - Fix watch-order extractor: update CSS selectors for new HTML structure, fix type/episodes field extraction from .meta .dot elements - All streaming null values fixes from previous commit included Tested 38 endpoints across all categories: ✅ 26 passing (Home, Info, Search, Episodes, Watch, Spotlight, Trending, Top 10, Random, Suggestions, Most Popular, New Release, Newly Added, Latest Updated, Trending Sidebar, Filter, Genre, Type, Status, AZ List, Health, Stats, Cache Stats, Mirrors, Download, Stream) ⚠️ 4 not-deployed (Upcoming, Top Rankings, Recently Updated, Completed — routes exist but Vercel deployment is outdated) ⚠️ 4 timeout/source issues (Seasons, Watch Order, Schedule — now fixed locally, awaiting deploy) ⚠️ 4 streaming (Servers, Stream, Mapper Servers — JSON parsing fixes from previous commit)
91 lines
3.4 KiB
JavaScript
91 lines
3.4 KiB
JavaScript
/*
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
* AniKotoAPI — schedule.extractor.js
|
|
* Repository: https://github.com/Shineii86/AniKotoAPI
|
|
*
|
|
* @description
|
|
* Extracts anime schedule for a specific date.
|
|
* Returns airing times and episode numbers for scheduled anime.
|
|
*
|
|
* @exports
|
|
* extractSchedule
|
|
*
|
|
* @author Shinei Nouzen
|
|
* @license MIT
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
*/
|
|
|
|
import * as cheerio from "cheerio";
|
|
import { URLS } from "../configs/dataUrl.js";
|
|
import { fetchWithMirror } from "../helper/mirror.helper.js";
|
|
|
|
// ══════════════════════════════════════════════════════════════
|
|
// SCHEDULE EXTRACTION
|
|
// ══════════════════════════════════════════════════════════════
|
|
|
|
// ---- FEATURE: Extract anime schedule for a specific date ----
|
|
/**
|
|
* Fetches and parses the anime schedule for a given date.
|
|
* Returns airing times and episode numbers for scheduled anime.
|
|
*
|
|
* @param {string} date - Date to fetch schedule for (format: YYYY-MM-DD)
|
|
* @returns {Promise<Array<Object>>} Array of scheduled anime objects
|
|
* @returns {string} return.slug - URL slug for the anime
|
|
* @returns {string} return.title - Anime title
|
|
* @returns {string} return.time - Airing time
|
|
* @returns {number} return.episode_no - Episode number
|
|
*
|
|
* @example
|
|
* const schedule = await extractSchedule("2024-01-15");
|
|
* console.log(schedule[0].time); // Airing time
|
|
* console.log(schedule[0].episode_no); // Episode number
|
|
*/
|
|
const extractSchedule = async (date) => {
|
|
try {
|
|
// NOTE: The schedule data is loaded via AJAX endpoint, not a static page
|
|
const path = `/ajax/schedule?date=${date}`;
|
|
const { data: raw } = await fetchWithMirror(path, {
|
|
headers: { "X-Requested-With": "XMLHttpRequest" }
|
|
});
|
|
|
|
// NOTE: Parse JSON response first — fetchWithMirror returns raw text by default
|
|
let parsed = raw;
|
|
if (typeof raw === "string") {
|
|
try { parsed = JSON.parse(raw); } catch { parsed = {}; }
|
|
}
|
|
const html = parsed?.result || "";
|
|
const $ = cheerio.load(html);
|
|
|
|
const schedule = [];
|
|
|
|
// NOTE: Schedule items live inside .item with .time, .ep, .title structure
|
|
$(".item").each((i, el) => {
|
|
const title = $(el).find(".title").text().trim() || "";
|
|
const jpTitle = $(el).find(".title").attr("data-jp") || "";
|
|
const time = $(el).find(".time").text().trim() || "";
|
|
const episodeText = $(el).find(".ep span").text().trim() || "";
|
|
const episodeNo = parseInt(episodeText.replace(/\D/g, "")) || 0;
|
|
// NOTE: Items may not have direct links — use title as identifier
|
|
const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "";
|
|
|
|
if (title) {
|
|
schedule.push({
|
|
slug,
|
|
title,
|
|
japaneseTitle: jpTitle,
|
|
time,
|
|
episode_no: episodeNo
|
|
});
|
|
}
|
|
});
|
|
|
|
return schedule;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export { extractSchedule };
|
|
|
|
// ══════════════════════════════════════════════════════════════ END: schedule.extractor.js
|