node-csfd-api 3.0.0-next.20 → 3.0.0-next.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +41 -3
  2. package/{cjs/fetchers → fetchers}/index.js +4 -13
  3. package/{cjs/helpers → helpers}/cinema.helper.js +18 -7
  4. package/{cjs/helpers → helpers}/creator.helper.js +12 -11
  5. package/{types/helpers → helpers}/search.helper.d.ts +1 -1
  6. package/{cjs/helpers → helpers}/search.helper.js +5 -3
  7. package/{cjs/helpers → helpers}/user-ratings.helper.js +2 -1
  8. package/index.js +39 -0
  9. package/package.json +10 -12
  10. package/services/cinema.service.js +34 -0
  11. package/services/creator.service.js +32 -0
  12. package/{cjs/services → services}/movie.service.js +10 -21
  13. package/{cjs/services → services}/search.service.js +8 -19
  14. package/{cjs/services → services}/user-ratings.service.js +25 -36
  15. package/cjs/index.js +0 -58
  16. package/cjs/services/cinema.service.js +0 -45
  17. package/cjs/services/creator.service.js +0 -43
  18. package/esm/fetchers/fetch.polyfill.js +0 -6
  19. package/esm/fetchers/index.js +0 -32
  20. package/esm/helpers/cinema.helper.js +0 -81
  21. package/esm/helpers/creator.helper.js +0 -73
  22. package/esm/helpers/global.helper.js +0 -59
  23. package/esm/helpers/movie.helper.js +0 -228
  24. package/esm/helpers/search-user.helper.js +0 -15
  25. package/esm/helpers/search.helper.js +0 -49
  26. package/esm/helpers/user-ratings.helper.js +0 -47
  27. package/esm/index.js +0 -54
  28. package/esm/interfaces/cinema.interface.js +0 -1
  29. package/esm/interfaces/creator.interface.js +0 -1
  30. package/esm/interfaces/global.js +0 -1
  31. package/esm/interfaces/movie.interface.js +0 -1
  32. package/esm/interfaces/search.interface.js +0 -1
  33. package/esm/interfaces/user-ratings.interface.js +0 -1
  34. package/esm/services/cinema.service.js +0 -41
  35. package/esm/services/creator.service.js +0 -39
  36. package/esm/services/movie.service.js +0 -65
  37. package/esm/services/search.service.js +0 -87
  38. package/esm/services/user-ratings.service.js +0 -91
  39. package/esm/vars.js +0 -7
  40. package/types/index.ts +0 -26
  41. /package/{types/fetchers → fetchers}/fetch.polyfill.d.ts +0 -0
  42. /package/{cjs/fetchers → fetchers}/fetch.polyfill.js +0 -0
  43. /package/{types/fetchers → fetchers}/index.d.ts +0 -0
  44. /package/{types/helpers → helpers}/cinema.helper.d.ts +0 -0
  45. /package/{types/helpers → helpers}/creator.helper.d.ts +0 -0
  46. /package/{types/helpers → helpers}/global.helper.d.ts +0 -0
  47. /package/{cjs/helpers → helpers}/global.helper.js +0 -0
  48. /package/{types/helpers → helpers}/movie.helper.d.ts +0 -0
  49. /package/{cjs/helpers → helpers}/movie.helper.js +0 -0
  50. /package/{types/helpers → helpers}/search-user.helper.d.ts +0 -0
  51. /package/{cjs/helpers → helpers}/search-user.helper.js +0 -0
  52. /package/{types/helpers → helpers}/user-ratings.helper.d.ts +0 -0
  53. /package/{types/index.d.ts → index.d.ts} +0 -0
  54. /package/{types/interfaces → interfaces}/cinema.interface.d.ts +0 -0
  55. /package/{cjs/interfaces → interfaces}/cinema.interface.js +0 -0
  56. /package/{types/interfaces → interfaces}/creator.interface.d.ts +0 -0
  57. /package/{cjs/interfaces → interfaces}/creator.interface.js +0 -0
  58. /package/{types/interfaces → interfaces}/global.d.ts +0 -0
  59. /package/{cjs/interfaces → interfaces}/global.js +0 -0
  60. /package/{types/interfaces → interfaces}/movie.interface.d.ts +0 -0
  61. /package/{cjs/interfaces → interfaces}/movie.interface.js +0 -0
  62. /package/{types/interfaces → interfaces}/search.interface.d.ts +0 -0
  63. /package/{cjs/interfaces → interfaces}/search.interface.js +0 -0
  64. /package/{types/interfaces → interfaces}/user-ratings.interface.d.ts +0 -0
  65. /package/{cjs/interfaces → interfaces}/user-ratings.interface.js +0 -0
  66. /package/{types/services → services}/cinema.service.d.ts +0 -0
  67. /package/{types/services → services}/creator.service.d.ts +0 -0
  68. /package/{types/services → services}/movie.service.d.ts +0 -0
  69. /package/{types/services → services}/search.service.d.ts +0 -0
  70. /package/{types/services → services}/user-ratings.service.d.ts +0 -0
  71. /package/{types/vars.d.ts → vars.d.ts} +0 -0
  72. /package/{cjs/vars.js → vars.js} +0 -0
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CinemaScraper = void 0;
13
- const node_html_parser_1 = require("node-html-parser");
14
- const fetchers_1 = require("../fetchers");
15
- const vars_1 = require("../vars");
16
- const cinema_helper_1 = require("./../helpers/cinema.helper");
17
- class CinemaScraper {
18
- cinemas(district = 1, period = 'today') {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const url = (0, vars_1.cinemasUrl)(district, period);
21
- const response = yield (0, fetchers_1.fetchPage)(url);
22
- const cinemasHtml = (0, node_html_parser_1.parse)(response);
23
- const contentNode = cinemasHtml.querySelectorAll('#snippet--cinemas section.box');
24
- this.buildCinemas(contentNode);
25
- return this.cinema;
26
- });
27
- }
28
- buildCinemas(contentNode) {
29
- const cinemas = [];
30
- contentNode.map((x) => {
31
- var _a, _b;
32
- const cinema = {
33
- id: (0, cinema_helper_1.getCinemaId)(x),
34
- name: (_a = (0, cinema_helper_1.parseCinema)(x)) === null || _a === void 0 ? void 0 : _a.name,
35
- city: (_b = (0, cinema_helper_1.parseCinema)(x)) === null || _b === void 0 ? void 0 : _b.city,
36
- url: (0, cinema_helper_1.getCinemaUrl)(x),
37
- coords: (0, cinema_helper_1.getCoords)(x),
38
- screenings: (0, cinema_helper_1.getGroupedFilmsByDate)(x)
39
- };
40
- cinemas.push(cinema);
41
- });
42
- this.cinema = cinemas;
43
- }
44
- }
45
- exports.CinemaScraper = CinemaScraper;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CreatorScraper = void 0;
13
- const node_html_parser_1 = require("node-html-parser");
14
- const fetchers_1 = require("../fetchers");
15
- const creator_helper_1 = require("../helpers/creator.helper");
16
- const vars_1 = require("../vars");
17
- class CreatorScraper {
18
- creator(creatorId) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const url = (0, vars_1.creatorUrl)(+creatorId);
21
- const response = yield (0, fetchers_1.fetchPage)(url);
22
- const creatorHtml = (0, node_html_parser_1.parse)(response);
23
- const asideNode = creatorHtml.querySelector('.creator-about');
24
- const filmsNode = creatorHtml.querySelector('.creator-filmography');
25
- this.buildCreator(+creatorId, asideNode, filmsNode);
26
- return this.person;
27
- });
28
- }
29
- buildCreator(id, asideEl, filmsNode) {
30
- var _a, _b, _c;
31
- this.person = {
32
- id,
33
- name: (0, creator_helper_1.getName)(asideEl),
34
- birthday: (_a = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _a === void 0 ? void 0 : _a.birthday,
35
- birthplace: (_b = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _b === void 0 ? void 0 : _b.birthPlace,
36
- photo: (0, creator_helper_1.getPhoto)(asideEl),
37
- age: ((_c = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _c === void 0 ? void 0 : _c.age) || null,
38
- bio: (0, creator_helper_1.getBio)(asideEl),
39
- films: (0, creator_helper_1.getFilms)(filmsNode)
40
- };
41
- }
42
- }
43
- exports.CreatorScraper = CreatorScraper;
@@ -1,6 +0,0 @@
1
- // Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
2
- import { fetch as crossFetch } from 'cross-fetch';
3
- export const fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
4
- (typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
5
- (typeof window !== 'undefined' && window.fetch) || // Browser fetch
6
- crossFetch; // Polyfill fetch
@@ -1,32 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { fetchSafe } from './fetch.polyfill';
11
- const USER_AGENTS = [
12
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
13
- 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
14
- 'Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36',
15
- 'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36'
16
- ];
17
- const headers = {
18
- 'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
19
- };
20
- export const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
21
- try {
22
- const response = yield fetchSafe(url, { headers });
23
- if (response.status >= 400 && response.status < 600) {
24
- throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
25
- }
26
- return yield response.text();
27
- }
28
- catch (e) {
29
- console.error(e);
30
- return 'Error';
31
- }
32
- });
@@ -1,81 +0,0 @@
1
- import { parseColor, parseIdFromUrl } from './global.helper';
2
- export const getColorRating = (el) => {
3
- return parseColor(el === null || el === void 0 ? void 0 : el.classNames.split(' ').pop());
4
- };
5
- export const getCinemaId = (el) => {
6
- var _a;
7
- const id = (_a = el === null || el === void 0 ? void 0 : el.id) === null || _a === void 0 ? void 0 : _a.split('-')[1];
8
- return +id;
9
- };
10
- export const getId = (url) => {
11
- if (url) {
12
- return parseIdFromUrl(url);
13
- }
14
- return null;
15
- };
16
- export const getName = (el) => {
17
- return el.querySelector('h1').innerText.trim();
18
- };
19
- export const getCoords = (el) => {
20
- const link = el === null || el === void 0 ? void 0 : el.querySelector('.box-header img[alt="Google Maps"]').closest('a').getAttribute('href');
21
- const coords = link.split('q=')[1].split(',');
22
- const [lat, lng] = coords;
23
- return { lat: +lat, lng: +lng };
24
- };
25
- export const getCinemaUrl = (el) => {
26
- var _a;
27
- return (_a = el.querySelector('.box-header .cinema-logo a')) === null || _a === void 0 ? void 0 : _a.attributes.href;
28
- };
29
- export const parseCinema = (el) => {
30
- const title = el.querySelector('.box-header h2').innerText.trim();
31
- const [city, name] = title.split(' - ');
32
- return { city, name };
33
- };
34
- export const getGroupedFilmsByDate = (el) => {
35
- const divs = el.querySelectorAll(':scope > div');
36
- const getDatesAndFilms = divs
37
- .map((_, index) => index)
38
- .filter((index) => index % 2 === 0)
39
- .map((index) => {
40
- const [date, films] = divs.slice(index, index + 2);
41
- const dateText = date === null || date === void 0 ? void 0 : date.innerText.trim();
42
- return { date: dateText, films: getFilms('', films) };
43
- });
44
- return getDatesAndFilms;
45
- };
46
- export const getFilms = (date, el) => {
47
- const filmNodes = el.querySelectorAll('.cinema-table tr');
48
- const films = filmNodes.map((filmNode) => {
49
- var _a, _b, _c, _d;
50
- const url = (_a = filmNode.querySelector('td.name h3 a')) === null || _a === void 0 ? void 0 : _a.attributes.href;
51
- const id = getId(url);
52
- const title = (_b = filmNode.querySelector('.name h3')) === null || _b === void 0 ? void 0 : _b.text.trim();
53
- const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
54
- const showTimes = (_c = filmNode.querySelectorAll('.td-time')) === null || _c === void 0 ? void 0 : _c.map((x) => x.textContent.trim());
55
- const meta = (_d = filmNode.querySelectorAll('.td-title span')) === null || _d === void 0 ? void 0 : _d.map((x) => x.text.trim());
56
- return {
57
- id,
58
- title,
59
- url,
60
- colorRating,
61
- showTimes,
62
- meta: parseMeta(meta)
63
- };
64
- });
65
- return films;
66
- };
67
- export const parseMeta = (meta) => {
68
- const metaConvert = [];
69
- for (const element of meta) {
70
- if (element === 'T') {
71
- metaConvert.push('subtitles');
72
- }
73
- else if (element === 'D') {
74
- metaConvert.push('dubbing');
75
- }
76
- else {
77
- metaConvert.push(element);
78
- }
79
- }
80
- return metaConvert;
81
- };
@@ -1,73 +0,0 @@
1
- import { addProtocol, parseColor, parseIdFromUrl } from './global.helper';
2
- export const getColorRating = (el) => {
3
- return parseColor(el === null || el === void 0 ? void 0 : el.classNames.split(' ').pop());
4
- };
5
- export const getId = (url) => {
6
- if (url) {
7
- return parseIdFromUrl(url);
8
- }
9
- return null;
10
- };
11
- export const getName = (el) => {
12
- return el.querySelector('h1').innerText.trim();
13
- };
14
- export const getBirthdayInfo = (el) => {
15
- const text = el.querySelector('h1 + p').innerHTML.trim();
16
- const parts = text.split('\n');
17
- let birthday;
18
- let age;
19
- let birthPlace;
20
- if (parts.length) {
21
- const birthdayRow = parts.find((x) => x.includes('nar.'));
22
- const ageRow = parts.find((x) => x.includes('let)'));
23
- const birthPlaceRow = parts.find((x) => x.includes('<br>')); // Ugly but there is no other way to detect
24
- birthday = birthdayRow ? parseBirthday(birthdayRow) : '';
25
- age = ageRow ? +parseAge(ageRow) : null;
26
- birthPlace = birthPlaceRow ? parseBirthPlace(birthPlaceRow) : '';
27
- }
28
- return { birthday, age, birthPlace };
29
- };
30
- export const getBio = (el) => {
31
- return el.querySelector('.article-content p').text.trim().split('\n')[0].trim();
32
- };
33
- export const getPhoto = (el) => {
34
- const image = el.querySelector('img').attributes.src;
35
- return addProtocol(image);
36
- };
37
- export const parseBirthday = (text) => {
38
- return text.replace(/nar./g, '').trim();
39
- };
40
- export const parseAge = (text) => {
41
- return text.trim().replace(/\(/g, '').replace(/let\)/g, '').trim();
42
- };
43
- export const parseBirthPlace = (text) => {
44
- return text.trim().replace(/<br>/g, '').trim();
45
- };
46
- export const getFilms = (el) => {
47
- var _a;
48
- const filmNodes = (_a = el.querySelectorAll('.box')[0]) === null || _a === void 0 ? void 0 : _a.querySelectorAll('table tr');
49
- let yearCache;
50
- const films = filmNodes.map((filmNode) => {
51
- var _a, _b, _c;
52
- const id = getId((_a = filmNode.querySelector('td.name .film-title-name')) === null || _a === void 0 ? void 0 : _a.attributes.href);
53
- const title = (_b = filmNode.querySelector('.name')) === null || _b === void 0 ? void 0 : _b.text.trim();
54
- const year = +((_c = filmNode.querySelector('.year')) === null || _c === void 0 ? void 0 : _c.text.trim());
55
- const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
56
- // Cache year from previous film because there is a gap between movies with same year
57
- if (year) {
58
- yearCache = +year;
59
- }
60
- if (id && title) {
61
- return {
62
- id,
63
- title,
64
- year: year || yearCache,
65
- colorRating
66
- };
67
- }
68
- return {};
69
- });
70
- // Remove empty objects
71
- const filmsUnique = films.filter((value) => Object.keys(value).length !== 0);
72
- return filmsUnique;
73
- };
@@ -1,59 +0,0 @@
1
- export const parseIdFromUrl = (url) => {
2
- if (url) {
3
- const idSlug = url === null || url === void 0 ? void 0 : url.split('/')[2];
4
- const id = idSlug === null || idSlug === void 0 ? void 0 : idSlug.split('-')[0];
5
- return +id || null;
6
- }
7
- else {
8
- return null;
9
- }
10
- };
11
- export const getColor = (cls) => {
12
- switch (cls) {
13
- case 'page-lightgrey':
14
- return 'unknown';
15
- case 'page-red':
16
- return 'good';
17
- case 'page-blue':
18
- return 'average';
19
- case 'page-grey':
20
- return 'bad';
21
- default:
22
- return 'unknown';
23
- }
24
- };
25
- export const parseColor = (quality) => {
26
- switch (quality) {
27
- case 'lightgrey':
28
- return 'unknown';
29
- case 'red':
30
- return 'good';
31
- case 'blue':
32
- return 'average';
33
- case 'grey':
34
- return 'bad';
35
- default:
36
- return 'unknown';
37
- }
38
- };
39
- export const addProtocol = (url) => {
40
- return url.startsWith('//') ? 'https:' + url : url;
41
- };
42
- export const getDuration = (matches) => {
43
- return {
44
- sign: matches[1] === undefined ? '+' : '-',
45
- years: matches[2] === undefined ? 0 : matches[2],
46
- months: matches[3] === undefined ? 0 : matches[3],
47
- weeks: matches[4] === undefined ? 0 : matches[4],
48
- days: matches[5] === undefined ? 0 : matches[5],
49
- hours: matches[6] === undefined ? 0 : matches[6],
50
- minutes: matches[7] === undefined ? 0 : matches[7],
51
- seconds: matches[8] === undefined ? 0 : matches[8]
52
- };
53
- };
54
- export const parseISO8601Duration = (iso) => {
55
- const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
56
- const matches = iso.match(iso8601DurationRegex);
57
- const duration = getDuration(matches);
58
- return +duration.minutes;
59
- };
@@ -1,228 +0,0 @@
1
- import { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl } from './global.helper';
2
- export const getId = (el) => {
3
- const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;
4
- return parseIdFromUrl(url);
5
- };
6
- export const getTitle = (el) => {
7
- return el.querySelector('h1').innerText.split(`(`)[0].trim();
8
- };
9
- export const getGenres = (el) => {
10
- const genresRaw = el.querySelector('.genres').textContent;
11
- return genresRaw.split(' / ');
12
- };
13
- export const getOrigins = (el) => {
14
- const originsRaw = el.querySelector('.origin').textContent;
15
- const origins = originsRaw.split(',')[0];
16
- return origins.split(' / ');
17
- };
18
- export const getColorRating = (bodyClasses) => {
19
- return getColor(bodyClasses[1]);
20
- };
21
- export const getRating = (el) => {
22
- const ratingRaw = el.querySelector('.film-rating-average').textContent;
23
- const rating = ratingRaw === null || ratingRaw === void 0 ? void 0 : ratingRaw.replace(/%/g, '').trim();
24
- const ratingInt = parseInt(rating);
25
- if (Number.isInteger(ratingInt)) {
26
- return ratingInt;
27
- }
28
- else {
29
- return null;
30
- }
31
- };
32
- export const getRatingCount = (el) => {
33
- var _a;
34
- const ratingCountRaw = (_a = el.querySelector('.box-rating-container .counter')) === null || _a === void 0 ? void 0 : _a.textContent;
35
- const ratingCount = +(ratingCountRaw === null || ratingCountRaw === void 0 ? void 0 : ratingCountRaw.replace(/[(\s)]/g, ''));
36
- if (Number.isInteger(ratingCount)) {
37
- return ratingCount;
38
- }
39
- else {
40
- return null;
41
- }
42
- };
43
- export const getYear = (el) => {
44
- try {
45
- const jsonLd = JSON.parse(el);
46
- return +jsonLd.dateCreated;
47
- }
48
- catch (error) {
49
- console.error('node-csfd-api: Error parsing JSON-LD', error);
50
- return null;
51
- }
52
- };
53
- export const getDuration = (jsonLdRaw, el) => {
54
- let duration = null;
55
- try {
56
- const jsonLd = JSON.parse(jsonLdRaw);
57
- duration = jsonLd.duration;
58
- return parseISO8601Duration(duration);
59
- }
60
- catch (error) {
61
- const origin = el.querySelector('.origin').innerText;
62
- const timeString = origin.split(',');
63
- if (timeString.length > 2) {
64
- // Get last time elelment
65
- const timeString2 = timeString.pop().trim();
66
- // Clean it
67
- const timeRaw = timeString2.split('(')[0].trim();
68
- // Split by minutes and hours
69
- const hoursMinsRaw = timeRaw.split('min')[0];
70
- const hoursMins = hoursMinsRaw.split('h');
71
- // Resolve hours + minutes format
72
- duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];
73
- return duration;
74
- }
75
- else {
76
- return null;
77
- }
78
- }
79
- };
80
- export const getTitlesOther = (el) => {
81
- const namesNode = el.querySelectorAll('.film-names li');
82
- if (!namesNode.length) {
83
- return [];
84
- }
85
- const titlesOther = namesNode.map((el) => {
86
- const country = el.querySelector('img.flag').attributes.alt;
87
- const title = el.textContent.trim().split('\n')[0];
88
- if (country && title) {
89
- return {
90
- country,
91
- title
92
- };
93
- }
94
- else {
95
- return null;
96
- }
97
- });
98
- return titlesOther.filter((x) => x);
99
- };
100
- export const getPoster = (el) => {
101
- var _a;
102
- const poster = el.querySelector('.film-posters img');
103
- // Resolve empty image
104
- if (poster) {
105
- if ((_a = poster.classNames) === null || _a === void 0 ? void 0 : _a.includes('empty-image')) {
106
- return null;
107
- }
108
- else {
109
- // Full sized image (not thumb)
110
- const imageThumb = poster.attributes.src.split('?')[0];
111
- const image = imageThumb.replace(/\/w140\//, '/w1080/');
112
- return addProtocol(image);
113
- }
114
- }
115
- else {
116
- return null;
117
- }
118
- };
119
- export const getRandomPhoto = (el) => {
120
- var _a;
121
- const imageNode = el.querySelector('.gallery-item picture img');
122
- const image = (_a = imageNode === null || imageNode === void 0 ? void 0 : imageNode.attributes) === null || _a === void 0 ? void 0 : _a.src;
123
- if (image) {
124
- return image.replace(/\/w663\//, '/w1326/');
125
- }
126
- else {
127
- return null;
128
- }
129
- };
130
- export const getTrivia = (el) => {
131
- const triviaNodes = el.querySelectorAll('.article-trivia ul li');
132
- if (triviaNodes === null || triviaNodes === void 0 ? void 0 : triviaNodes.length) {
133
- return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
134
- }
135
- else {
136
- return null;
137
- }
138
- };
139
- export const getDescriptions = (el) => {
140
- return el
141
- .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
142
- .map((movie) => { var _a; return (_a = movie.textContent) === null || _a === void 0 ? void 0 : _a.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); });
143
- };
144
- export const parsePeople = (el) => {
145
- const people = el.querySelectorAll('a');
146
- return (people
147
- // Filter out "more" links
148
- .filter((x) => x.classNames.length === 0)
149
- .map((person) => {
150
- return {
151
- id: parseIdFromUrl(person.attributes.href),
152
- name: person.innerText.trim(),
153
- url: `https://www.csfd.cz${person.attributes.href}`
154
- };
155
- }));
156
- };
157
- export const getGroup = (el, group) => {
158
- const creators = el.querySelectorAll('.creators h4');
159
- const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];
160
- if (element === null || element === void 0 ? void 0 : element.parentNode) {
161
- return parsePeople(element.parentNode);
162
- }
163
- else {
164
- return [];
165
- }
166
- };
167
- export const getType = (el) => {
168
- var _a;
169
- const type = el.querySelector('.film-header-name .type');
170
- return ((_a = type === null || type === void 0 ? void 0 : type.innerText) === null || _a === void 0 ? void 0 : _a.replace(/[{()}]/g, '')) || 'film';
171
- };
172
- export const getVods = (el) => {
173
- let vods = [];
174
- if (el) {
175
- const buttons = el.querySelectorAll('.box-buttons .button');
176
- const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));
177
- vods = buttonsVod.map((btn) => {
178
- return {
179
- title: btn.textContent.trim(),
180
- url: btn.attributes.href
181
- };
182
- });
183
- }
184
- return vods.length ? vods : [];
185
- };
186
- // Get box content
187
- export const getBoxContent = (el, box) => {
188
- var _a;
189
- const headers = el.querySelectorAll('section.box .box-header');
190
- return (_a = headers.find((header) => header.querySelector('h3').textContent.trim().includes(box))) === null || _a === void 0 ? void 0 : _a.parentNode;
191
- };
192
- export const getBoxMovies = (el, boxName) => {
193
- const movieListItem = [];
194
- const box = getBoxContent(el, boxName);
195
- const movieTitleNodes = box === null || box === void 0 ? void 0 : box.querySelectorAll('.article-header .film-title-name');
196
- if (movieTitleNodes === null || movieTitleNodes === void 0 ? void 0 : movieTitleNodes.length) {
197
- for (const item of movieTitleNodes) {
198
- movieListItem.push({
199
- id: parseIdFromUrl(item.attributes.href),
200
- title: item.textContent.trim(),
201
- url: `https://www.csfd.cz${item.attributes.href}`
202
- });
203
- }
204
- }
205
- return movieListItem;
206
- };
207
- export const getPremieres = (el) => {
208
- var _a, _b;
209
- const premiereNodes = el.querySelectorAll('.box-premieres li');
210
- const premiere = [];
211
- for (const premiereNode of premiereNodes) {
212
- const title = premiereNode.querySelector('p + span').attributes.title;
213
- if (title) {
214
- const [date, ...company] = title === null || title === void 0 ? void 0 : title.split(' ');
215
- premiere.push({
216
- country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
217
- format: (_b = premiereNode.querySelector('p').textContent.trim()) === null || _b === void 0 ? void 0 : _b.split(' od')[0],
218
- date,
219
- company: company.join(' ')
220
- });
221
- }
222
- }
223
- return premiere;
224
- };
225
- export const getTags = (el) => {
226
- const tagsRaw = el.querySelectorAll('.box-content a[href*="/podrobne-vyhledavani/?tag="]');
227
- return tagsRaw.map((tag) => tag.textContent);
228
- };
@@ -1,15 +0,0 @@
1
- import { addProtocol } from './global.helper';
2
- export const getUser = (el) => {
3
- return el.querySelector('.user-title-name').text;
4
- };
5
- export const getUserRealName = (el) => {
6
- var _a;
7
- return ((_a = el.querySelector('.user-real-name')) === null || _a === void 0 ? void 0 : _a.text.trim()) || null;
8
- };
9
- export const getAvatar = (el) => {
10
- const image = el.querySelector('.article-img img').attributes.src;
11
- return addProtocol(image);
12
- };
13
- export const getUserUrl = (el) => {
14
- return el.querySelector('.user-title-name').attributes.href;
15
- };
@@ -1,49 +0,0 @@
1
- import { addProtocol, parseColor, parseIdFromUrl } from './global.helper';
2
- export const getType = (el) => {
3
- const type = el.querySelectorAll('.film-title-info .info')[1];
4
- return ((type === null || type === void 0 ? void 0 : type.innerText.replace(/[{()}]/g, '')) || 'film');
5
- };
6
- export const getTitle = (el) => {
7
- return el.querySelector('.film-title-name').text;
8
- };
9
- export const getYear = (el) => {
10
- var _a;
11
- return +((_a = el.querySelectorAll('.film-title-info .info')[0]) === null || _a === void 0 ? void 0 : _a.innerText.replace(/[{()}]/g, ''));
12
- };
13
- export const getUrl = (el) => {
14
- return el.querySelector('.film-title-name').attributes.href;
15
- };
16
- export const getColorRating = (el) => {
17
- return parseColor(el.querySelector('.article-header i.icon').classNames.split(' ').pop());
18
- };
19
- export const getPoster = (el) => {
20
- const image = el.querySelector('img').attributes.src;
21
- return addProtocol(image);
22
- };
23
- export const getOrigins = (el) => {
24
- var _a;
25
- const originsRaw = el.querySelector('.article-content p .info').text;
26
- const originsAll = (_a = originsRaw === null || originsRaw === void 0 ? void 0 : originsRaw.split(', ')) === null || _a === void 0 ? void 0 : _a[0];
27
- return originsAll === null || originsAll === void 0 ? void 0 : originsAll.split('/').map((country) => country.trim());
28
- };
29
- export const parsePeople = (el, type) => {
30
- let who;
31
- if (type === 'directors')
32
- who = 'Režie:';
33
- if (type === 'actors')
34
- who = 'Hrají:';
35
- const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) => el.textContent.includes(who));
36
- if (peopleNode) {
37
- const people = Array.from(peopleNode.querySelectorAll('a'));
38
- return people.map((person) => {
39
- return {
40
- id: parseIdFromUrl(person.attributes.href),
41
- name: person.innerText.trim(),
42
- url: `https://www.csfd.cz${person.attributes.href}`
43
- };
44
- });
45
- }
46
- else {
47
- return [];
48
- }
49
- };