node-csfd-api 2.4.0-next.0 → 2.4.2
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.
- package/README.md +4 -1
- package/{types/fetchers → fetchers}/index.d.ts +0 -0
- package/{cjs/fetchers → fetchers}/index.js +7 -13
- package/{types/helpers → helpers}/creator.helper.d.ts +0 -0
- package/{cjs/helpers → helpers}/creator.helper.js +0 -0
- package/{types/helpers → helpers}/global.helper.d.ts +0 -0
- package/{cjs/helpers → helpers}/global.helper.js +8 -3
- package/{types/helpers → helpers}/movie.helper.d.ts +2 -0
- package/{cjs/helpers → helpers}/movie.helper.js +36 -11
- package/{types/helpers → helpers}/search-user.helper.d.ts +0 -0
- package/{cjs/helpers → helpers}/search-user.helper.js +0 -0
- package/{types/helpers → helpers}/search.helper.d.ts +0 -0
- package/{cjs/helpers → helpers}/search.helper.js +0 -0
- package/{types/helpers → helpers}/user-ratings.helper.d.ts +0 -0
- package/{cjs/helpers → helpers}/user-ratings.helper.js +0 -0
- package/{types/index.d.ts → index.d.ts} +0 -0
- package/index.js +33 -0
- package/{types/interfaces → interfaces}/creator.interface.d.ts +0 -0
- package/{cjs/interfaces → interfaces}/creator.interface.js +0 -0
- package/{types/interfaces → interfaces}/global.d.ts +0 -0
- package/{cjs/interfaces → interfaces}/global.js +0 -0
- package/{types/interfaces → interfaces}/movie.interface.d.ts +2 -0
- package/{cjs/interfaces → interfaces}/movie.interface.js +0 -0
- package/{types/interfaces → interfaces}/search.interface.d.ts +0 -0
- package/{cjs/interfaces → interfaces}/search.interface.js +0 -0
- package/{types/interfaces → interfaces}/user-ratings.interface.d.ts +0 -0
- package/{cjs/interfaces → interfaces}/user-ratings.interface.js +0 -0
- package/package.json +9 -10
- package/{types/services → services}/creator.service.d.ts +0 -0
- package/services/creator.service.js +32 -0
- package/{types/services → services}/movie.service.d.ts +0 -0
- package/{cjs/services → services}/movie.service.js +12 -21
- package/{types/services → services}/search.service.d.ts +0 -0
- package/{cjs/services → services}/search.service.js +7 -18
- package/{types/services → services}/user-ratings.service.d.ts +0 -0
- package/{cjs/services → services}/user-ratings.service.js +25 -36
- package/{types/vars.d.ts → vars.d.ts} +0 -0
- package/{cjs/vars.js → vars.js} +1 -1
- package/cjs/index.js +0 -50
- package/cjs/services/creator.service.js +0 -43
- package/esm/fetchers/index.js +0 -32
- package/esm/helpers/creator.helper.js +0 -72
- package/esm/helpers/global.helper.js +0 -51
- package/esm/helpers/movie.helper.js +0 -200
- package/esm/helpers/search-user.helper.js +0 -15
- package/esm/helpers/search.helper.js +0 -38
- package/esm/helpers/user-ratings.helper.js +0 -47
- package/esm/index.js +0 -46
- package/esm/interfaces/creator.interface.js +0 -1
- package/esm/interfaces/global.js +0 -1
- package/esm/interfaces/movie.interface.js +0 -1
- package/esm/interfaces/search.interface.js +0 -1
- package/esm/interfaces/user-ratings.interface.js +0 -1
- package/esm/services/creator.service.js +0 -39
- package/esm/services/movie.service.js +0 -63
- package/esm/services/search.service.js +0 -67
- package/esm/services/user-ratings.service.js +0 -91
- package/esm/vars.js +0 -4
- package/types/index.ts +0 -22
package/esm/fetchers/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// import fetch from 'cross-fetch';
|
|
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
|
-
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 fetch(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,72 +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
|
-
const filmNodes = el.querySelectorAll('.box:first-of-type table tr');
|
|
48
|
-
let yearCache;
|
|
49
|
-
const films = filmNodes.map((filmNode) => {
|
|
50
|
-
var _a, _b, _c;
|
|
51
|
-
const id = getId((_a = filmNode.querySelector('td.name .film-title-name')) === null || _a === void 0 ? void 0 : _a.attributes.href);
|
|
52
|
-
const title = (_b = filmNode.querySelector('.name')) === null || _b === void 0 ? void 0 : _b.text.trim();
|
|
53
|
-
const year = +((_c = filmNode.querySelector('.year')) === null || _c === void 0 ? void 0 : _c.text.trim());
|
|
54
|
-
const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
|
|
55
|
-
// Cache year from previous film because there is a gap between movies with same year
|
|
56
|
-
if (year) {
|
|
57
|
-
yearCache = +year;
|
|
58
|
-
}
|
|
59
|
-
if (id && title) {
|
|
60
|
-
return {
|
|
61
|
-
id,
|
|
62
|
-
title,
|
|
63
|
-
year: year || yearCache,
|
|
64
|
-
colorRating
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {};
|
|
68
|
-
});
|
|
69
|
-
// Remove empty objects
|
|
70
|
-
const filmsUnique = films.filter((value) => Object.keys(value).length !== 0);
|
|
71
|
-
return filmsUnique;
|
|
72
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const parseIdFromUrl = (url) => {
|
|
2
|
-
const idSlug = url.split('/')[2];
|
|
3
|
-
const id = idSlug.split('-')[0];
|
|
4
|
-
return +id;
|
|
5
|
-
};
|
|
6
|
-
export const getColor = (cls) => {
|
|
7
|
-
switch (cls) {
|
|
8
|
-
case 'page-lightgrey':
|
|
9
|
-
return 'unknown';
|
|
10
|
-
case 'page-red':
|
|
11
|
-
return 'good';
|
|
12
|
-
case 'page-blue':
|
|
13
|
-
return 'average';
|
|
14
|
-
case 'page-grey':
|
|
15
|
-
return 'bad';
|
|
16
|
-
default:
|
|
17
|
-
return 'unknown';
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export const parseColor = (quality) => {
|
|
21
|
-
switch (quality) {
|
|
22
|
-
case 'lightgrey':
|
|
23
|
-
return 'unknown';
|
|
24
|
-
case 'red':
|
|
25
|
-
return 'good';
|
|
26
|
-
case 'blue':
|
|
27
|
-
return 'average';
|
|
28
|
-
case 'grey':
|
|
29
|
-
return 'bad';
|
|
30
|
-
default:
|
|
31
|
-
return 'unknown';
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export const addProtocol = (url) => {
|
|
35
|
-
return url.startsWith('//') ? 'https:' + url : url;
|
|
36
|
-
};
|
|
37
|
-
export const parseISO8601Duration = (iso) => {
|
|
38
|
-
const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
|
|
39
|
-
const matches = iso.match(iso8601DurationRegex);
|
|
40
|
-
const duration = {
|
|
41
|
-
sign: matches[1] === undefined ? '+' : '-',
|
|
42
|
-
years: matches[2] === undefined ? 0 : matches[2],
|
|
43
|
-
months: matches[3] === undefined ? 0 : matches[3],
|
|
44
|
-
weeks: matches[4] === undefined ? 0 : matches[4],
|
|
45
|
-
days: matches[5] === undefined ? 0 : matches[5],
|
|
46
|
-
hours: matches[6] === undefined ? 0 : matches[6],
|
|
47
|
-
minutes: matches[7] === undefined ? 0 : matches[7],
|
|
48
|
-
seconds: matches[8] === undefined ? 0 : matches[8]
|
|
49
|
-
};
|
|
50
|
-
return +duration.minutes;
|
|
51
|
-
};
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { addProtocol, getColor, parseIdFromUrl, parseISO8601Duration } 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
|
-
if (Number.isInteger(rating)) {
|
|
25
|
-
return rating;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export const getRatingCount = (el) => {
|
|
32
|
-
var _a;
|
|
33
|
-
const ratingCountRaw = (_a = el.querySelector('.box-rating-container .counter')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
34
|
-
const ratingCount = +(ratingCountRaw === null || ratingCountRaw === void 0 ? void 0 : ratingCountRaw.replace(/[(\s)]/g, ''));
|
|
35
|
-
if (Number.isInteger(ratingCount)) {
|
|
36
|
-
return ratingCount;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
export const getYear = (el) => {
|
|
43
|
-
try {
|
|
44
|
-
const jsonLd = JSON.parse(el);
|
|
45
|
-
return +jsonLd.dateCreated;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error('node-csfd-api: Error parsing JSON-LD', error);
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
export const getDuration = (jsonLdRaw, el) => {
|
|
53
|
-
let duration = null;
|
|
54
|
-
try {
|
|
55
|
-
const jsonLd = JSON.parse(jsonLdRaw);
|
|
56
|
-
duration = jsonLd.duration;
|
|
57
|
-
return parseISO8601Duration(duration);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
const origin = el.querySelector('.origin').innerText;
|
|
61
|
-
const timeString = origin.split(',');
|
|
62
|
-
if (timeString.length > 2) {
|
|
63
|
-
// Get last time elelment
|
|
64
|
-
const timeString2 = timeString.pop().trim();
|
|
65
|
-
// Clean it
|
|
66
|
-
const timeRaw = timeString2.split('(')[0].trim();
|
|
67
|
-
// Split by minutes and hours
|
|
68
|
-
const hoursMinsRaw = timeRaw.split('min')[0];
|
|
69
|
-
const hoursMins = hoursMinsRaw.split('h');
|
|
70
|
-
// Resolve hours + minutes format
|
|
71
|
-
duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];
|
|
72
|
-
return duration;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
export const getTitlesOther = (el) => {
|
|
80
|
-
const namesNode = el.querySelectorAll('.film-names li');
|
|
81
|
-
return namesNode.map((el) => {
|
|
82
|
-
const country = el.querySelector('img.flag').attributes.alt;
|
|
83
|
-
const title = el.textContent.trim().split('\n')[0];
|
|
84
|
-
if (country && title) {
|
|
85
|
-
return {
|
|
86
|
-
country,
|
|
87
|
-
title
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
export const getPoster = (el) => {
|
|
96
|
-
var _a;
|
|
97
|
-
const poster = el.querySelector('.film-posters img');
|
|
98
|
-
// Resolve empty image
|
|
99
|
-
if (poster) {
|
|
100
|
-
if ((_a = poster.classNames) === null || _a === void 0 ? void 0 : _a.includes('empty-image')) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// Full sized image (not thumb)
|
|
105
|
-
const imageThumb = poster.attributes.src.split('?')[0];
|
|
106
|
-
const image = imageThumb.replace(/\/w140\//, '/w1080/');
|
|
107
|
-
return addProtocol(image);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
export const getDescriptions = (el) => {
|
|
115
|
-
return el
|
|
116
|
-
.querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
|
|
117
|
-
.map((movie) => { var _a; return (_a = movie.textContent) === null || _a === void 0 ? void 0 : _a.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); });
|
|
118
|
-
};
|
|
119
|
-
export const parsePeople = (el) => {
|
|
120
|
-
const people = el.querySelectorAll('a');
|
|
121
|
-
return (people
|
|
122
|
-
// Filter out "more" links
|
|
123
|
-
.filter((x) => x.classNames.length === 0)
|
|
124
|
-
.map((person) => {
|
|
125
|
-
return {
|
|
126
|
-
id: parseIdFromUrl(person.attributes.href),
|
|
127
|
-
name: person.innerText.trim(),
|
|
128
|
-
url: `https://www.csfd.cz${person.attributes.href}`
|
|
129
|
-
};
|
|
130
|
-
}));
|
|
131
|
-
};
|
|
132
|
-
export const getGroup = (el, group) => {
|
|
133
|
-
const creators = el.querySelectorAll('.creators h4');
|
|
134
|
-
const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];
|
|
135
|
-
if (element === null || element === void 0 ? void 0 : element.parentNode) {
|
|
136
|
-
return parsePeople(element.parentNode);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
export const getType = (el) => {
|
|
143
|
-
var _a;
|
|
144
|
-
const type = el.querySelector('.film-header-name .type');
|
|
145
|
-
return ((_a = type === null || type === void 0 ? void 0 : type.innerText) === null || _a === void 0 ? void 0 : _a.replace(/[{()}]/g, '')) || 'film';
|
|
146
|
-
};
|
|
147
|
-
export const getVods = (el) => {
|
|
148
|
-
let vods = [];
|
|
149
|
-
if (el) {
|
|
150
|
-
const buttons = el.querySelectorAll('.box-buttons .button');
|
|
151
|
-
const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));
|
|
152
|
-
vods = buttonsVod.map((btn) => {
|
|
153
|
-
return {
|
|
154
|
-
title: btn.textContent.trim(),
|
|
155
|
-
url: btn.attributes.href
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
return vods.length ? vods : [];
|
|
160
|
-
};
|
|
161
|
-
// Get box content
|
|
162
|
-
export const getBoxContent = (el, box) => {
|
|
163
|
-
var _a;
|
|
164
|
-
const headers = el.querySelectorAll('section.box .box-header');
|
|
165
|
-
return (_a = headers.find((header) => header.querySelector('h3').textContent.trim().includes(box))) === null || _a === void 0 ? void 0 : _a.parentNode;
|
|
166
|
-
};
|
|
167
|
-
export const getBoxMovies = (el, boxName) => {
|
|
168
|
-
const movieListItem = [];
|
|
169
|
-
const box = getBoxContent(el, boxName);
|
|
170
|
-
const movieTitleNodes = box === null || box === void 0 ? void 0 : box.querySelectorAll('.article-header .film-title-name');
|
|
171
|
-
if (movieTitleNodes === null || movieTitleNodes === void 0 ? void 0 : movieTitleNodes.length) {
|
|
172
|
-
for (const item of movieTitleNodes) {
|
|
173
|
-
movieListItem.push({
|
|
174
|
-
id: parseIdFromUrl(item.attributes.href),
|
|
175
|
-
title: item.textContent.trim(),
|
|
176
|
-
url: `https://www.csfd.cz${item.attributes.href}`
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return movieListItem;
|
|
181
|
-
};
|
|
182
|
-
export const getPremieres = (el) => {
|
|
183
|
-
var _a;
|
|
184
|
-
const premieresNode = el.querySelectorAll('.box-premieres li');
|
|
185
|
-
const premiere = [];
|
|
186
|
-
for (const premiereNode of premieresNode) {
|
|
187
|
-
const [date, ...company] = premiereNode.querySelector('p + span').attributes.title.split(' ');
|
|
188
|
-
premiere.push({
|
|
189
|
-
country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
|
|
190
|
-
format: premiereNode.querySelector('p').textContent.trim().split(' od')[0],
|
|
191
|
-
date,
|
|
192
|
-
company: company.join(' ')
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
return premiere;
|
|
196
|
-
};
|
|
197
|
-
export const getTags = (el) => {
|
|
198
|
-
const tagsRaw = el.querySelectorAll('.box-content a[href*="/podrobne-vyhledavani/?tag="]');
|
|
199
|
-
return tagsRaw.map((tag) => tag.textContent);
|
|
200
|
-
};
|
|
@@ -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,38 +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
|
-
const people = el.querySelectorAll(`.article-content .${type} a`);
|
|
31
|
-
return people.map((person) => {
|
|
32
|
-
return {
|
|
33
|
-
id: parseIdFromUrl(person.attributes.href),
|
|
34
|
-
name: person.innerText.trim(),
|
|
35
|
-
url: `https://www.csfd.cz${person.attributes.href}`
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { parseIdFromUrl } from './global.helper';
|
|
2
|
-
export const getId = (el) => {
|
|
3
|
-
const url = el.querySelector('td.name .film-title-name').attributes.href;
|
|
4
|
-
return parseIdFromUrl(url);
|
|
5
|
-
};
|
|
6
|
-
export const getUserRating = (el) => {
|
|
7
|
-
const ratingText = el.querySelector('td.star-rating-only .stars').classNames.split(' ').pop();
|
|
8
|
-
const rating = ratingText.includes('stars-') ? +ratingText.split('-').pop() : 0;
|
|
9
|
-
return rating;
|
|
10
|
-
};
|
|
11
|
-
export const getType = (el) => {
|
|
12
|
-
const typeText = el.querySelectorAll('td.name .film-title-info .info');
|
|
13
|
-
return (typeText.length > 1 ? typeText[1].text.slice(1, -1) : 'film');
|
|
14
|
-
};
|
|
15
|
-
export const getTitle = (el) => {
|
|
16
|
-
return el.querySelector('td.name .film-title-name').text;
|
|
17
|
-
};
|
|
18
|
-
export const getYear = (el) => {
|
|
19
|
-
return +el.querySelectorAll('td.name .film-title-info .info')[0].text.slice(1, -1);
|
|
20
|
-
};
|
|
21
|
-
export const getColorRating = (el) => {
|
|
22
|
-
const color = parseColor(el.querySelector('td.name .icon').classNames.split(' ').pop());
|
|
23
|
-
return color;
|
|
24
|
-
};
|
|
25
|
-
export const getDate = (el) => {
|
|
26
|
-
return el.querySelector('td.date-only').text.trim();
|
|
27
|
-
};
|
|
28
|
-
export const getUrl = (el) => {
|
|
29
|
-
const url = el.querySelector('td.name .film-title-name').attributes.href;
|
|
30
|
-
return `https://www.csfd.cz${url}`;
|
|
31
|
-
};
|
|
32
|
-
export const parseColor = (quality) => {
|
|
33
|
-
switch (quality) {
|
|
34
|
-
case 'lightgrey':
|
|
35
|
-
return 'unknown';
|
|
36
|
-
case 'red':
|
|
37
|
-
return 'good';
|
|
38
|
-
case 'blue':
|
|
39
|
-
return 'average';
|
|
40
|
-
case 'grey':
|
|
41
|
-
return 'bad';
|
|
42
|
-
default:
|
|
43
|
-
return 'unknown';
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
// Sleep in loop
|
|
47
|
-
export const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
|
package/esm/index.js
DELETED
|
@@ -1,46 +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 { CreatorScraper } from './services/creator.service';
|
|
11
|
-
import { MovieScraper } from './services/movie.service';
|
|
12
|
-
import { SearchScraper } from './services/search.service';
|
|
13
|
-
import { UserRatingsScraper } from './services/user-ratings.service';
|
|
14
|
-
export class Csfd {
|
|
15
|
-
constructor(userRatingsService, movieService, creatorService, searchService) {
|
|
16
|
-
this.userRatingsService = userRatingsService;
|
|
17
|
-
this.movieService = movieService;
|
|
18
|
-
this.creatorService = creatorService;
|
|
19
|
-
this.searchService = searchService;
|
|
20
|
-
}
|
|
21
|
-
userRatings(user, config) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
return this.userRatingsService.userRatings(user, config);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
movie(movie) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
return this.movieService.movie(+movie);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
creator(creator) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return this.creatorService.creator(+creator);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
search(text) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
return this.searchService.search(text);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const movieScraper = new MovieScraper();
|
|
43
|
-
const userRatingsScraper = new UserRatingsScraper();
|
|
44
|
-
const creatorScraper = new CreatorScraper();
|
|
45
|
-
const searchScraper = new SearchScraper();
|
|
46
|
-
export const csfd = new Csfd(userRatingsScraper, movieScraper, creatorScraper, searchScraper);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/interfaces/global.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,39 +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 { parse } from 'node-html-parser';
|
|
11
|
-
import { fetchPage } from '../fetchers';
|
|
12
|
-
import { getBio, getBirthdayInfo, getFilms, getName, getPhoto } from '../helpers/creator.helper';
|
|
13
|
-
import { creatorUrl } from '../vars';
|
|
14
|
-
export class CreatorScraper {
|
|
15
|
-
creator(creatorId) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const url = creatorUrl(+creatorId);
|
|
18
|
-
const response = yield fetchPage(url);
|
|
19
|
-
const creatorHtml = parse(response);
|
|
20
|
-
const asideNode = creatorHtml.querySelector('.creator-about');
|
|
21
|
-
const filmsNode = creatorHtml.querySelector('.creator-filmography');
|
|
22
|
-
this.buildCreator(+creatorId, asideNode, filmsNode);
|
|
23
|
-
return this.person;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
buildCreator(id, asideEl, filmsNode) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
this.person = {
|
|
29
|
-
id,
|
|
30
|
-
name: getName(asideEl),
|
|
31
|
-
birthday: (_a = getBirthdayInfo(asideEl)) === null || _a === void 0 ? void 0 : _a.birthday,
|
|
32
|
-
birthplace: (_b = getBirthdayInfo(asideEl)) === null || _b === void 0 ? void 0 : _b.birthPlace,
|
|
33
|
-
photo: getPhoto(asideEl),
|
|
34
|
-
age: ((_c = getBirthdayInfo(asideEl)) === null || _c === void 0 ? void 0 : _c.age) || null,
|
|
35
|
-
bio: getBio(asideEl),
|
|
36
|
-
films: getFilms(filmsNode)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,63 +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 { parse } from 'node-html-parser';
|
|
11
|
-
import { fetchPage } from '../fetchers';
|
|
12
|
-
import { getBoxMovies, getColorRating, getDescriptions, getDuration, getGenres, getGroup, getOrigins, getPoster, getPremieres, getRating, getRatingCount, getTags, getTitle, getTitlesOther, getType, getVods, getYear } from '../helpers/movie.helper';
|
|
13
|
-
import { movieUrl } from '../vars';
|
|
14
|
-
export class MovieScraper {
|
|
15
|
-
movie(movieId) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const url = movieUrl(+movieId);
|
|
18
|
-
const response = yield fetchPage(url);
|
|
19
|
-
const movieHtml = parse(response);
|
|
20
|
-
const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');
|
|
21
|
-
const asideNode = movieHtml.querySelector('.aside-movie-profile');
|
|
22
|
-
const movieNode = movieHtml.querySelector('.main-movie-profile');
|
|
23
|
-
const jsonLd = movieHtml.querySelector('script[type="application/ld+json"]').innerText;
|
|
24
|
-
this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);
|
|
25
|
-
return this.film;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
buildMovie(movieId, el, asideEl, pageClasses, jsonLd) {
|
|
29
|
-
this.film = {
|
|
30
|
-
id: movieId,
|
|
31
|
-
title: getTitle(el),
|
|
32
|
-
year: getYear(jsonLd),
|
|
33
|
-
duration: getDuration(jsonLd, el),
|
|
34
|
-
descriptions: getDescriptions(el),
|
|
35
|
-
genres: getGenres(el),
|
|
36
|
-
type: getType(el),
|
|
37
|
-
url: movieUrl(movieId),
|
|
38
|
-
origins: getOrigins(el),
|
|
39
|
-
colorRating: getColorRating(pageClasses),
|
|
40
|
-
rating: getRating(asideEl),
|
|
41
|
-
ratingCount: getRatingCount(asideEl),
|
|
42
|
-
titlesOther: getTitlesOther(el),
|
|
43
|
-
poster: getPoster(el),
|
|
44
|
-
creators: {
|
|
45
|
-
directors: getGroup(el, 'Režie'),
|
|
46
|
-
writers: getGroup(el, 'Scénář'),
|
|
47
|
-
cinematography: getGroup(el, 'Kamera'),
|
|
48
|
-
music: getGroup(el, 'Hudba'),
|
|
49
|
-
actors: getGroup(el, 'Hrají'),
|
|
50
|
-
basedOn: getGroup(el, 'Předloha'),
|
|
51
|
-
producers: getGroup(el, 'Produkce'),
|
|
52
|
-
filmEditing: getGroup(el, 'Střih'),
|
|
53
|
-
costumeDesign: getGroup(el, 'Kostýmy'),
|
|
54
|
-
productionDesign: getGroup(el, 'Scénografie')
|
|
55
|
-
},
|
|
56
|
-
vod: getVods(asideEl),
|
|
57
|
-
tags: getTags(asideEl),
|
|
58
|
-
premieres: getPremieres(asideEl),
|
|
59
|
-
related: getBoxMovies(asideEl, 'Související'),
|
|
60
|
-
similar: getBoxMovies(asideEl, 'Podobné')
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|