diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/parsers/estimatedSchedule.ts | 1 | ||||
| -rw-r--r-- | src/parsers/homePage.ts | 43 | ||||
| -rw-r--r-- | src/types/anime.ts | 4 | ||||
| -rw-r--r-- | src/types/parsers/estimatedSchedule.ts | 1 | ||||
| -rw-r--r-- | src/types/parsers/homePage.ts | 6 | ||||
| -rw-r--r-- | src/utils/methods.ts | 16 |
6 files changed, 35 insertions, 36 deletions
diff --git a/src/parsers/estimatedSchedule.ts b/src/parsers/estimatedSchedule.ts index 822102b..abfce97 100644 --- a/src/parsers/estimatedSchedule.ts +++ b/src/parsers/estimatedSchedule.ts @@ -55,6 +55,7 @@ async function scrapeEstimatedSchedule( ?.trim() || null, airingTimestamp, secondsUntilAiring: Math.floor((airingTimestamp - Date.now()) / 1000), + episode: Number($(el).find("a .fd-play button").text().trim().split(" ")[1]) }); }); diff --git a/src/parsers/homePage.ts b/src/parsers/homePage.ts index 979e7e9..cbdaef6 100644 --- a/src/parsers/homePage.ts +++ b/src/parsers/homePage.ts @@ -5,6 +5,7 @@ import { ACCEPT_ENCODING_HEADER, extractTop10Animes, extractAnimes, + extractMostPopularAnimes, } from "../utils/index.js"; import axios, { AxiosError } from "axios"; import createHttpError, { type HttpError } from "http-errors"; @@ -24,6 +25,9 @@ async function scrapeHomePage(): Promise<ScrapedHomePage | HttpError> { month: [], }, topAiringAnimes: [], + mostPopularAnimes: [], + mostFavoriteAnimes: [], + latestCompletedAnimes: [], genres: [], }; @@ -114,11 +118,15 @@ async function scrapeHomePage(): Promise<ScrapedHomePage | HttpError> { rank: parseInt( $(el).find(".item .number")?.children()?.first()?.text()?.trim() ), + id: $(el).find(".item .film-poster")?.attr("href")?.slice(1)?.trim(), name: $(el) .find(".item .number .film-title.dynamic-name") ?.text() ?.trim(), - id: $(el).find(".item .film-poster")?.attr("href")?.slice(1)?.trim(), + jname: $(el) + .find(".item .number .film-title.dynamic-name") + ?.attr("data-jname") + ?.trim(), poster: $(el) .find(".item .film-poster .film-poster-img") ?.attr("data-src") @@ -158,35 +166,10 @@ async function scrapeHomePage(): Promise<ScrapedHomePage | HttpError> { } }); - const topAiringSelector: SelectorType = - "#anime-featured .row div:nth-of-type(1) .anif-block-ul ul li"; - $(topAiringSelector).each((i, el) => { - const otherInfo = $(el) - .find(".fd-infor .fdi-item") - .map((i, el) => $(el).text().trim()) - .get(); - - res.topAiringAnimes.push({ - id: $(el) - .find(".film-detail .film-name .dynamic-name") - ?.attr("href") - ?.slice(1) - ?.trim(), - name: $(el) - .find(".film-detail .film-name .dynamic-name") - ?.attr("title") - ?.trim(), - jname: $(el) - .find(".film-detail .film-name .dynamic-name") - ?.attr("data-jname") - ?.trim(), - poster: $(el) - .find(".film-poster a .film-poster-img") - ?.attr("data-src") - ?.trim(), - otherInfo, - }); - }); + res.topAiringAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(1) .anif-block-ul ul li"); + res.mostPopularAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(2) .anif-block-ul ul li"); + res.mostFavoriteAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(3) .anif-block-ul ul li"); + res.latestCompletedAnimes = extractMostPopularAnimes($, "#anime-featured .row div:nth-of-type(4) .anif-block-ul ul li"); return res; } catch (err: any) { diff --git a/src/types/anime.ts b/src/types/anime.ts index 52bf13a..83a3d1f 100644 --- a/src/types/anime.ts +++ b/src/types/anime.ts @@ -1,6 +1,7 @@ export interface Anime { id: string | null; name: string | null; + jname: string | null; poster: string | null; duration: string | null; type: string | null; @@ -15,6 +16,7 @@ type CommonAnimeProps = "id" | "name" | "poster"; export interface Top10Anime extends Pick<Anime, CommonAnimeProps | "episodes"> { rank: number | null; + jname: string | null; } export type Top10AnimeTimePeriod = "day" | "week" | "month"; @@ -39,6 +41,8 @@ export interface LatestEpisodeAnime extends Anime {} export interface TopUpcomingAnime extends Anime {} export interface TopAiringAnime extends MostPopularAnime {} +export interface MostFavoriteAnime extends MostPopularAnime {} +export interface LatestCompletedAnime extends MostPopularAnime {} export interface AnimeGeneralAboutInfo extends Pick<Anime, CommonAnimeProps>, diff --git a/src/types/parsers/estimatedSchedule.ts b/src/types/parsers/estimatedSchedule.ts index 6207904..881be86 100644 --- a/src/types/parsers/estimatedSchedule.ts +++ b/src/types/parsers/estimatedSchedule.ts @@ -5,6 +5,7 @@ type EstimatedSchedule = { jname: string | null; airingTimestamp: number; secondsUntilAiring: number; + episode: number; }; export type ScrapedEstimatedSchedule = { diff --git a/src/types/parsers/homePage.ts b/src/types/parsers/homePage.ts index 5641a9a..23f6284 100644 --- a/src/types/parsers/homePage.ts +++ b/src/types/parsers/homePage.ts @@ -4,6 +4,9 @@ import type { TopAiringAnime, TopUpcomingAnime, LatestEpisodeAnime, + MostFavoriteAnime, + MostPopularAnime, + LatestCompletedAnime, } from "../anime.js"; import type { HttpError } from "http-errors"; import type { ScrapedAnimeCategory } from "./animeCategory.js"; @@ -15,4 +18,7 @@ export interface ScrapedHomePage latestEpisodeAnimes: Array<LatestEpisodeAnime> | HttpError; topUpcomingAnimes: Array<TopUpcomingAnime> | HttpError; topAiringAnimes: Array<TopAiringAnime> | HttpError; + mostPopularAnimes: Array<MostPopularAnime> | HttpError; + mostFavoriteAnimes: Array<MostFavoriteAnime> | HttpError; + latestCompletedAnimes: Array<LatestCompletedAnime> | HttpError; } diff --git a/src/utils/methods.ts b/src/utils/methods.ts index 1ed0c88..9f57ff9 100644 --- a/src/utils/methods.ts +++ b/src/utils/methods.ts @@ -39,6 +39,10 @@ export const extractAnimes = ( .find(".film-detail .film-name .dynamic-name") ?.text() ?.trim(), + jname: $(el) + .find(".film-detail .film-name .dynamic-name") + ?.attr("data-jname") + ?.trim() || null, poster: $(el) .find(".film-poster .film-poster-img") @@ -102,6 +106,7 @@ export const extractTop10Animes = ( .trim() || null, rank: Number($(el).find(".film-number span")?.text()?.trim()) || null, name: $(el).find(".film-detail .dynamic-name")?.text()?.trim() || null, + jname: $(el).find(".film-detail .dynamic-name")?.attr("data-jname")?.trim() || null, poster: $(el) .find(".film-poster .film-poster-img") @@ -150,17 +155,16 @@ export const extractMostPopularAnimes = ( ?.slice(1) .trim() || null, name: $(el).find(".film-detail .dynamic-name")?.text()?.trim() || null, - poster: - $(el) - .find(".film-poster .film-poster-img") - ?.attr("data-src") - ?.trim() || null, jname: $(el) .find(".film-detail .film-name .dynamic-name") .attr("data-jname") ?.trim() || null, - + poster: + $(el) + .find(".film-poster .film-poster-img") + ?.attr("data-src") + ?.trim() || null, episodes: { sub: Number($(el)?.find(".fd-infor .tick .tick-sub")?.text()?.trim()) || |
