UNPKG

node-csfd-api

Version:

ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)

35 lines (34 loc) 1.4 kB
import { creatorUrl } from "../vars.js"; import { fetchPage } from "../fetchers/index.js"; import { extractId } from "../helpers/global.helper.js"; import { getCreatorBio, getCreatorBirthdayInfo, getCreatorFilms, getCreatorName, getCreatorPhoto } from "../helpers/creator.helper.js"; import { parse } from "node-html-parser"; //#region src/services/creator.service.ts var CreatorScraper = class { async creator(creatorId, options) { const id = extractId(creatorId); if (id === null || isNaN(id)) throw new Error("node-csfd-api: creatorId must be a valid number"); const url = creatorUrl(id, { language: options?.language }); const response = await fetchPage(url, { ...options?.request }); const creatorHtml = parse(response); const asideNode = creatorHtml.querySelector(".creator-about"); const filmsNode = creatorHtml.querySelector(".creator-filmography"); return this.buildCreator(+creatorId, asideNode, filmsNode); } buildCreator(id, asideEl, filmsNode) { const birthdayInfo = getCreatorBirthdayInfo(asideEl); return { id, name: getCreatorName(asideEl), birthday: birthdayInfo?.birthday, birthplace: birthdayInfo?.birthPlace, photo: getCreatorPhoto(asideEl), age: birthdayInfo?.age || null, bio: getCreatorBio(asideEl), films: getCreatorFilms(filmsNode) }; } }; //#endregion export { CreatorScraper }; //# sourceMappingURL=creator.service.js.map