feat: added promotional videos to /info endpoint response
This commit is contained in:
@@ -326,7 +326,15 @@ console.log(data);
|
|||||||
},
|
},
|
||||||
type: string,
|
type: string,
|
||||||
duration: string
|
duration: string
|
||||||
}
|
},
|
||||||
|
promotionalVideos: [
|
||||||
|
{
|
||||||
|
title: string | undefined,
|
||||||
|
source: string | undefined,
|
||||||
|
thumbnail: string | undefined
|
||||||
|
},
|
||||||
|
{...},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
moreInfo: {
|
moreInfo: {
|
||||||
aired: string,
|
aired: string,
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import axios, { AxiosError } from "axios";
|
|||||||
import createHttpError, { type HttpError } from "http-errors";
|
import createHttpError, { type HttpError } from "http-errors";
|
||||||
import { load, type CheerioAPI, type SelectorType } from "cheerio";
|
import { load, type CheerioAPI, type SelectorType } from "cheerio";
|
||||||
import { type ScrapedAnimeAboutInfo } from "../types/parsers/index.js";
|
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}
|
// /anime/info?id=${anime-id}
|
||||||
async function scrapeAnimeAboutInfo(
|
async function scrapeAnimeAboutInfo(
|
||||||
@@ -34,6 +36,7 @@ async function scrapeAnimeAboutInfo(
|
|||||||
type: null,
|
type: null,
|
||||||
duration: null,
|
duration: null,
|
||||||
},
|
},
|
||||||
|
promotionalVideos: [],
|
||||||
},
|
},
|
||||||
moreInfo: {},
|
moreInfo: {},
|
||||||
},
|
},
|
||||||
@@ -55,6 +58,8 @@ async function scrapeAnimeAboutInfo(
|
|||||||
|
|
||||||
const $: CheerioAPI = load(mainPage.data);
|
const $: CheerioAPI = load(mainPage.data);
|
||||||
|
|
||||||
|
// fs.writeFile("./about.html", mainPage.data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res.anime.info.anilistId = Number(
|
res.anime.info.anilistId = Number(
|
||||||
JSON.parse($("body")?.find("#syncData")?.text())?.anilist_id
|
JSON.parse($("body")?.find("#syncData")?.text())?.anilist_id
|
||||||
@@ -116,6 +121,17 @@ async function scrapeAnimeAboutInfo(
|
|||||||
?.replace(/[\s\n]+/g, " ")
|
?.replace(/[\s\n]+/g, " ")
|
||||||
?.split(" ")
|
?.split(" ")
|
||||||
?.pop() || null;
|
?.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
|
// more information
|
||||||
$(`${selector} .anisc-info-wrap .anisc-info .item:not(.w-hide)`).each(
|
$(`${selector} .anisc-info-wrap .anisc-info .item:not(.w-hide)`).each(
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export interface AnimeGeneralAboutInfo
|
|||||||
stats: {
|
stats: {
|
||||||
quality: string | null;
|
quality: string | null;
|
||||||
} & Pick<Anime, "duration" | "episodes" | "rating" | "type">;
|
} & Pick<Anime, "duration" | "episodes" | "rating" | "type">;
|
||||||
|
promotionalVideos: AnimePromotionalVideo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RecommendedAnime extends Anime {}
|
export interface RecommendedAnime extends Anime {}
|
||||||
@@ -59,6 +60,12 @@ export interface Season extends Pick<Anime, CommonAnimeProps> {
|
|||||||
title: string | null;
|
title: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AnimePromotionalVideo {
|
||||||
|
title: string | undefined;
|
||||||
|
source: string | undefined;
|
||||||
|
thumbnail: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AnimeSearchSuggestion
|
export interface AnimeSearchSuggestion
|
||||||
extends Omit<MostPopularAnime, "episodes" | "type"> {
|
extends Omit<MostPopularAnime, "episodes" | "type"> {
|
||||||
moreInfo: Array<string>;
|
moreInfo: Array<string>;
|
||||||
|
|||||||
Reference in New Issue
Block a user