UNPKG

kinoklub-api

Version:

Support library for KinoKlub

59 lines (58 loc) 2.81 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { parse } from 'node-html-parser'; import { fetchPage } from '../fetchers/index.js'; import { getButton, getCurrentProjection, getDescription, getDirector, getImage, getInfo, getLanguage, getProjections, getSubtitles, getTags, getTitle, getTitleOriginal, getYoutube, removeIndexesFromArray } from '../helpers/movie.helper.js'; import { movieUrl, ticketsRedirectUrl } from '../vars.js'; import { getTicketParams } from './../helpers/global.helper.js'; export class MovieScraper { movie(screeningId, lang) { return __awaiter(this, void 0, void 0, function* () { const url = movieUrl(screeningId, lang); const response = yield fetchPage(url); const html = parse(response); return this.buildMovie(screeningId, html); }); } buildMovie(id, el) { const infoRaw = getInfo(el); const { text: titleOriginal, index: titleOriginalIndex } = getTitleOriginal(infoRaw); const { text: director, index: directorIndex } = getDirector(infoRaw); const { text: subtitles, index: subtitlesIndex } = getSubtitles(infoRaw); const { text: language, index: languageIndex } = getLanguage(infoRaw); const info = removeIndexesFromArray(infoRaw, [ titleOriginalIndex, directorIndex, subtitlesIndex, languageIndex ]); const ticketParams = getTicketParams(el); const queryParams = new URLSearchParams(ticketParams).toString(); return { id, title: getTitle(el), titleOriginal, ticketUrl: queryParams ? ticketsRedirectUrl + '?' + queryParams : null, infoRaw, info, description: getDescription(el), director, subtitles, language, tags: getTags(el), csfd: getButton(el, 'ČSFD'), imdb: getButton(el, 'IMDB'), youtube: getYoutube(el), image: getImage(el), projection: getCurrentProjection(el), projectionsOther: getProjections(el) }; } }