UNPKG

kinoklub-api

Version:

Support library for KinoKlub

103 lines (102 loc) 4.82 kB
import { resolveCinema, resolveDate } from './global.helper.js'; export const getId = (el) => { return +el.querySelector('.program__movie-name').attributes['data-projection']; }; export const getTitle = (el) => { return el.querySelector('h3').textContent.trim(); }; export const getInfo = (el) => { var _a, _b, _c, _d, _e; return (_e = (_d = (_c = (_b = (_a = el .querySelector('h6.show-on-mobile')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.replace(/(\r\n|\n|\r|\t)/gm, '')) === null || _c === void 0 ? void 0 : _c.trim()) === null || _d === void 0 ? void 0 : _d.split('/')) === null || _e === void 0 ? void 0 : _e.map((x) => x.trim()); }; export const getDescription = (el) => { const blocks = el.querySelectorAll('.modal-body__mobile-bottom p'); const blocksCleaned = blocks.map((block) => { var _a, _b; return (_b = (_a = block === null || block === void 0 ? void 0 : block.textContent) === null || _a === void 0 ? void 0 : _a.replace(/(\r\n|\n|\r|\t)/gm, '')) === null || _b === void 0 ? void 0 : _b.trim(); }); return blocksCleaned.join('\n'); }; export const getButton = (el, name) => { const buttons = el.querySelectorAll('.modal-body__buttons a'); const separator = name === 'IMDB' ? 'title' : 'film'; const button = buttons.find((x) => x.textContent.trim() === name); if (button) { const link = button.attributes.href; const parts = link.split('/'); const index = parts.findIndex((el) => el === separator); const id = parts[index + 1]; return { id, link }; } else { return { id: null, link: null }; } }; export const getTags = (el) => { return el .querySelectorAll('.modal-body__tags.show-on-mobile span') .map((x) => x.textContent.trim()); }; export const getYoutube = (el) => { var _a; const id = (_a = el.querySelector('#trailer-button')) === null || _a === void 0 ? void 0 : _a.attributes['data-youtube-id']; return id ? 'https://youtu.be/' + id : null; }; export const getImage = (el) => { const id = el.querySelector('.modal-body__image img').attributes.src; return id ? 'https://www.kinoaero.cz' + id : null; }; export const pickInfo = (info, parseString) => { const index = info.findIndex((x) => x.includes(parseString)); const pickedInfo = info[index]; if (index !== -1 && pickedInfo) { return { text: pickedInfo.split(parseString)[1].trim(), index }; } return null; }; export const getTitleOriginal = (info) => { return (pickInfo(info, 'Originální název:') || pickInfo(info, 'Original title:') || { text: null, index: null }); }; export const getDirector = (info) => { return pickInfo(info, 'režie:') || pickInfo(info, 'director:') || { text: null, index: null }; }; export const getLanguage = (info) => { return pickInfo(info, 'znění:') || pickInfo(info, 'language:') || { text: null, index: null }; }; export const getSubtitles = (info) => { return pickInfo(info, 'titulky:') || pickInfo(info, 'subtitles:') || { text: null, index: null }; }; export const getCurrentProjection = (el) => { const element = el.querySelector('.modal-body__projection-row--current'); return parseProjection(element); }; export const removeIndexesFromArray = (arr, indexes) => { const indexSet = new Set(indexes); const arrayWithValuesRemoved = arr.filter((value, i) => !indexSet.has(i)); return arrayWithValuesRemoved; }; const parseProjection = (el) => { var _a, _b, _c, _d, _e, _f, _g; if (el) { const cinemaName = (_a = el.querySelector('.modal-body__projection-cinema span')) === null || _a === void 0 ? void 0 : _a.textContent; const cinema = resolveCinema(cinemaName); const day = (_c = (_b = el .querySelector('.modal-body__projection-day')) === null || _b === void 0 ? void 0 : _b.textContent) === null || _c === void 0 ? void 0 : _c.replace(/(\r\n|\n|\r|\t)/gm, '').trim(); const time = (_e = (_d = el .querySelector('.modal-body__projection-time')) === null || _d === void 0 ? void 0 : _d.textContent) === null || _e === void 0 ? void 0 : _e.replace(/(\r\n|\n|\r|\t)/gm, '').trim(); const date = resolveDate(day, time); const price = (_g = (_f = el .querySelector('.modal-body__projection-price')) === null || _f === void 0 ? void 0 : _f.textContent) === null || _g === void 0 ? void 0 : _g.replace(/(\r\n|\n|\r|\t)/gm, '').trim(); return { cinema, date, price }; } else { return null; } }; export const getProjections = (el) => { const element = el.querySelectorAll('.modal-body__projection-row'); return element.map((el) => parseProjection(el)); };