node-csfd-api
Version:
ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)
1 lines • 2.1 kB
Source Map (JSON)
{"version":3,"file":"cinema.service.mjs","names":["cinemas: CSFDCinema[]","cinema: CSFDCinema"],"sources":["../../src/services/cinema.service.ts"],"sourcesContent":["import { HTMLElement, parse } from 'node-html-parser';\nimport { CSFDCinema, CSFDCinemaPeriod } from '../dto/cinema';\nimport { fetchPage } from '../fetchers';\nimport { CSFDOptions } from '../types';\nimport { cinemasUrl } from '../vars';\nimport {\n getCinemaCoords,\n getCinemaId,\n getCinemaUrl,\n getGroupedFilmsByDate,\n parseCinema\n} from './../helpers/cinema.helper';\n\nexport class CinemaScraper {\n public async cinemas(\n district: number = 1,\n period: CSFDCinemaPeriod = 'today',\n options?: CSFDOptions\n ): Promise<CSFDCinema[]> {\n const url = cinemasUrl(district, period, { language: options?.language });\n const response = await fetchPage(url, { ...options?.request });\n const cinemasHtml = parse(response);\n\n const contentNode = cinemasHtml.querySelectorAll('#snippet--cinemas section[id*=\"cinema-\"]');\n\n return this.buildCinemas(contentNode);\n }\n\n private buildCinemas(contentNode: HTMLElement[]): CSFDCinema[] {\n const cinemas: CSFDCinema[] = [];\n\n contentNode.forEach((x) => {\n const cinemaInfo = parseCinema(x);\n const cinema: CSFDCinema = {\n id: getCinemaId(x),\n name: cinemaInfo?.name,\n city: cinemaInfo?.city,\n url: getCinemaUrl(x),\n coords: getCinemaCoords(x),\n screenings: getGroupedFilmsByDate(x)\n };\n cinemas.push(cinema);\n });\n\n return cinemas;\n }\n}\n"],"mappings":";;;;;;AAaA,IAAa,gBAAb,MAA2B;CACzB,MAAa,QACX,WAAmB,GACnB,SAA2B,SAC3B,SACuB;EAKvB,MAAM,cAFc,MADH,MAAM,UADX,WAAW,UAAU,QAAQ,EAAE,UAAU,SAAS,UAAU,CAAC,EACnC,EAAE,GAAG,SAAS,SAAS,CAAC,CAC3B,CAEH,iBAAiB,6CAA2C;AAE5F,SAAO,KAAK,aAAa,YAAY;;CAGvC,AAAQ,aAAa,aAA0C;EAC7D,MAAMA,UAAwB,EAAE;AAEhC,cAAY,SAAS,MAAM;GACzB,MAAM,aAAa,YAAY,EAAE;GACjC,MAAMC,SAAqB;IACzB,IAAI,YAAY,EAAE;IAClB,MAAM,YAAY;IAClB,MAAM,YAAY;IAClB,KAAK,aAAa,EAAE;IACpB,QAAQ,gBAAgB,EAAE;IAC1B,YAAY,sBAAsB,EAAE;IACrC;AACD,WAAQ,KAAK,OAAO;IACpB;AAEF,SAAO"}