node-csfd-api 3.0.0-next.22 → 3.0.0-next.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/{fetchers → cjs/fetchers}/index.js +13 -4
  2. package/{helpers → cjs/helpers}/cinema.helper.js +12 -12
  3. package/{helpers → cjs/helpers}/creator.helper.js +19 -23
  4. package/{helpers → cjs/helpers}/movie.helper.js +44 -46
  5. package/{helpers → cjs/helpers}/search.helper.js +17 -17
  6. package/{helpers → cjs/helpers}/user-ratings.helper.js +16 -17
  7. package/cjs/index.js +58 -0
  8. package/cjs/services/cinema.service.js +45 -0
  9. package/cjs/services/creator.service.js +43 -0
  10. package/cjs/services/movie.service.js +69 -0
  11. package/cjs/services/search.service.js +91 -0
  12. package/cjs/services/user-ratings.service.js +95 -0
  13. package/esm/fetchers/index.js +13 -4
  14. package/esm/helpers/cinema.helper.js +7 -7
  15. package/esm/helpers/creator.helper.js +12 -12
  16. package/esm/helpers/movie.helper.js +23 -23
  17. package/esm/helpers/search.helper.js +8 -8
  18. package/esm/helpers/user-ratings.helper.js +8 -8
  19. package/esm/index.js +29 -10
  20. package/esm/services/cinema.service.js +20 -9
  21. package/esm/services/creator.service.js +27 -16
  22. package/esm/services/movie.service.js +51 -40
  23. package/esm/services/search.service.js +38 -27
  24. package/esm/services/user-ratings.service.js +45 -34
  25. package/package.json +11 -17
  26. package/{helpers → types/helpers}/cinema.helper.d.ts +5 -5
  27. package/types/helpers/creator.helper.d.ts +12 -0
  28. package/types/helpers/movie.helper.d.ts +23 -0
  29. package/types/helpers/search.helper.d.ts +11 -0
  30. package/types/helpers/user-ratings.helper.d.ts +11 -0
  31. package/{esm/types → types}/index.d.ts +1 -1
  32. package/types/index.ts +22 -0
  33. package/{interfaces → types/interfaces}/movie.interface.d.ts +11 -11
  34. package/{interfaces → types/interfaces}/search.interface.d.ts +4 -4
  35. package/{vars.d.ts → types/vars.d.ts} +1 -1
  36. package/esm/types/helpers/cinema.helper.d.ts +0 -18
  37. package/esm/types/helpers/creator.helper.d.ts +0 -17
  38. package/esm/types/helpers/movie.helper.d.ts +0 -25
  39. package/esm/types/helpers/search.helper.d.ts +0 -11
  40. package/esm/types/helpers/user-ratings.helper.d.ts +0 -13
  41. package/esm/types/interfaces/movie.interface.d.ts +0 -66
  42. package/esm/types/interfaces/search.interface.d.ts +0 -27
  43. package/esm/types/vars.d.ts +0 -6
  44. package/fetchers/fetch.polyfill.d.ts +0 -1
  45. package/fetchers/index.d.ts +0 -1
  46. package/helpers/creator.helper.d.ts +0 -17
  47. package/helpers/global.helper.d.ts +0 -17
  48. package/helpers/movie.helper.d.ts +0 -25
  49. package/helpers/search-user.helper.d.ts +0 -5
  50. package/helpers/search.helper.d.ts +0 -11
  51. package/helpers/user-ratings.helper.d.ts +0 -13
  52. package/index.d.ts +0 -24
  53. package/index.js +0 -39
  54. package/interfaces/cinema.interface.d.ts +0 -23
  55. package/interfaces/creator.interface.d.ts +0 -12
  56. package/interfaces/global.d.ts +0 -22
  57. package/interfaces/user-ratings.interface.d.ts +0 -18
  58. package/services/cinema.service.d.ts +0 -6
  59. package/services/cinema.service.js +0 -34
  60. package/services/creator.service.d.ts +0 -6
  61. package/services/creator.service.js +0 -32
  62. package/services/movie.service.d.ts +0 -6
  63. package/services/movie.service.js +0 -58
  64. package/services/search.service.d.ts +0 -5
  65. package/services/search.service.js +0 -80
  66. package/services/user-ratings.service.d.ts +0 -7
  67. package/services/user-ratings.service.js +0 -84
  68. /package/{fetchers → cjs/fetchers}/fetch.polyfill.js +0 -0
  69. /package/{helpers → cjs/helpers}/global.helper.js +0 -0
  70. /package/{helpers → cjs/helpers}/search-user.helper.js +0 -0
  71. /package/{interfaces → cjs/interfaces}/cinema.interface.js +0 -0
  72. /package/{interfaces → cjs/interfaces}/creator.interface.js +0 -0
  73. /package/{interfaces → cjs/interfaces}/global.js +0 -0
  74. /package/{interfaces → cjs/interfaces}/movie.interface.js +0 -0
  75. /package/{interfaces → cjs/interfaces}/search.interface.js +0 -0
  76. /package/{interfaces → cjs/interfaces}/user-ratings.interface.js +0 -0
  77. /package/{vars.js → cjs/vars.js} +0 -0
  78. /package/{esm/types → types}/fetchers/fetch.polyfill.d.ts +0 -0
  79. /package/{esm/types → types}/fetchers/index.d.ts +0 -0
  80. /package/{esm/types → types}/helpers/global.helper.d.ts +0 -0
  81. /package/{esm/types → types}/helpers/search-user.helper.d.ts +0 -0
  82. /package/{esm/types → types}/interfaces/cinema.interface.d.ts +0 -0
  83. /package/{esm/types → types}/interfaces/creator.interface.d.ts +0 -0
  84. /package/{esm/types → types}/interfaces/global.d.ts +0 -0
  85. /package/{esm/types → types}/interfaces/user-ratings.interface.d.ts +0 -0
  86. /package/{esm/types → types}/services/cinema.service.d.ts +0 -0
  87. /package/{esm/types → types}/services/creator.service.d.ts +0 -0
  88. /package/{esm/types → types}/services/movie.service.d.ts +0 -0
  89. /package/{esm/types → types}/services/search.service.d.ts +0 -0
  90. /package/{esm/types → types}/services/user-ratings.service.d.ts +0 -0
@@ -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.getCinemaCoords)(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.getCreatorName)(asideEl),
34
+ birthday: (_a = (0, creator_helper_1.getCreatorBirthdayInfo)(asideEl)) === null || _a === void 0 ? void 0 : _a.birthday,
35
+ birthplace: (_b = (0, creator_helper_1.getCreatorBirthdayInfo)(asideEl)) === null || _b === void 0 ? void 0 : _b.birthPlace,
36
+ photo: (0, creator_helper_1.getCreatorPhoto)(asideEl),
37
+ age: ((_c = (0, creator_helper_1.getCreatorBirthdayInfo)(asideEl)) === null || _c === void 0 ? void 0 : _c.age) || null,
38
+ bio: (0, creator_helper_1.getCreatorBio)(asideEl),
39
+ films: (0, creator_helper_1.getCreatorFilms)(filmsNode)
40
+ };
41
+ }
42
+ }
43
+ exports.CreatorScraper = CreatorScraper;
@@ -0,0 +1,69 @@
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.MovieScraper = void 0;
13
+ const node_html_parser_1 = require("node-html-parser");
14
+ const fetchers_1 = require("../fetchers");
15
+ const movie_helper_1 = require("../helpers/movie.helper");
16
+ const vars_1 = require("../vars");
17
+ class MovieScraper {
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
+ });
30
+ }
31
+ buildMovie(movieId, el, asideEl, pageClasses, jsonLd) {
32
+ this.film = {
33
+ id: movieId,
34
+ title: (0, movie_helper_1.getMovieTitle)(el),
35
+ year: (0, movie_helper_1.getMovieYear)(jsonLd),
36
+ duration: (0, movie_helper_1.getMovieDuration)(jsonLd, el),
37
+ descriptions: (0, movie_helper_1.getMovieDescriptions)(el),
38
+ genres: (0, movie_helper_1.getMovieGenres)(el),
39
+ type: (0, movie_helper_1.getMovieType)(el),
40
+ url: (0, vars_1.movieUrl)(movieId),
41
+ origins: (0, movie_helper_1.getMovieOrigins)(el),
42
+ colorRating: (0, movie_helper_1.getMovieColorRating)(pageClasses),
43
+ rating: (0, movie_helper_1.getMovieRating)(asideEl),
44
+ ratingCount: (0, movie_helper_1.getMovieRatingCount)(asideEl),
45
+ titlesOther: (0, movie_helper_1.getMovieTitlesOther)(el),
46
+ poster: (0, movie_helper_1.getMoviePoster)(el),
47
+ photo: (0, movie_helper_1.getMovieRandomPhoto)(el),
48
+ trivia: (0, movie_helper_1.getMovieTrivia)(el),
49
+ creators: {
50
+ directors: (0, movie_helper_1.getMovieGroup)(el, 'Režie'),
51
+ writers: (0, movie_helper_1.getMovieGroup)(el, 'Scénář'),
52
+ cinematography: (0, movie_helper_1.getMovieGroup)(el, 'Kamera'),
53
+ music: (0, movie_helper_1.getMovieGroup)(el, 'Hudba'),
54
+ actors: (0, movie_helper_1.getMovieGroup)(el, 'Hrají'),
55
+ basedOn: (0, movie_helper_1.getMovieGroup)(el, 'Předloha'),
56
+ producers: (0, movie_helper_1.getMovieGroup)(el, 'Produkce'),
57
+ filmEditing: (0, movie_helper_1.getMovieGroup)(el, 'Střih'),
58
+ costumeDesign: (0, movie_helper_1.getMovieGroup)(el, 'Kostýmy'),
59
+ productionDesign: (0, movie_helper_1.getMovieGroup)(el, 'Scénografie')
60
+ },
61
+ vod: (0, movie_helper_1.getMovieVods)(asideEl),
62
+ tags: (0, movie_helper_1.getMovieTags)(asideEl),
63
+ premieres: (0, movie_helper_1.getMoviePremieres)(asideEl),
64
+ related: (0, movie_helper_1.getMovieBoxMovies)(asideEl, 'Související'),
65
+ similar: (0, movie_helper_1.getMovieBoxMovies)(asideEl, 'Podobné')
66
+ };
67
+ }
68
+ }
69
+ exports.MovieScraper = MovieScraper;
@@ -0,0 +1,91 @@
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.forEach((m) => {
36
+ const url = (0, search_helper_1.getSearchUrl)(m);
37
+ const movie = {
38
+ id: (0, global_helper_1.parseIdFromUrl)(url),
39
+ title: (0, search_helper_1.getSearchTitle)(m),
40
+ year: (0, search_helper_1.getSearchYear)(m),
41
+ url: `https://www.csfd.cz${url}`,
42
+ type: (0, search_helper_1.getSearchType)(m),
43
+ colorRating: (0, search_helper_1.getSearchColorRating)(m),
44
+ poster: (0, search_helper_1.getSearchPoster)(m),
45
+ origins: (0, search_helper_1.getSearchOrigins)(m),
46
+ creators: {
47
+ directors: (0, search_helper_1.parseSearchPeople)(m, 'directors'),
48
+ actors: (0, search_helper_1.parseSearchPeople)(m, 'actors')
49
+ }
50
+ };
51
+ movies.push(movie);
52
+ });
53
+ usersNode.forEach((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.forEach((m) => {
65
+ const url = (0, search_helper_1.getSearchUrl)(m);
66
+ const user = {
67
+ id: (0, global_helper_1.parseIdFromUrl)(url),
68
+ title: (0, search_helper_1.getSearchTitle)(m),
69
+ year: (0, search_helper_1.getSearchYear)(m),
70
+ url: `https://www.csfd.cz${url}`,
71
+ type: (0, search_helper_1.getSearchType)(m),
72
+ colorRating: (0, search_helper_1.getSearchColorRating)(m),
73
+ poster: (0, search_helper_1.getSearchPoster)(m),
74
+ origins: (0, search_helper_1.getSearchOrigins)(m),
75
+ creators: {
76
+ directors: (0, search_helper_1.parseSearchPeople)(m, 'directors'),
77
+ actors: (0, search_helper_1.parseSearchPeople)(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;
@@ -0,0 +1,95 @@
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.getUserRatingType)(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.getUserRatingId)(el),
85
+ title: (0, user_ratings_helper_1.getUserRatingTitle)(el),
86
+ year: (0, user_ratings_helper_1.getUserRatingYear)(el),
87
+ type: (0, user_ratings_helper_1.getUserRatingType)(el),
88
+ url: (0, user_ratings_helper_1.getUserRatingUrl)(el),
89
+ colorRating: (0, user_ratings_helper_1.getUserRatingColorRating)(el),
90
+ userDate: (0, user_ratings_helper_1.getUserRatingDate)(el),
91
+ userRating: (0, user_ratings_helper_1.getUserRating)(el)
92
+ });
93
+ }
94
+ }
95
+ exports.UserRatingsScraper = UserRatingsScraper;
@@ -1,3 +1,12 @@
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
+ };
1
10
  import { fetchSafe } from './fetch.polyfill';
2
11
  const USER_AGENTS = [
3
12
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
@@ -8,16 +17,16 @@ const USER_AGENTS = [
8
17
  const headers = {
9
18
  'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
10
19
  };
11
- export const fetchPage = async (url) => {
20
+ export const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
12
21
  try {
13
- const response = await fetchSafe(url, { headers });
22
+ const response = yield fetchSafe(url, { headers });
14
23
  if (response.status >= 400 && response.status < 600) {
15
24
  throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
16
25
  }
17
- return await response.text();
26
+ return yield response.text();
18
27
  }
19
28
  catch (e) {
20
29
  console.error(e);
21
30
  return 'Error';
22
31
  }
23
- };
32
+ });
@@ -1,5 +1,5 @@
1
1
  import { parseColor, parseIdFromUrl } from './global.helper';
2
- export const getColorRating = (el) => {
2
+ export const getCinemaColorRating = (el) => {
3
3
  return parseColor(el === null || el === void 0 ? void 0 : el.classNames.split(' ').pop());
4
4
  };
5
5
  export const getCinemaId = (el) => {
@@ -7,13 +7,13 @@ export const getCinemaId = (el) => {
7
7
  const id = (_a = el === null || el === void 0 ? void 0 : el.id) === null || _a === void 0 ? void 0 : _a.split('-')[1];
8
8
  return +id;
9
9
  };
10
- export const getId = (url) => {
10
+ export const getCinemaUrlId = (url) => {
11
11
  if (url) {
12
12
  return parseIdFromUrl(url);
13
13
  }
14
14
  return null;
15
15
  };
16
- export const getCoords = (el) => {
16
+ export const getCinemaCoords = (el) => {
17
17
  if (!el)
18
18
  return null;
19
19
  const linkMapsEl = el.querySelector('a[href*="q="]');
@@ -51,18 +51,18 @@ export const getGroupedFilmsByDate = (el) => {
51
51
  var _a, _b, _c;
52
52
  const [date, films] = divs.slice(index, index + 2);
53
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) };
54
+ return { date: dateText, films: getCinemaFilms('', films) };
55
55
  });
56
56
  return getDatesAndFilms;
57
57
  };
58
- export const getFilms = (date, el) => {
58
+ export const getCinemaFilms = (date, el) => {
59
59
  const filmNodes = el.querySelectorAll('.cinema-table tr');
60
60
  const films = filmNodes.map((filmNode) => {
61
61
  var _a, _b, _c, _d;
62
62
  const url = (_a = filmNode.querySelector('td.name h3 a')) === null || _a === void 0 ? void 0 : _a.attributes.href;
63
- const id = getId(url);
63
+ const id = getCinemaUrlId(url);
64
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'));
65
+ const colorRating = getCinemaColorRating(filmNode.querySelector('.name .icon'));
66
66
  const showTimes = (_c = filmNode.querySelectorAll('.td-time')) === null || _c === void 0 ? void 0 : _c.map((x) => x.textContent.trim());
67
67
  const meta = (_d = filmNode.querySelectorAll('.td-title span')) === null || _d === void 0 ? void 0 : _d.map((x) => x.text.trim());
68
68
  return {
@@ -1,17 +1,17 @@
1
1
  import { addProtocol, parseColor, parseIdFromUrl } from './global.helper';
2
- export const getColorRating = (el) => {
2
+ const getCreatorColorRating = (el) => {
3
3
  return parseColor(el === null || el === void 0 ? void 0 : el.classNames.split(' ').pop());
4
4
  };
5
- export const getId = (url) => {
5
+ export const getCreatorId = (url) => {
6
6
  if (url) {
7
7
  return parseIdFromUrl(url);
8
8
  }
9
9
  return null;
10
10
  };
11
- export const getName = (el) => {
11
+ export const getCreatorName = (el) => {
12
12
  return el.querySelector('h1').innerText.trim();
13
13
  };
14
- export const getBirthdayInfo = (el) => {
14
+ export const getCreatorBirthdayInfo = (el) => {
15
15
  var _a, _b;
16
16
  const infoBlock = el.querySelector('h1 + p');
17
17
  const text = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.innerHTML.trim();
@@ -27,33 +27,33 @@ export const getBirthdayInfo = (el) => {
27
27
  const birthPlace = birthPlaceRow ? parseBirthPlace(birthPlaceRow) : '';
28
28
  return { birthday, age, birthPlace };
29
29
  };
30
- export const getBio = (el) => {
30
+ export const getCreatorBio = (el) => {
31
31
  var _a;
32
32
  return ((_a = el.querySelector('.article-content p')) === null || _a === void 0 ? void 0 : _a.text.trim().split('\n')[0].trim()) || null;
33
33
  };
34
- export const getPhoto = (el) => {
34
+ export const getCreatorPhoto = (el) => {
35
35
  const image = el.querySelector('img').attributes.src;
36
36
  return addProtocol(image);
37
37
  };
38
- export const parseBirthday = (text) => {
38
+ const parseBirthday = (text) => {
39
39
  return text.replace(/nar./g, '').trim();
40
40
  };
41
- export const parseAge = (text) => {
41
+ const parseAge = (text) => {
42
42
  return text.trim().replace(/\(/g, '').replace(/let\)/g, '').trim();
43
43
  };
44
- export const parseBirthPlace = (text) => {
44
+ const parseBirthPlace = (text) => {
45
45
  return text.trim().replace(/<br>/g, '').trim();
46
46
  };
47
- export const getFilms = (el) => {
47
+ export const getCreatorFilms = (el) => {
48
48
  var _a;
49
49
  const filmNodes = (_a = el.querySelectorAll('.box')[0]) === null || _a === void 0 ? void 0 : _a.querySelectorAll('table tr');
50
50
  let yearCache;
51
51
  const films = filmNodes.map((filmNode) => {
52
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);
53
+ const id = getCreatorId((_a = filmNode.querySelector('td.name .film-title-name')) === null || _a === void 0 ? void 0 : _a.attributes.href);
54
54
  const title = (_b = filmNode.querySelector('.name')) === null || _b === void 0 ? void 0 : _b.text.trim();
55
55
  const year = +((_c = filmNode.querySelector('.year')) === null || _c === void 0 ? void 0 : _c.text.trim());
56
- const colorRating = getColorRating(filmNode.querySelector('.name .icon'));
56
+ const colorRating = getCreatorColorRating(filmNode.querySelector('.name .icon'));
57
57
  // Cache year from previous film because there is a gap between movies with same year
58
58
  if (year) {
59
59
  yearCache = +year;
@@ -1,24 +1,24 @@
1
1
  import { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl } from './global.helper';
2
- export const getId = (el) => {
2
+ export const getMovieId = (el) => {
3
3
  const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;
4
4
  return parseIdFromUrl(url);
5
5
  };
6
- export const getTitle = (el) => {
6
+ export const getMovieTitle = (el) => {
7
7
  return el.querySelector('h1').innerText.split(`(`)[0].trim();
8
8
  };
9
- export const getGenres = (el) => {
9
+ export const getMovieGenres = (el) => {
10
10
  const genresRaw = el.querySelector('.genres').textContent;
11
11
  return genresRaw.split(' / ');
12
12
  };
13
- export const getOrigins = (el) => {
13
+ export const getMovieOrigins = (el) => {
14
14
  const originsRaw = el.querySelector('.origin').textContent;
15
15
  const origins = originsRaw.split(',')[0];
16
16
  return origins.split(' / ');
17
17
  };
18
- export const getColorRating = (bodyClasses) => {
18
+ export const getMovieColorRating = (bodyClasses) => {
19
19
  return getColor(bodyClasses[1]);
20
20
  };
21
- export const getRating = (el) => {
21
+ export const getMovieRating = (el) => {
22
22
  const ratingRaw = el.querySelector('.film-rating-average').textContent;
23
23
  const rating = ratingRaw === null || ratingRaw === void 0 ? void 0 : ratingRaw.replace(/%/g, '').trim();
24
24
  const ratingInt = parseInt(rating);
@@ -29,7 +29,7 @@ export const getRating = (el) => {
29
29
  return null;
30
30
  }
31
31
  };
32
- export const getRatingCount = (el) => {
32
+ export const getMovieRatingCount = (el) => {
33
33
  var _a;
34
34
  const ratingCountRaw = (_a = el.querySelector('.box-rating-container .counter')) === null || _a === void 0 ? void 0 : _a.textContent;
35
35
  const ratingCount = +(ratingCountRaw === null || ratingCountRaw === void 0 ? void 0 : ratingCountRaw.replace(/[(\s)]/g, ''));
@@ -40,7 +40,7 @@ export const getRatingCount = (el) => {
40
40
  return null;
41
41
  }
42
42
  };
43
- export const getYear = (el) => {
43
+ export const getMovieYear = (el) => {
44
44
  try {
45
45
  const jsonLd = JSON.parse(el);
46
46
  return +jsonLd.dateCreated;
@@ -50,7 +50,7 @@ export const getYear = (el) => {
50
50
  return null;
51
51
  }
52
52
  };
53
- export const getDuration = (jsonLdRaw, el) => {
53
+ export const getMovieDuration = (jsonLdRaw, el) => {
54
54
  let duration = null;
55
55
  try {
56
56
  const jsonLd = JSON.parse(jsonLdRaw);
@@ -77,7 +77,7 @@ export const getDuration = (jsonLdRaw, el) => {
77
77
  }
78
78
  }
79
79
  };
80
- export const getTitlesOther = (el) => {
80
+ export const getMovieTitlesOther = (el) => {
81
81
  const namesNode = el.querySelectorAll('.film-names li');
82
82
  if (!namesNode.length) {
83
83
  return [];
@@ -97,7 +97,7 @@ export const getTitlesOther = (el) => {
97
97
  });
98
98
  return titlesOther.filter((x) => x);
99
99
  };
100
- export const getPoster = (el) => {
100
+ export const getMoviePoster = (el) => {
101
101
  var _a;
102
102
  const poster = el.querySelector('.film-posters img');
103
103
  // Resolve empty image
@@ -116,7 +116,7 @@ export const getPoster = (el) => {
116
116
  return null;
117
117
  }
118
118
  };
119
- export const getRandomPhoto = (el) => {
119
+ export const getMovieRandomPhoto = (el) => {
120
120
  var _a;
121
121
  const imageNode = el.querySelector('.gallery-item picture img');
122
122
  const image = (_a = imageNode === null || imageNode === void 0 ? void 0 : imageNode.attributes) === null || _a === void 0 ? void 0 : _a.src;
@@ -127,7 +127,7 @@ export const getRandomPhoto = (el) => {
127
127
  return null;
128
128
  }
129
129
  };
130
- export const getTrivia = (el) => {
130
+ export const getMovieTrivia = (el) => {
131
131
  const triviaNodes = el.querySelectorAll('.article-trivia ul li');
132
132
  if (triviaNodes === null || triviaNodes === void 0 ? void 0 : triviaNodes.length) {
133
133
  return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
@@ -136,12 +136,12 @@ export const getTrivia = (el) => {
136
136
  return null;
137
137
  }
138
138
  };
139
- export const getDescriptions = (el) => {
139
+ export const getMovieDescriptions = (el) => {
140
140
  return el
141
141
  .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
142
142
  .map((movie) => { var _a; return (_a = movie.textContent) === null || _a === void 0 ? void 0 : _a.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); });
143
143
  };
144
- export const parsePeople = (el) => {
144
+ const parseMoviePeople = (el) => {
145
145
  const people = el.querySelectorAll('a');
146
146
  return (people
147
147
  // Filter out "more" links
@@ -154,22 +154,22 @@ export const parsePeople = (el) => {
154
154
  };
155
155
  }));
156
156
  };
157
- export const getGroup = (el, group) => {
157
+ export const getMovieGroup = (el, group) => {
158
158
  const creators = el.querySelectorAll('.creators h4');
159
159
  const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];
160
160
  if (element === null || element === void 0 ? void 0 : element.parentNode) {
161
- return parsePeople(element.parentNode);
161
+ return parseMoviePeople(element.parentNode);
162
162
  }
163
163
  else {
164
164
  return [];
165
165
  }
166
166
  };
167
- export const getType = (el) => {
167
+ export const getMovieType = (el) => {
168
168
  var _a;
169
169
  const type = el.querySelector('.film-header-name .type');
170
170
  return ((_a = type === null || type === void 0 ? void 0 : type.innerText) === null || _a === void 0 ? void 0 : _a.replace(/[{()}]/g, '')) || 'film';
171
171
  };
172
- export const getVods = (el) => {
172
+ export const getMovieVods = (el) => {
173
173
  let vods = [];
174
174
  if (el) {
175
175
  const buttons = el.querySelectorAll('.box-buttons .button');
@@ -184,12 +184,12 @@ export const getVods = (el) => {
184
184
  return vods.length ? vods : [];
185
185
  };
186
186
  // Get box content
187
- export const getBoxContent = (el, box) => {
187
+ const getBoxContent = (el, box) => {
188
188
  var _a;
189
189
  const headers = el.querySelectorAll('section.box .box-header');
190
190
  return (_a = headers.find((header) => header.querySelector('h3').textContent.trim().includes(box))) === null || _a === void 0 ? void 0 : _a.parentNode;
191
191
  };
192
- export const getBoxMovies = (el, boxName) => {
192
+ export const getMovieBoxMovies = (el, boxName) => {
193
193
  const movieListItem = [];
194
194
  const box = getBoxContent(el, boxName);
195
195
  const movieTitleNodes = box === null || box === void 0 ? void 0 : box.querySelectorAll('.article-header .film-title-name');
@@ -204,7 +204,7 @@ export const getBoxMovies = (el, boxName) => {
204
204
  }
205
205
  return movieListItem;
206
206
  };
207
- export const getPremieres = (el) => {
207
+ export const getMoviePremieres = (el) => {
208
208
  var _a, _b;
209
209
  const premiereNodes = el.querySelectorAll('.box-premieres li');
210
210
  const premiere = [];
@@ -222,7 +222,7 @@ export const getPremieres = (el) => {
222
222
  }
223
223
  return premiere;
224
224
  };
225
- export const getTags = (el) => {
225
+ export const getMovieTags = (el) => {
226
226
  const tagsRaw = el.querySelectorAll('.box-content a[href*="/podrobne-vyhledavani/?tag="]');
227
227
  return tagsRaw.map((tag) => tag.textContent);
228
228
  };