node-csfd-api 3.0.0-next.21 → 3.0.0-next.23
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/{fetchers → cjs/fetchers}/index.js +13 -4
- package/{helpers → cjs/helpers}/cinema.helper.js +6 -6
- package/cjs/index.js +58 -0
- package/cjs/services/cinema.service.js +45 -0
- package/cjs/services/creator.service.js +43 -0
- package/{services → cjs/services}/movie.service.js +21 -10
- package/{services → cjs/services}/search.service.js +22 -11
- package/{services → cjs/services}/user-ratings.service.js +36 -25
- package/esm/fetchers/fetch.polyfill.js +6 -0
- package/esm/fetchers/index.js +32 -0
- package/esm/helpers/cinema.helper.js +93 -0
- package/esm/helpers/creator.helper.js +74 -0
- package/esm/helpers/global.helper.js +59 -0
- package/esm/helpers/movie.helper.js +228 -0
- package/esm/helpers/search-user.helper.js +15 -0
- package/esm/helpers/search.helper.js +51 -0
- package/esm/helpers/user-ratings.helper.js +48 -0
- package/esm/index.js +54 -0
- package/esm/interfaces/cinema.interface.js +1 -0
- package/esm/interfaces/creator.interface.js +1 -0
- package/esm/interfaces/global.js +1 -0
- package/esm/interfaces/movie.interface.js +1 -0
- package/esm/interfaces/search.interface.js +1 -0
- package/esm/interfaces/user-ratings.interface.js +1 -0
- package/esm/services/cinema.service.js +41 -0
- package/esm/services/creator.service.js +39 -0
- package/esm/services/movie.service.js +65 -0
- package/esm/services/search.service.js +87 -0
- package/esm/services/user-ratings.service.js +91 -0
- package/esm/vars.js +7 -0
- package/package.json +9 -7
- package/{helpers → types/helpers}/cinema.helper.d.ts +2 -3
- package/{index.d.ts → types/index.d.ts} +1 -1
- package/types/index.ts +26 -0
- package/index.js +0 -39
- package/services/cinema.service.js +0 -34
- package/services/creator.service.js +0 -32
- /package/{fetchers → cjs/fetchers}/fetch.polyfill.js +0 -0
- /package/{helpers → cjs/helpers}/creator.helper.js +0 -0
- /package/{helpers → cjs/helpers}/global.helper.js +0 -0
- /package/{helpers → cjs/helpers}/movie.helper.js +0 -0
- /package/{helpers → cjs/helpers}/search-user.helper.js +0 -0
- /package/{helpers → cjs/helpers}/search.helper.js +0 -0
- /package/{helpers → cjs/helpers}/user-ratings.helper.js +0 -0
- /package/{interfaces → cjs/interfaces}/cinema.interface.js +0 -0
- /package/{interfaces → cjs/interfaces}/creator.interface.js +0 -0
- /package/{interfaces → cjs/interfaces}/global.js +0 -0
- /package/{interfaces → cjs/interfaces}/movie.interface.js +0 -0
- /package/{interfaces → cjs/interfaces}/search.interface.js +0 -0
- /package/{interfaces → cjs/interfaces}/user-ratings.interface.js +0 -0
- /package/{vars.js → cjs/vars.js} +0 -0
- /package/{fetchers → types/fetchers}/fetch.polyfill.d.ts +0 -0
- /package/{fetchers → types/fetchers}/index.d.ts +0 -0
- /package/{helpers → types/helpers}/creator.helper.d.ts +0 -0
- /package/{helpers → types/helpers}/global.helper.d.ts +0 -0
- /package/{helpers → types/helpers}/movie.helper.d.ts +0 -0
- /package/{helpers → types/helpers}/search-user.helper.d.ts +0 -0
- /package/{helpers → types/helpers}/search.helper.d.ts +0 -0
- /package/{helpers → types/helpers}/user-ratings.helper.d.ts +0 -0
- /package/{interfaces → types/interfaces}/cinema.interface.d.ts +0 -0
- /package/{interfaces → types/interfaces}/creator.interface.d.ts +0 -0
- /package/{interfaces → types/interfaces}/global.d.ts +0 -0
- /package/{interfaces → types/interfaces}/movie.interface.d.ts +0 -0
- /package/{interfaces → types/interfaces}/search.interface.d.ts +0 -0
- /package/{interfaces → types/interfaces}/user-ratings.interface.d.ts +0 -0
- /package/{services → types/services}/cinema.service.d.ts +0 -0
- /package/{services → types/services}/creator.service.d.ts +0 -0
- /package/{services → types/services}/movie.service.d.ts +0 -0
- /package/{services → types/services}/search.service.d.ts +0 -0
- /package/{services → types/services}/user-ratings.service.d.ts +0 -0
- /package/{vars.d.ts → types/vars.d.ts} +0 -0
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.fetchPage = void 0;
|
|
4
13
|
const fetch_polyfill_1 = require("./fetch.polyfill");
|
|
@@ -11,17 +20,17 @@ const USER_AGENTS = [
|
|
|
11
20
|
const headers = {
|
|
12
21
|
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
13
22
|
};
|
|
14
|
-
const fetchPage =
|
|
23
|
+
const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
24
|
try {
|
|
16
|
-
const response =
|
|
25
|
+
const response = yield (0, fetch_polyfill_1.fetchSafe)(url, { headers });
|
|
17
26
|
if (response.status >= 400 && response.status < 600) {
|
|
18
27
|
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
19
28
|
}
|
|
20
|
-
return
|
|
29
|
+
return yield response.text();
|
|
21
30
|
}
|
|
22
31
|
catch (e) {
|
|
23
32
|
console.error(e);
|
|
24
33
|
return 'Error';
|
|
25
34
|
}
|
|
26
|
-
};
|
|
35
|
+
});
|
|
27
36
|
exports.fetchPage = fetchPage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMeta = exports.getFilms = exports.getGroupedFilmsByDate = exports.parseCinema = exports.getCinemaUrl = exports.getCoords = exports.
|
|
3
|
+
exports.parseMeta = exports.getFilms = exports.getGroupedFilmsByDate = exports.parseCinema = exports.getCinemaUrl = exports.getCoords = exports.getId = exports.getCinemaId = exports.getColorRating = void 0;
|
|
4
4
|
const global_helper_1 = require("./global.helper");
|
|
5
5
|
const getColorRating = (el) => {
|
|
6
6
|
return (0, global_helper_1.parseColor)(el === null || el === void 0 ? void 0 : el.classNames.split(' ').pop());
|
|
@@ -19,11 +19,9 @@ const getId = (url) => {
|
|
|
19
19
|
return null;
|
|
20
20
|
};
|
|
21
21
|
exports.getId = getId;
|
|
22
|
-
const getName = (el) => {
|
|
23
|
-
return el.querySelector('h1').innerText.trim();
|
|
24
|
-
};
|
|
25
|
-
exports.getName = getName;
|
|
26
22
|
const getCoords = (el) => {
|
|
23
|
+
if (!el)
|
|
24
|
+
return null;
|
|
27
25
|
const linkMapsEl = el.querySelector('a[href*="q="]');
|
|
28
26
|
if (!linkMapsEl)
|
|
29
27
|
return null;
|
|
@@ -42,6 +40,8 @@ const getCoords = (el) => {
|
|
|
42
40
|
exports.getCoords = getCoords;
|
|
43
41
|
const getCinemaUrl = (el) => {
|
|
44
42
|
var _a, _b;
|
|
43
|
+
if (!el)
|
|
44
|
+
return '';
|
|
45
45
|
return (_b = (_a = el.querySelector('a[title="Přejít na webovou stránku kina"]')) === null || _a === void 0 ? void 0 : _a.attributes.href) !== null && _b !== void 0 ? _b : '';
|
|
46
46
|
};
|
|
47
47
|
exports.getCinemaUrl = getCinemaUrl;
|
|
@@ -59,7 +59,7 @@ const getGroupedFilmsByDate = (el) => {
|
|
|
59
59
|
.map((index) => {
|
|
60
60
|
var _a, _b, _c;
|
|
61
61
|
const [date, films] = divs.slice(index, index + 2);
|
|
62
|
-
const dateText = (_c = (_b = (_a = date === null || date === void 0 ? void 0 : date.firstChild) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c :
|
|
62
|
+
const dateText = (_c = (_b = (_a = date === null || date === void 0 ? void 0 : date.firstChild) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : null;
|
|
63
63
|
return { date: dateText, films: (0, exports.getFilms)('', films) };
|
|
64
64
|
});
|
|
65
65
|
return getDatesAndFilms;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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.csfd = exports.Csfd = void 0;
|
|
13
|
+
const cinema_service_1 = require("./services/cinema.service");
|
|
14
|
+
const creator_service_1 = require("./services/creator.service");
|
|
15
|
+
const movie_service_1 = require("./services/movie.service");
|
|
16
|
+
const search_service_1 = require("./services/search.service");
|
|
17
|
+
const user_ratings_service_1 = require("./services/user-ratings.service");
|
|
18
|
+
class Csfd {
|
|
19
|
+
constructor(userRatingsService, movieService, creatorService, searchService, cinemaService) {
|
|
20
|
+
this.userRatingsService = userRatingsService;
|
|
21
|
+
this.movieService = movieService;
|
|
22
|
+
this.creatorService = creatorService;
|
|
23
|
+
this.searchService = searchService;
|
|
24
|
+
this.cinemaService = cinemaService;
|
|
25
|
+
}
|
|
26
|
+
userRatings(user, config) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return this.userRatingsService.userRatings(user, config);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
movie(movie) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return this.movieService.movie(+movie);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
creator(creator) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return this.creatorService.creator(+creator);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
search(text) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return this.searchService.search(text);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
cinema(district, period) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return this.cinemaService.cinemas(+district, period);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.Csfd = Csfd;
|
|
53
|
+
const movieScraper = new movie_service_1.MovieScraper();
|
|
54
|
+
const userRatingsScraper = new user_ratings_service_1.UserRatingsScraper();
|
|
55
|
+
const cinemaScraper = new cinema_service_1.CinemaScraper();
|
|
56
|
+
const creatorScraper = new creator_service_1.CreatorScraper();
|
|
57
|
+
const searchScraper = new search_service_1.SearchScraper();
|
|
58
|
+
exports.csfd = new Csfd(userRatingsScraper, movieScraper, creatorScraper, searchScraper, cinemaScraper);
|
|
@@ -0,0 +1,45 @@
|
|
|
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() {
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* (district = 1, period = 'today') {
|
|
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.forEach((x) => {
|
|
31
|
+
const cinemaInfo = (0, cinema_helper_1.parseCinema)(x);
|
|
32
|
+
const cinema = {
|
|
33
|
+
id: (0, cinema_helper_1.getCinemaId)(x),
|
|
34
|
+
name: cinemaInfo === null || cinemaInfo === void 0 ? void 0 : cinemaInfo.name,
|
|
35
|
+
city: cinemaInfo === null || cinemaInfo === void 0 ? void 0 : cinemaInfo.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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.MovieScraper = void 0;
|
|
4
13
|
const node_html_parser_1 = require("node-html-parser");
|
|
@@ -6,16 +15,18 @@ const fetchers_1 = require("../fetchers");
|
|
|
6
15
|
const movie_helper_1 = require("../helpers/movie.helper");
|
|
7
16
|
const vars_1 = require("../vars");
|
|
8
17
|
class MovieScraper {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
movie(movieId) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const url = (0, vars_1.movieUrl)(+movieId);
|
|
21
|
+
const response = yield (0, fetchers_1.fetchPage)(url);
|
|
22
|
+
const movieHtml = (0, node_html_parser_1.parse)(response);
|
|
23
|
+
const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');
|
|
24
|
+
const asideNode = movieHtml.querySelector('.aside-movie-profile');
|
|
25
|
+
const movieNode = movieHtml.querySelector('.main-movie-profile');
|
|
26
|
+
const jsonLd = movieHtml.querySelector('script[type="application/ld+json"]').innerText;
|
|
27
|
+
this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);
|
|
28
|
+
return this.film;
|
|
29
|
+
});
|
|
19
30
|
}
|
|
20
31
|
buildMovie(movieId, el, asideEl, pageClasses, jsonLd) {
|
|
21
32
|
this.film = {
|
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.SearchScraper = void 0;
|
|
4
13
|
const node_html_parser_1 = require("node-html-parser");
|
|
@@ -8,20 +17,22 @@ const search_user_helper_1 = require("../helpers/search-user.helper");
|
|
|
8
17
|
const search_helper_1 = require("../helpers/search.helper");
|
|
9
18
|
const vars_1 = require("../vars");
|
|
10
19
|
class SearchScraper {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
});
|
|
19
30
|
}
|
|
20
31
|
parseSearch(moviesNode, usersNode, tvSeriesNode) {
|
|
21
32
|
const movies = [];
|
|
22
33
|
const users = [];
|
|
23
34
|
const tvSeries = [];
|
|
24
|
-
moviesNode.
|
|
35
|
+
moviesNode.forEach((m) => {
|
|
25
36
|
const url = (0, search_helper_1.getUrl)(m);
|
|
26
37
|
const movie = {
|
|
27
38
|
id: (0, global_helper_1.parseIdFromUrl)(url),
|
|
@@ -39,7 +50,7 @@ class SearchScraper {
|
|
|
39
50
|
};
|
|
40
51
|
movies.push(movie);
|
|
41
52
|
});
|
|
42
|
-
usersNode.
|
|
53
|
+
usersNode.forEach((m) => {
|
|
43
54
|
const url = (0, search_user_helper_1.getUserUrl)(m);
|
|
44
55
|
const user = {
|
|
45
56
|
id: (0, global_helper_1.parseIdFromUrl)(url),
|
|
@@ -50,7 +61,7 @@ class SearchScraper {
|
|
|
50
61
|
};
|
|
51
62
|
users.push(user);
|
|
52
63
|
});
|
|
53
|
-
tvSeriesNode.
|
|
64
|
+
tvSeriesNode.forEach((m) => {
|
|
54
65
|
const url = (0, search_helper_1.getUrl)(m);
|
|
55
66
|
const user = {
|
|
56
67
|
id: (0, global_helper_1.parseIdFromUrl)(url),
|
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.UserRatingsScraper = void 0;
|
|
4
13
|
const node_html_parser_1 = require("node-html-parser");
|
|
@@ -9,34 +18,36 @@ class UserRatingsScraper {
|
|
|
9
18
|
constructor() {
|
|
10
19
|
this.films = [];
|
|
11
20
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
}
|
|
35
46
|
}
|
|
47
|
+
return allMovies;
|
|
36
48
|
}
|
|
37
49
|
return allMovies;
|
|
38
|
-
}
|
|
39
|
-
return allMovies;
|
|
50
|
+
});
|
|
40
51
|
}
|
|
41
52
|
getPage(config, movies) {
|
|
42
53
|
var _a, _b, _c, _d;
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
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 getCoords = (el) => {
|
|
17
|
+
if (!el)
|
|
18
|
+
return null;
|
|
19
|
+
const linkMapsEl = el.querySelector('a[href*="q="]');
|
|
20
|
+
if (!linkMapsEl)
|
|
21
|
+
return null;
|
|
22
|
+
const linkMaps = linkMapsEl.getAttribute('href');
|
|
23
|
+
const [_, latLng] = linkMaps.split('q=');
|
|
24
|
+
const coords = latLng.split(',');
|
|
25
|
+
if (coords.length !== 2)
|
|
26
|
+
return null;
|
|
27
|
+
const lat = Number(coords[0]);
|
|
28
|
+
const lng = Number(coords[1]);
|
|
29
|
+
if (Number.isFinite(lat) && Number.isFinite(lng)) {
|
|
30
|
+
return { lat, lng };
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
export const getCinemaUrl = (el) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
if (!el)
|
|
37
|
+
return '';
|
|
38
|
+
return (_b = (_a = el.querySelector('a[title="Přejít na webovou stránku kina"]')) === null || _a === void 0 ? void 0 : _a.attributes.href) !== null && _b !== void 0 ? _b : '';
|
|
39
|
+
};
|
|
40
|
+
export const parseCinema = (el) => {
|
|
41
|
+
const title = el.querySelector('.box-header h2').innerText.trim();
|
|
42
|
+
const [city, name] = title.split(' - ');
|
|
43
|
+
return { city, name };
|
|
44
|
+
};
|
|
45
|
+
export const getGroupedFilmsByDate = (el) => {
|
|
46
|
+
const divs = el.querySelectorAll(':scope > div');
|
|
47
|
+
const getDatesAndFilms = divs
|
|
48
|
+
.map((_, index) => index)
|
|
49
|
+
.filter((index) => index % 2 === 0)
|
|
50
|
+
.map((index) => {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
const [date, films] = divs.slice(index, index + 2);
|
|
53
|
+
const dateText = (_c = (_b = (_a = date === null || date === void 0 ? void 0 : date.firstChild) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : null;
|
|
54
|
+
return { date: dateText, films: getFilms('', films) };
|
|
55
|
+
});
|
|
56
|
+
return getDatesAndFilms;
|
|
57
|
+
};
|
|
58
|
+
export const getFilms = (date, el) => {
|
|
59
|
+
const filmNodes = el.querySelectorAll('.cinema-table tr');
|
|
60
|
+
const films = filmNodes.map((filmNode) => {
|
|
61
|
+
var _a, _b, _c, _d;
|
|
62
|
+
const url = (_a = filmNode.querySelector('td.name h3 a')) === null || _a === void 0 ? void 0 : _a.attributes.href;
|
|
63
|
+
const id = getId(url);
|
|
64
|
+
const title = (_b = filmNode.querySelector('.name h3')) === null || _b === void 0 ? void 0 : _b.text.trim();
|
|
65
|
+
const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
|
|
66
|
+
const showTimes = (_c = filmNode.querySelectorAll('.td-time')) === null || _c === void 0 ? void 0 : _c.map((x) => x.textContent.trim());
|
|
67
|
+
const meta = (_d = filmNode.querySelectorAll('.td-title span')) === null || _d === void 0 ? void 0 : _d.map((x) => x.text.trim());
|
|
68
|
+
return {
|
|
69
|
+
id,
|
|
70
|
+
title,
|
|
71
|
+
url,
|
|
72
|
+
colorRating,
|
|
73
|
+
showTimes,
|
|
74
|
+
meta: parseMeta(meta)
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return films;
|
|
78
|
+
};
|
|
79
|
+
export const parseMeta = (meta) => {
|
|
80
|
+
const metaConvert = [];
|
|
81
|
+
for (const element of meta) {
|
|
82
|
+
if (element === 'T') {
|
|
83
|
+
metaConvert.push('subtitles');
|
|
84
|
+
}
|
|
85
|
+
else if (element === 'D') {
|
|
86
|
+
metaConvert.push('dubbing');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
metaConvert.push(element);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return metaConvert;
|
|
93
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
var _a, _b;
|
|
16
|
+
const infoBlock = el.querySelector('h1 + p');
|
|
17
|
+
const text = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.innerHTML.trim();
|
|
18
|
+
const birthPlaceRow = (_a = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.querySelector('.info-place')) === null || _a === void 0 ? void 0 : _a.innerHTML.trim();
|
|
19
|
+
const ageRow = (_b = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.querySelector('.info')) === null || _b === void 0 ? void 0 : _b.innerHTML.trim();
|
|
20
|
+
let birthday = '';
|
|
21
|
+
if (text) {
|
|
22
|
+
const parts = text.split('\n');
|
|
23
|
+
const birthdayRow = parts.find((x) => x.includes('nar.'));
|
|
24
|
+
birthday = birthdayRow ? parseBirthday(birthdayRow) : '';
|
|
25
|
+
}
|
|
26
|
+
const age = ageRow ? +parseAge(ageRow) : null;
|
|
27
|
+
const birthPlace = birthPlaceRow ? parseBirthPlace(birthPlaceRow) : '';
|
|
28
|
+
return { birthday, age, birthPlace };
|
|
29
|
+
};
|
|
30
|
+
export const getBio = (el) => {
|
|
31
|
+
var _a;
|
|
32
|
+
return ((_a = el.querySelector('.article-content p')) === null || _a === void 0 ? void 0 : _a.text.trim().split('\n')[0].trim()) || null;
|
|
33
|
+
};
|
|
34
|
+
export const getPhoto = (el) => {
|
|
35
|
+
const image = el.querySelector('img').attributes.src;
|
|
36
|
+
return addProtocol(image);
|
|
37
|
+
};
|
|
38
|
+
export const parseBirthday = (text) => {
|
|
39
|
+
return text.replace(/nar./g, '').trim();
|
|
40
|
+
};
|
|
41
|
+
export const parseAge = (text) => {
|
|
42
|
+
return text.trim().replace(/\(/g, '').replace(/let\)/g, '').trim();
|
|
43
|
+
};
|
|
44
|
+
export const parseBirthPlace = (text) => {
|
|
45
|
+
return text.trim().replace(/<br>/g, '').trim();
|
|
46
|
+
};
|
|
47
|
+
export const getFilms = (el) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const filmNodes = (_a = el.querySelectorAll('.box')[0]) === null || _a === void 0 ? void 0 : _a.querySelectorAll('table tr');
|
|
50
|
+
let yearCache;
|
|
51
|
+
const films = filmNodes.map((filmNode) => {
|
|
52
|
+
var _a, _b, _c;
|
|
53
|
+
const id = getId((_a = filmNode.querySelector('td.name .film-title-name')) === null || _a === void 0 ? void 0 : _a.attributes.href);
|
|
54
|
+
const title = (_b = filmNode.querySelector('.name')) === null || _b === void 0 ? void 0 : _b.text.trim();
|
|
55
|
+
const year = +((_c = filmNode.querySelector('.year')) === null || _c === void 0 ? void 0 : _c.text.trim());
|
|
56
|
+
const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
|
|
57
|
+
// Cache year from previous film because there is a gap between movies with same year
|
|
58
|
+
if (year) {
|
|
59
|
+
yearCache = +year;
|
|
60
|
+
}
|
|
61
|
+
if (id && title) {
|
|
62
|
+
return {
|
|
63
|
+
id,
|
|
64
|
+
title,
|
|
65
|
+
year: year || yearCache,
|
|
66
|
+
colorRating
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {};
|
|
70
|
+
});
|
|
71
|
+
// Remove empty objects
|
|
72
|
+
const filmsUnique = films.filter((value) => Object.keys(value).length !== 0);
|
|
73
|
+
return filmsUnique;
|
|
74
|
+
};
|