From 8abde11e7b09652447938afda936b0fa2bca7c76 Mon Sep 17 00:00:00 2001 From: WBRK-dev Date: Sun, 28 Apr 2024 11:25:12 +0200 Subject: feat: added promotional videos to `/info` endpoint response --- src/parsers/animeAboutInfo.ts | 16 ++++++++++++++++ src/types/anime.ts | 7 +++++++ 2 files changed, 23 insertions(+) (limited to 'src') diff --git a/src/parsers/animeAboutInfo.ts b/src/parsers/animeAboutInfo.ts index 54af57f..7b2e422 100644 --- a/src/parsers/animeAboutInfo.ts +++ b/src/parsers/animeAboutInfo.ts @@ -10,6 +10,8 @@ import axios, { AxiosError } from "axios"; import createHttpError, { type HttpError } from "http-errors"; import { load, type CheerioAPI, type SelectorType } from "cheerio"; import { type ScrapedAnimeAboutInfo } from "../types/parsers/index.js"; +import type { AnimePromotionalVideo } from "../types/anime.js"; +import * as fs from "fs/promises"; // /anime/info?id=${anime-id} async function scrapeAnimeAboutInfo( @@ -34,6 +36,7 @@ async function scrapeAnimeAboutInfo( type: null, duration: null, }, + promotionalVideos: [], }, moreInfo: {}, }, @@ -55,6 +58,8 @@ async function scrapeAnimeAboutInfo( const $: CheerioAPI = load(mainPage.data); + // fs.writeFile("./about.html", mainPage.data); + try { res.anime.info.anilistId = Number( JSON.parse($("body")?.find("#syncData")?.text())?.anilist_id @@ -116,6 +121,17 @@ async function scrapeAnimeAboutInfo( ?.replace(/[\s\n]+/g, " ") ?.split(" ") ?.pop() || null; + + // get promotional videos + $(".block_area.block_area-promotions .block_area-promotions-list .screen-items .item").each( + (_, el) => { + res.anime.info.promotionalVideos.push({ + title: $(el).attr("data-title"), + source: $(el).attr("data-src"), + thumbnail: $(el).find("img").attr("src"), + }); + } + ); // more information $(`${selector} .anisc-info-wrap .anisc-info .item:not(.w-hide)`).each( diff --git a/src/types/anime.ts b/src/types/anime.ts index 9af00bc..cbb80c5 100644 --- a/src/types/anime.ts +++ b/src/types/anime.ts @@ -48,6 +48,7 @@ export interface AnimeGeneralAboutInfo stats: { quality: string | null; } & Pick; + promotionalVideos: AnimePromotionalVideo[]; } export interface RecommendedAnime extends Anime {} @@ -59,6 +60,12 @@ export interface Season extends Pick { title: string | null; } +export interface AnimePromotionalVideo { + title: string | undefined; + source: string | undefined; + thumbnail: string | undefined; +} + export interface AnimeSearchSuggestion extends Omit { moreInfo: Array; -- cgit v1.2.3 From f6261199f8e83fd52714055023d033afbc09e53f Mon Sep 17 00:00:00 2001 From: WBRK-dev Date: Sun, 28 Apr 2024 11:44:26 +0200 Subject: feat: added characters and voice actors to `/info` endpoint response --- src/parsers/animeAboutInfo.ts | 21 +++++++++++++++++++++ src/types/anime.ts | 13 +++++++++++++ 2 files changed, 34 insertions(+) (limited to 'src') diff --git a/src/parsers/animeAboutInfo.ts b/src/parsers/animeAboutInfo.ts index 7b2e422..2467aed 100644 --- a/src/parsers/animeAboutInfo.ts +++ b/src/parsers/animeAboutInfo.ts @@ -37,6 +37,7 @@ async function scrapeAnimeAboutInfo( duration: null, }, promotionalVideos: [], + charactersVoiceActors: [], }, moreInfo: {}, }, @@ -133,6 +134,26 @@ async function scrapeAnimeAboutInfo( } ); + // get characters and voice actors + $(".block_area.block_area-actors .block-actors-content .bac-list-wrap .bac-item").each( + (_, el) => { + res.anime.info.charactersVoiceActors.push({ + character: { + id: $(el).find($(".per-info.ltr .pi-avatar")).attr("href")?.split("/")[2] || "", + poster: $(el).find($(".per-info.ltr .pi-avatar img")).attr("data-src") || "", + name: $(el).find($(".per-info.ltr .pi-detail a")).text(), + cast: $(el).find($(".per-info.ltr .pi-detail .pi-cast")).text(), + }, + voiceActor: { + id: $(el).find($(".per-info.rtl .pi-avatar")).attr("href")?.split("/")[2] || "", + poster: $(el).find($(".per-info.rtl .pi-avatar img")).attr("data-src") || "", + name: $(el).find($(".per-info.rtl .pi-detail a")).text(), + cast: $(el).find($(".per-info.rtl .pi-detail .pi-cast")).text(), + }, + }); + } + ); + // more information $(`${selector} .anisc-info-wrap .anisc-info .item:not(.w-hide)`).each( (i, el) => { diff --git a/src/types/anime.ts b/src/types/anime.ts index cbb80c5..c23acaa 100644 --- a/src/types/anime.ts +++ b/src/types/anime.ts @@ -49,6 +49,7 @@ export interface AnimeGeneralAboutInfo quality: string | null; } & Pick; promotionalVideos: AnimePromotionalVideo[]; + charactersVoiceActors: AnimeCharactersAndVoiceActors[]; } export interface RecommendedAnime extends Anime {} @@ -66,6 +67,18 @@ export interface AnimePromotionalVideo { thumbnail: string | undefined; } +export interface AnimeCharactersAndVoiceActors { + character: AnimeCharacter; + voiceActor: AnimeCharacter; +} + +export interface AnimeCharacter { + id: string; + poster: string; + name: string; + cast: string; +} + export interface AnimeSearchSuggestion extends Omit { moreInfo: Array; -- cgit v1.2.3 From 2f0157ab33b21ff3cac33333d65dd1adcc3308ca Mon Sep 17 00:00:00 2001 From: WBRK-dev Date: Sun, 28 Apr 2024 11:47:44 +0200 Subject: chore: removed unnecessary lines --- src/parsers/animeAboutInfo.ts | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/parsers/animeAboutInfo.ts b/src/parsers/animeAboutInfo.ts index 2467aed..f92b0fc 100644 --- a/src/parsers/animeAboutInfo.ts +++ b/src/parsers/animeAboutInfo.ts @@ -10,8 +10,6 @@ import axios, { AxiosError } from "axios"; import createHttpError, { type HttpError } from "http-errors"; import { load, type CheerioAPI, type SelectorType } from "cheerio"; import { type ScrapedAnimeAboutInfo } from "../types/parsers/index.js"; -import type { AnimePromotionalVideo } from "../types/anime.js"; -import * as fs from "fs/promises"; // /anime/info?id=${anime-id} async function scrapeAnimeAboutInfo( @@ -59,8 +57,6 @@ async function scrapeAnimeAboutInfo( const $: CheerioAPI = load(mainPage.data); - // fs.writeFile("./about.html", mainPage.data); - try { res.anime.info.anilistId = Number( JSON.parse($("body")?.find("#syncData")?.text())?.anilist_id -- cgit v1.2.3