UNPKG

node-csfd-api

Version:

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

1 lines 2.52 kB
{"version":3,"file":"creator.service.cjs","names":["extractId","fetchPage","creatorUrl","getCreatorBirthdayInfo","getCreatorName","getCreatorPhoto","getCreatorBio","getCreatorFilms"],"sources":["../../src/services/creator.service.ts"],"sourcesContent":["import { HTMLElement, parse } from 'node-html-parser';\nimport { CSFDCreator } from '../dto/creator';\nimport { fetchPage } from '../fetchers';\nimport { extractId } from '../helpers/global.helper';\nimport {\n getCreatorBio,\n getCreatorBirthdayInfo,\n getCreatorFilms,\n getCreatorName,\n getCreatorPhoto\n} from '../helpers/creator.helper';\nimport { CSFDOptions } from '../types';\nimport { creatorUrl } from '../vars';\n\nexport class CreatorScraper {\n public async creator(creatorId: number | string, options?: CSFDOptions): Promise<CSFDCreator> {\n const id = extractId(creatorId);\n if (id === null || isNaN(id)) {\n throw new Error('node-csfd-api: creatorId must be a valid number');\n }\n const url = creatorUrl(id, { language: options?.language });\n const response = await fetchPage(url, { ...options?.request });\n\n const creatorHtml = parse(response);\n\n const asideNode = creatorHtml.querySelector('.creator-about');\n const filmsNode = creatorHtml.querySelector('.creator-filmography');\n return this.buildCreator(+creatorId, asideNode, filmsNode);\n }\n\n private buildCreator(id: number, asideEl: HTMLElement, filmsNode: HTMLElement): CSFDCreator {\n const birthdayInfo = getCreatorBirthdayInfo(asideEl);\n return {\n id,\n name: getCreatorName(asideEl),\n birthday: birthdayInfo?.birthday,\n birthplace: birthdayInfo?.birthPlace,\n photo: getCreatorPhoto(asideEl),\n age: birthdayInfo?.age || null,\n bio: getCreatorBio(asideEl),\n films: getCreatorFilms(filmsNode)\n };\n }\n}\n"],"mappings":";;;;;;AAcA,IAAa,iBAAb,MAA4B;CAC1B,MAAa,QAAQ,WAA4B,SAA6C;EAC5F,MAAM,KAAKA,sBAAAA,UAAU,SAAS;EAC9B,IAAI,OAAO,QAAQ,MAAM,EAAE,GACzB,MAAM,IAAI,MAAM,iDAAiD;EAKnE,MAAM,eAAA,GAAA,iBAAA,MAAA,CAAoB,MAFHC,cAAAA,UADXC,aAAAA,WAAW,IAAI,EAAE,UAAU,SAAS,SAAS,CACtB,GAAG,EAAE,GAAG,SAAS,QAAQ,CAAC,CAE3B;EAElC,MAAM,YAAY,YAAY,cAAc,gBAAgB;EAC5D,MAAM,YAAY,YAAY,cAAc,sBAAsB;EAClE,OAAO,KAAK,aAAa,CAAC,WAAW,WAAW,SAAS;CAC3D;CAEA,aAAqB,IAAY,SAAsB,WAAqC;EAC1F,MAAM,eAAeC,uBAAAA,uBAAuB,OAAO;EACnD,OAAO;GACL;GACA,MAAMC,uBAAAA,eAAe,OAAO;GAC5B,UAAU,cAAc;GACxB,YAAY,cAAc;GAC1B,OAAOC,uBAAAA,gBAAgB,OAAO;GAC9B,KAAK,cAAc,OAAO;GAC1B,KAAKC,uBAAAA,cAAc,OAAO;GAC1B,OAAOC,uBAAAA,gBAAgB,SAAS;EAClC;CACF;AACF"}