node-csfd-api 3.0.0-next.9 → 3.0.1
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/LICENSE +21 -0
- package/README.md +89 -44
- package/_virtual/rolldown_runtime.js +25 -0
- package/dto/cinema.d.mts +28 -0
- package/dto/cinema.d.ts +28 -0
- package/dto/creator.d.mts +17 -0
- package/dto/creator.d.ts +17 -0
- package/dto/global.d.mts +26 -0
- package/dto/global.d.ts +26 -0
- package/dto/movie.d.mts +71 -0
- package/dto/movie.d.ts +71 -0
- package/dto/search.d.mts +32 -0
- package/dto/search.d.ts +32 -0
- package/dto/user-ratings.d.mts +23 -0
- package/dto/user-ratings.d.ts +23 -0
- package/fetchers/fetch.polyfill.js +10 -0
- package/fetchers/fetch.polyfill.js.map +1 -0
- package/fetchers/fetch.polyfill.mjs +8 -0
- package/fetchers/fetch.polyfill.mjs.map +1 -0
- package/fetchers/index.js +24 -0
- package/fetchers/index.js.map +1 -0
- package/fetchers/index.mjs +24 -0
- package/fetchers/index.mjs.map +1 -0
- package/helpers/cinema.helper.js +84 -0
- package/helpers/cinema.helper.js.map +1 -0
- package/helpers/cinema.helper.mjs +80 -0
- package/helpers/cinema.helper.mjs.map +1 -0
- package/helpers/creator.helper.js +73 -0
- package/helpers/creator.helper.js.map +1 -0
- package/helpers/creator.helper.mjs +69 -0
- package/helpers/creator.helper.mjs.map +1 -0
- package/helpers/global.helper.js +50 -0
- package/helpers/global.helper.js.map +1 -0
- package/helpers/global.helper.mjs +45 -0
- package/helpers/global.helper.mjs.map +1 -0
- package/helpers/movie.helper.js +162 -0
- package/helpers/movie.helper.js.map +1 -0
- package/helpers/movie.helper.mjs +144 -0
- package/helpers/movie.helper.mjs.map +1 -0
- package/helpers/search-user.helper.js +29 -0
- package/helpers/search-user.helper.js.map +1 -0
- package/helpers/search-user.helper.mjs +24 -0
- package/helpers/search-user.helper.mjs.map +1 -0
- package/helpers/search.helper.js +52 -0
- package/helpers/search.helper.js.map +1 -0
- package/helpers/search.helper.mjs +45 -0
- package/helpers/search.helper.mjs.map +1 -0
- package/helpers/user-ratings.helper.js +52 -0
- package/helpers/user-ratings.helper.js.map +1 -0
- package/helpers/user-ratings.helper.mjs +44 -0
- package/helpers/user-ratings.helper.mjs.map +1 -0
- package/index.d.mts +30 -0
- package/index.d.ts +30 -0
- package/index.js +42 -0
- package/index.js.map +1 -0
- package/index.mjs +41 -0
- package/index.mjs.map +1 -0
- package/package.json +15 -28
- package/services/cinema.service.d.mts +11 -0
- package/services/cinema.service.d.ts +11 -0
- package/services/cinema.service.js +35 -0
- package/services/cinema.service.js.map +1 -0
- package/services/cinema.service.mjs +33 -0
- package/services/cinema.service.mjs.map +1 -0
- package/services/creator.service.d.mts +11 -0
- package/services/creator.service.d.ts +11 -0
- package/services/creator.service.js +35 -0
- package/services/creator.service.js.map +1 -0
- package/services/creator.service.mjs +33 -0
- package/services/creator.service.mjs.map +1 -0
- package/services/movie.service.d.mts +11 -0
- package/services/movie.service.d.ts +11 -0
- package/services/movie.service.js +62 -0
- package/services/movie.service.js.map +1 -0
- package/services/movie.service.mjs +60 -0
- package/services/movie.service.mjs.map +1 -0
- package/services/search.service.d.mts +10 -0
- package/services/search.service.d.ts +10 -0
- package/services/search.service.js +81 -0
- package/services/search.service.js.map +1 -0
- package/services/search.service.mjs +79 -0
- package/services/search.service.mjs.map +1 -0
- package/services/user-ratings.service.d.mts +12 -0
- package/services/user-ratings.service.d.ts +12 -0
- package/services/user-ratings.service.js +66 -0
- package/services/user-ratings.service.js.map +1 -0
- package/services/user-ratings.service.mjs +64 -0
- package/services/user-ratings.service.mjs.map +1 -0
- package/{cjs/vars.js → vars.js} +13 -7
- package/vars.js.map +1 -0
- package/vars.mjs +12 -0
- package/vars.mjs.map +1 -0
- package/cjs/fetchers/index.js +0 -41
- package/cjs/helpers/creator.helper.js +0 -86
- package/cjs/helpers/global.helper.js +0 -64
- package/cjs/helpers/movie.helper.js +0 -248
- package/cjs/helpers/search-user.helper.js +0 -22
- package/cjs/helpers/search.helper.js +0 -60
- package/cjs/helpers/user-ratings.helper.js +0 -60
- package/cjs/index.js +0 -50
- package/cjs/services/creator.service.js +0 -43
- package/cjs/services/movie.service.js +0 -69
- package/cjs/services/search.service.js +0 -91
- package/cjs/services/user-ratings.service.js +0 -95
- package/esm/fetchers/index.js +0 -37
- package/esm/helpers/creator.helper.js +0 -73
- package/esm/helpers/global.helper.js +0 -56
- package/esm/helpers/movie.helper.js +0 -223
- package/esm/helpers/search-user.helper.js +0 -15
- package/esm/helpers/search.helper.js +0 -49
- package/esm/helpers/user-ratings.helper.js +0 -47
- package/esm/index.js +0 -46
- package/esm/services/creator.service.js +0 -39
- package/esm/services/movie.service.js +0 -65
- package/esm/services/search.service.js +0 -87
- package/esm/services/user-ratings.service.js +0 -91
- package/esm/vars.js +0 -4
- package/types/fetchers/index.d.ts +0 -1
- package/types/helpers/creator.helper.d.ts +0 -17
- package/types/helpers/global.helper.d.ts +0 -7
- package/types/helpers/movie.helper.d.ts +0 -25
- package/types/helpers/search-user.helper.d.ts +0 -5
- package/types/helpers/search.helper.d.ts +0 -11
- package/types/helpers/user-ratings.helper.d.ts +0 -13
- package/types/index.d.ts +0 -20
- package/types/index.ts +0 -22
- package/types/interfaces/creator.interface.d.ts +0 -12
- package/types/interfaces/global.d.ts +0 -22
- package/types/interfaces/movie.interface.d.ts +0 -66
- package/types/interfaces/search.interface.d.ts +0 -27
- package/types/interfaces/user-ratings.interface.d.ts +0 -18
- package/types/services/creator.service.d.ts +0 -6
- package/types/services/movie.service.d.ts +0 -6
- package/types/services/search.service.d.ts +0 -5
- package/types/services/user-ratings.service.d.ts +0 -7
- package/types/vars.d.ts +0 -4
|
@@ -1,91 +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.SearchScraper = void 0;
|
|
13
|
-
const node_html_parser_1 = require("node-html-parser");
|
|
14
|
-
const fetchers_1 = require("../fetchers");
|
|
15
|
-
const global_helper_1 = require("../helpers/global.helper");
|
|
16
|
-
const search_user_helper_1 = require("../helpers/search-user.helper");
|
|
17
|
-
const search_helper_1 = require("../helpers/search.helper");
|
|
18
|
-
const vars_1 = require("../vars");
|
|
19
|
-
class SearchScraper {
|
|
20
|
-
search(text) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const url = (0, vars_1.searchUrl)(text);
|
|
23
|
-
const response = yield (0, fetchers_1.fetchPage)(url);
|
|
24
|
-
const html = (0, node_html_parser_1.parse)(response);
|
|
25
|
-
const moviesNode = html.querySelectorAll('.main-movies article');
|
|
26
|
-
const usersNode = html.querySelectorAll('.main-users article');
|
|
27
|
-
const tvSeriesNode = html.querySelectorAll('.main-series article');
|
|
28
|
-
return this.parseSearch(moviesNode, usersNode, tvSeriesNode);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
parseSearch(moviesNode, usersNode, tvSeriesNode) {
|
|
32
|
-
const movies = [];
|
|
33
|
-
const users = [];
|
|
34
|
-
const tvSeries = [];
|
|
35
|
-
moviesNode.map((m) => {
|
|
36
|
-
const url = (0, search_helper_1.getUrl)(m);
|
|
37
|
-
const movie = {
|
|
38
|
-
id: (0, global_helper_1.parseIdFromUrl)(url),
|
|
39
|
-
title: (0, search_helper_1.getTitle)(m),
|
|
40
|
-
year: (0, search_helper_1.getYear)(m),
|
|
41
|
-
url: `https://www.csfd.cz${url}`,
|
|
42
|
-
type: (0, search_helper_1.getType)(m),
|
|
43
|
-
colorRating: (0, search_helper_1.getColorRating)(m),
|
|
44
|
-
poster: (0, search_helper_1.getPoster)(m),
|
|
45
|
-
origins: (0, search_helper_1.getOrigins)(m),
|
|
46
|
-
creators: {
|
|
47
|
-
directors: (0, search_helper_1.parsePeople)(m, 'directors'),
|
|
48
|
-
actors: (0, search_helper_1.parsePeople)(m, 'actors')
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
movies.push(movie);
|
|
52
|
-
});
|
|
53
|
-
usersNode.map((m) => {
|
|
54
|
-
const url = (0, search_user_helper_1.getUserUrl)(m);
|
|
55
|
-
const user = {
|
|
56
|
-
id: (0, global_helper_1.parseIdFromUrl)(url),
|
|
57
|
-
user: (0, search_user_helper_1.getUser)(m),
|
|
58
|
-
userRealName: (0, search_user_helper_1.getUserRealName)(m),
|
|
59
|
-
avatar: (0, search_user_helper_1.getAvatar)(m),
|
|
60
|
-
url: `https://www.csfd.cz${url}`
|
|
61
|
-
};
|
|
62
|
-
users.push(user);
|
|
63
|
-
});
|
|
64
|
-
tvSeriesNode.map((m) => {
|
|
65
|
-
const url = (0, search_helper_1.getUrl)(m);
|
|
66
|
-
const user = {
|
|
67
|
-
id: (0, global_helper_1.parseIdFromUrl)(url),
|
|
68
|
-
title: (0, search_helper_1.getTitle)(m),
|
|
69
|
-
year: (0, search_helper_1.getYear)(m),
|
|
70
|
-
url: `https://www.csfd.cz${url}`,
|
|
71
|
-
type: (0, search_helper_1.getType)(m),
|
|
72
|
-
colorRating: (0, search_helper_1.getColorRating)(m),
|
|
73
|
-
poster: (0, search_helper_1.getPoster)(m),
|
|
74
|
-
origins: (0, search_helper_1.getOrigins)(m),
|
|
75
|
-
creators: {
|
|
76
|
-
directors: (0, search_helper_1.parsePeople)(m, 'directors'),
|
|
77
|
-
actors: (0, search_helper_1.parsePeople)(m, 'actors')
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
tvSeries.push(user);
|
|
81
|
-
});
|
|
82
|
-
const search = {
|
|
83
|
-
movies: movies,
|
|
84
|
-
users: users,
|
|
85
|
-
tvSeries: tvSeries,
|
|
86
|
-
creators: []
|
|
87
|
-
};
|
|
88
|
-
return search;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.SearchScraper = SearchScraper;
|
|
@@ -1,95 +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.UserRatingsScraper = void 0;
|
|
13
|
-
const node_html_parser_1 = require("node-html-parser");
|
|
14
|
-
const fetchers_1 = require("../fetchers");
|
|
15
|
-
const user_ratings_helper_1 = require("../helpers/user-ratings.helper");
|
|
16
|
-
const vars_1 = require("../vars");
|
|
17
|
-
class UserRatingsScraper {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.films = [];
|
|
20
|
-
}
|
|
21
|
-
userRatings(user, config) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
let allMovies = [];
|
|
24
|
-
const url = (0, vars_1.userRatingsUrl)(user);
|
|
25
|
-
const response = yield (0, fetchers_1.fetchPage)(url);
|
|
26
|
-
const items = (0, node_html_parser_1.parse)(response);
|
|
27
|
-
const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
|
|
28
|
-
// Get number of pages
|
|
29
|
-
const pagesNode = items.querySelector('.pagination');
|
|
30
|
-
const pages = +(pagesNode === null || pagesNode === void 0 ? void 0 : pagesNode.childNodes[pagesNode.childNodes.length - 4].rawText) || 1;
|
|
31
|
-
allMovies = this.getPage(config, movies);
|
|
32
|
-
if (config === null || config === void 0 ? void 0 : config.allPages) {
|
|
33
|
-
console.log('User', user, url);
|
|
34
|
-
console.log('Fetching all pages', pages);
|
|
35
|
-
for (let i = 2; i <= pages; i++) {
|
|
36
|
-
console.log('Fetching page', i, 'out of', pages, '...');
|
|
37
|
-
const url = (0, vars_1.userRatingsUrl)(user, i);
|
|
38
|
-
const response = yield (0, fetchers_1.fetchPage)(url);
|
|
39
|
-
const items = (0, node_html_parser_1.parse)(response);
|
|
40
|
-
const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
|
|
41
|
-
allMovies = [...this.getPage(config, movies)];
|
|
42
|
-
// Sleep
|
|
43
|
-
if (config.allPagesDelay) {
|
|
44
|
-
yield (0, user_ratings_helper_1.sleep)(config.allPagesDelay);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return allMovies;
|
|
48
|
-
}
|
|
49
|
-
return allMovies;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
getPage(config, movies) {
|
|
53
|
-
var _a, _b, _c, _d;
|
|
54
|
-
if (config) {
|
|
55
|
-
if (((_a = config.includesOnly) === null || _a === void 0 ? void 0 : _a.length) && ((_b = config.excludes) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
56
|
-
console.warn(`node-csfd-api:
|
|
57
|
-
You can not use both parameters 'includesOnly' and 'excludes'.
|
|
58
|
-
Parameter 'includesOnly' will be used now:`, config.includesOnly);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
for (const el of movies) {
|
|
62
|
-
const type = (0, user_ratings_helper_1.getType)(el);
|
|
63
|
-
// Filtering includesOnly
|
|
64
|
-
if ((_c = config === null || config === void 0 ? void 0 : config.includesOnly) === null || _c === void 0 ? void 0 : _c.length) {
|
|
65
|
-
if (config.includesOnly.some((include) => type === include)) {
|
|
66
|
-
this.buildUserRatings(el);
|
|
67
|
-
}
|
|
68
|
-
// Filter exludes
|
|
69
|
-
}
|
|
70
|
-
else if ((_d = config === null || config === void 0 ? void 0 : config.excludes) === null || _d === void 0 ? void 0 : _d.length) {
|
|
71
|
-
if (!config.excludes.some((exclude) => type === exclude)) {
|
|
72
|
-
this.buildUserRatings(el);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// Without filtering
|
|
77
|
-
this.buildUserRatings(el);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return this.films;
|
|
81
|
-
}
|
|
82
|
-
buildUserRatings(el) {
|
|
83
|
-
this.films.push({
|
|
84
|
-
id: (0, user_ratings_helper_1.getId)(el),
|
|
85
|
-
title: (0, user_ratings_helper_1.getTitle)(el),
|
|
86
|
-
year: (0, user_ratings_helper_1.getYear)(el),
|
|
87
|
-
type: (0, user_ratings_helper_1.getType)(el),
|
|
88
|
-
url: (0, user_ratings_helper_1.getUrl)(el),
|
|
89
|
-
colorRating: (0, user_ratings_helper_1.getColorRating)(el),
|
|
90
|
-
userDate: (0, user_ratings_helper_1.getDate)(el),
|
|
91
|
-
userRating: (0, user_ratings_helper_1.getUserRating)(el)
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.UserRatingsScraper = UserRatingsScraper;
|
package/esm/fetchers/index.js
DELETED
|
@@ -1,37 +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
|
-
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
|
|
11
|
-
import { fetch as crossFetch } from 'cross-fetch';
|
|
12
|
-
const fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
|
|
13
|
-
(typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
|
|
14
|
-
(typeof window !== 'undefined' && window.fetch) || // Browser fetch
|
|
15
|
-
crossFetch; // Polyfill fetch
|
|
16
|
-
const USER_AGENTS = [
|
|
17
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
18
|
-
'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',
|
|
19
|
-
'Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36',
|
|
20
|
-
'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36'
|
|
21
|
-
];
|
|
22
|
-
const headers = {
|
|
23
|
-
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
24
|
-
};
|
|
25
|
-
export const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
try {
|
|
27
|
-
const response = yield fetchSafe(url, { headers });
|
|
28
|
-
if (response.status >= 400 && response.status < 600) {
|
|
29
|
-
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
30
|
-
}
|
|
31
|
-
return yield response.text();
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
console.error(e);
|
|
35
|
-
return 'Error';
|
|
36
|
-
}
|
|
37
|
-
});
|
|
@@ -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,56 +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 parseISO8601Duration = (iso) => {
|
|
43
|
-
const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
|
|
44
|
-
const matches = iso.match(iso8601DurationRegex);
|
|
45
|
-
const duration = {
|
|
46
|
-
sign: matches[1] === undefined ? '+' : '-',
|
|
47
|
-
years: matches[2] === undefined ? 0 : matches[2],
|
|
48
|
-
months: matches[3] === undefined ? 0 : matches[3],
|
|
49
|
-
weeks: matches[4] === undefined ? 0 : matches[4],
|
|
50
|
-
days: matches[5] === undefined ? 0 : matches[5],
|
|
51
|
-
hours: matches[6] === undefined ? 0 : matches[6],
|
|
52
|
-
minutes: matches[7] === undefined ? 0 : matches[7],
|
|
53
|
-
seconds: matches[8] === undefined ? 0 : matches[8]
|
|
54
|
-
};
|
|
55
|
-
return +duration.minutes;
|
|
56
|
-
};
|
|
@@ -1,223 +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 getRandomPhoto = (el) => {
|
|
115
|
-
var _a;
|
|
116
|
-
const imageNode = el.querySelector('.gallery-item picture img');
|
|
117
|
-
const image = (_a = imageNode === null || imageNode === void 0 ? void 0 : imageNode.attributes) === null || _a === void 0 ? void 0 : _a.src;
|
|
118
|
-
if (image) {
|
|
119
|
-
return image.replace(/\/w663\//, '/w1326/');
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
export const getTrivia = (el) => {
|
|
126
|
-
const triviaNodes = el.querySelectorAll('.article-trivia ul li');
|
|
127
|
-
if (triviaNodes === null || triviaNodes === void 0 ? void 0 : triviaNodes.length) {
|
|
128
|
-
return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
export const getDescriptions = (el) => {
|
|
135
|
-
return el
|
|
136
|
-
.querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
|
|
137
|
-
.map((movie) => { var _a; return (_a = movie.textContent) === null || _a === void 0 ? void 0 : _a.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); });
|
|
138
|
-
};
|
|
139
|
-
export const parsePeople = (el) => {
|
|
140
|
-
const people = el.querySelectorAll('a');
|
|
141
|
-
return (people
|
|
142
|
-
// Filter out "more" links
|
|
143
|
-
.filter((x) => x.classNames.length === 0)
|
|
144
|
-
.map((person) => {
|
|
145
|
-
return {
|
|
146
|
-
id: parseIdFromUrl(person.attributes.href),
|
|
147
|
-
name: person.innerText.trim(),
|
|
148
|
-
url: `https://www.csfd.cz${person.attributes.href}`
|
|
149
|
-
};
|
|
150
|
-
}));
|
|
151
|
-
};
|
|
152
|
-
export const getGroup = (el, group) => {
|
|
153
|
-
const creators = el.querySelectorAll('.creators h4');
|
|
154
|
-
const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];
|
|
155
|
-
if (element === null || element === void 0 ? void 0 : element.parentNode) {
|
|
156
|
-
return parsePeople(element.parentNode);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
export const getType = (el) => {
|
|
163
|
-
var _a;
|
|
164
|
-
const type = el.querySelector('.film-header-name .type');
|
|
165
|
-
return ((_a = type === null || type === void 0 ? void 0 : type.innerText) === null || _a === void 0 ? void 0 : _a.replace(/[{()}]/g, '')) || 'film';
|
|
166
|
-
};
|
|
167
|
-
export const getVods = (el) => {
|
|
168
|
-
let vods = [];
|
|
169
|
-
if (el) {
|
|
170
|
-
const buttons = el.querySelectorAll('.box-buttons .button');
|
|
171
|
-
const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));
|
|
172
|
-
vods = buttonsVod.map((btn) => {
|
|
173
|
-
return {
|
|
174
|
-
title: btn.textContent.trim(),
|
|
175
|
-
url: btn.attributes.href
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return vods.length ? vods : [];
|
|
180
|
-
};
|
|
181
|
-
// Get box content
|
|
182
|
-
export const getBoxContent = (el, box) => {
|
|
183
|
-
var _a;
|
|
184
|
-
const headers = el.querySelectorAll('section.box .box-header');
|
|
185
|
-
return (_a = headers.find((header) => header.querySelector('h3').textContent.trim().includes(box))) === null || _a === void 0 ? void 0 : _a.parentNode;
|
|
186
|
-
};
|
|
187
|
-
export const getBoxMovies = (el, boxName) => {
|
|
188
|
-
const movieListItem = [];
|
|
189
|
-
const box = getBoxContent(el, boxName);
|
|
190
|
-
const movieTitleNodes = box === null || box === void 0 ? void 0 : box.querySelectorAll('.article-header .film-title-name');
|
|
191
|
-
if (movieTitleNodes === null || movieTitleNodes === void 0 ? void 0 : movieTitleNodes.length) {
|
|
192
|
-
for (const item of movieTitleNodes) {
|
|
193
|
-
movieListItem.push({
|
|
194
|
-
id: parseIdFromUrl(item.attributes.href),
|
|
195
|
-
title: item.textContent.trim(),
|
|
196
|
-
url: `https://www.csfd.cz${item.attributes.href}`
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return movieListItem;
|
|
201
|
-
};
|
|
202
|
-
export const getPremieres = (el) => {
|
|
203
|
-
var _a, _b;
|
|
204
|
-
const premiereNodes = el.querySelectorAll('.box-premieres li');
|
|
205
|
-
const premiere = [];
|
|
206
|
-
for (const premiereNode of premiereNodes) {
|
|
207
|
-
const title = premiereNode.querySelector('p + span').attributes.title;
|
|
208
|
-
if (title) {
|
|
209
|
-
const [date, ...company] = title === null || title === void 0 ? void 0 : title.split(' ');
|
|
210
|
-
premiere.push({
|
|
211
|
-
country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
|
|
212
|
-
format: (_b = premiereNode.querySelector('p').textContent.trim()) === null || _b === void 0 ? void 0 : _b.split(' od')[0],
|
|
213
|
-
date,
|
|
214
|
-
company: company.join(' ')
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return premiere;
|
|
219
|
-
};
|
|
220
|
-
export const getTags = (el) => {
|
|
221
|
-
const tagsRaw = el.querySelectorAll('.box-content a[href*="/podrobne-vyhledavani/?tag="]');
|
|
222
|
-
return tagsRaw.map((tag) => tag.textContent);
|
|
223
|
-
};
|
|
@@ -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
|
-
};
|