From 5d929461ce918006b9c3977e5af5f76799e820b3 Mon Sep 17 00:00:00 2001 From: WBRK-dev Date: Sun, 21 Jul 2024 10:18:05 +0200 Subject: [PATCH] feat: added `mostPopular`, `mostFavorite` and `latestCompleted` to the home route response --- README.md | 41 +++++++++++++++++++++++++++++++++-- src/parsers/homePage.ts | 6 +++++ src/types/anime.ts | 2 ++ src/types/parsers/homePage.ts | 6 +++++ test/homePage.test.ts | 3 +++ 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7ee3b9..e34ad70 100644 --- a/README.md +++ b/README.md @@ -182,9 +182,7 @@ console.log(data); id: string, name: string, poster: string, - duration: string, type: string, - rating: string, episodes: { sub: number, dub: number, @@ -258,6 +256,45 @@ console.log(data); }, {...}, ], + mostPopularAnimes: [ + { + id: string, + name: string, + poster: string, + type: string, + episodes: { + sub: number, + dub: number, + } + }, + {...}, + ], + mostFavoriteAnimes: [ + { + id: string, + name: string, + poster: string, + type: string, + episodes: { + sub: number, + dub: number, + } + }, + {...}, + ], + latestCompletedAnimes: [ + { + id: string, + name: string, + poster: string, + type: string, + episodes: { + sub: number, + dub: number, + } + }, + {...}, + ], } ``` diff --git a/src/parsers/homePage.ts b/src/parsers/homePage.ts index b03b94e..1409a09 100644 --- a/src/parsers/homePage.ts +++ b/src/parsers/homePage.ts @@ -25,6 +25,9 @@ async function scrapeHomePage(): Promise { month: [], }, topAiringAnimes: [], + mostPopularAnimes: [], + mostFavoriteAnimes: [], + latestCompletedAnimes: [], genres: [], }; @@ -160,6 +163,9 @@ async function scrapeHomePage(): Promise { }); 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..0d32382 100644 --- a/src/types/anime.ts +++ b/src/types/anime.ts @@ -39,6 +39,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, 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 | HttpError; topUpcomingAnimes: Array | HttpError; topAiringAnimes: Array | HttpError; + mostPopularAnimes: Array | HttpError; + mostFavoriteAnimes: Array | HttpError; + latestCompletedAnimes: Array | HttpError; } diff --git a/test/homePage.test.ts b/test/homePage.test.ts index 192a060..25b409c 100644 --- a/test/homePage.test.ts +++ b/test/homePage.test.ts @@ -9,6 +9,9 @@ test("returns anime information present in homepage", async () => { expect(data.latestEpisodeAnimes).not.toEqual([]); expect(data.topUpcomingAnimes).not.toEqual([]); expect(data.topAiringAnimes).not.toEqual([]); + expect(data.mostPopularAnimes).not.toEqual([]); + expect(data.mostFavoriteAnimes).not.toEqual([]); + expect(data.latestCompletedAnimes).not.toEqual([]); expect(data.genres).not.toEqual([]); expect(data.top10Animes.today).not.toEqual([]);