node-csfd-api 2.4.0-next.0 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +4 -1
  2. package/{types/fetchers → fetchers}/index.d.ts +0 -0
  3. package/{cjs/fetchers → fetchers}/index.js +7 -13
  4. package/{types/helpers → helpers}/creator.helper.d.ts +0 -0
  5. package/{cjs/helpers → helpers}/creator.helper.js +0 -0
  6. package/{types/helpers → helpers}/global.helper.d.ts +0 -0
  7. package/{cjs/helpers → helpers}/global.helper.js +8 -3
  8. package/{types/helpers → helpers}/movie.helper.d.ts +2 -0
  9. package/{cjs/helpers → helpers}/movie.helper.js +36 -11
  10. package/{types/helpers → helpers}/search-user.helper.d.ts +0 -0
  11. package/{cjs/helpers → helpers}/search-user.helper.js +0 -0
  12. package/{types/helpers → helpers}/search.helper.d.ts +0 -0
  13. package/{cjs/helpers → helpers}/search.helper.js +0 -0
  14. package/{types/helpers → helpers}/user-ratings.helper.d.ts +0 -0
  15. package/{cjs/helpers → helpers}/user-ratings.helper.js +0 -0
  16. package/{types/index.d.ts → index.d.ts} +0 -0
  17. package/index.js +33 -0
  18. package/{types/interfaces → interfaces}/creator.interface.d.ts +0 -0
  19. package/{cjs/interfaces → interfaces}/creator.interface.js +0 -0
  20. package/{types/interfaces → interfaces}/global.d.ts +0 -0
  21. package/{cjs/interfaces → interfaces}/global.js +0 -0
  22. package/{types/interfaces → interfaces}/movie.interface.d.ts +2 -0
  23. package/{cjs/interfaces → interfaces}/movie.interface.js +0 -0
  24. package/{types/interfaces → interfaces}/search.interface.d.ts +0 -0
  25. package/{cjs/interfaces → interfaces}/search.interface.js +0 -0
  26. package/{types/interfaces → interfaces}/user-ratings.interface.d.ts +0 -0
  27. package/{cjs/interfaces → interfaces}/user-ratings.interface.js +0 -0
  28. package/package.json +9 -10
  29. package/{types/services → services}/creator.service.d.ts +0 -0
  30. package/services/creator.service.js +32 -0
  31. package/{types/services → services}/movie.service.d.ts +0 -0
  32. package/{cjs/services → services}/movie.service.js +12 -21
  33. package/{types/services → services}/search.service.d.ts +0 -0
  34. package/{cjs/services → services}/search.service.js +7 -18
  35. package/{types/services → services}/user-ratings.service.d.ts +0 -0
  36. package/{cjs/services → services}/user-ratings.service.js +25 -36
  37. package/{types/vars.d.ts → vars.d.ts} +0 -0
  38. package/{cjs/vars.js → vars.js} +1 -1
  39. package/cjs/index.js +0 -50
  40. package/cjs/services/creator.service.js +0 -43
  41. package/esm/fetchers/index.js +0 -32
  42. package/esm/helpers/creator.helper.js +0 -72
  43. package/esm/helpers/global.helper.js +0 -51
  44. package/esm/helpers/movie.helper.js +0 -200
  45. package/esm/helpers/search-user.helper.js +0 -15
  46. package/esm/helpers/search.helper.js +0 -38
  47. package/esm/helpers/user-ratings.helper.js +0 -47
  48. package/esm/index.js +0 -46
  49. package/esm/interfaces/creator.interface.js +0 -1
  50. package/esm/interfaces/global.js +0 -1
  51. package/esm/interfaces/movie.interface.js +0 -1
  52. package/esm/interfaces/search.interface.js +0 -1
  53. package/esm/interfaces/user-ratings.interface.js +0 -1
  54. package/esm/services/creator.service.js +0 -39
  55. package/esm/services/movie.service.js +0 -63
  56. package/esm/services/search.service.js +0 -67
  57. package/esm/services/user-ratings.service.js +0 -91
  58. package/esm/vars.js +0 -4
  59. package/types/index.ts +0 -22
package/README.md CHANGED
@@ -60,6 +60,8 @@ csfd.movie(535121).then((movie) => console.log(movie));
60
60
  colorRating: 'good',
61
61
  rating: 73,
62
62
  ratingCount: 6654,
63
+ photo: '//image.pmgstatic.com/cache/resized/w1326/files/images/film/photos/162/980/162980090_bbffbb.jpg',
64
+ trivia: ['Když Henry (Tory Kittles) se svým mladším bratrem...', 'Ve filmu se střídají...'],
63
65
  titlesOther: [
64
66
  { country: 'USA', title: 'Dragged Across Concrete' },
65
67
  { country: 'Kanada', title: 'Dragged Across Concrete' },
@@ -372,7 +374,8 @@ _Note: You can not use both parameters 'includesOnly' and 'excludes'. Parameter
372
374
  - [x] Premieres
373
375
  - [x] Related movies
374
376
  - [x] Similar movies
375
- - [ ] All images
377
+ - [x] Trivia
378
+ - [x] Photo from movie (random)
376
379
  - [ ] Reviews
377
380
  - [ ] OST
378
381
  - [ ] Search
File without changes
@@ -1,16 +1,10 @@
1
1
  "use strict";
2
- // import fetch from 'cross-fetch';
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
4
  };
12
5
  Object.defineProperty(exports, "__esModule", { value: true });
13
6
  exports.fetchPage = void 0;
7
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
14
8
  const USER_AGENTS = [
15
9
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
16
10
  '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',
@@ -20,17 +14,17 @@ const USER_AGENTS = [
20
14
  const headers = {
21
15
  'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
22
16
  };
23
- const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const fetchPage = async (url) => {
24
18
  try {
25
- const response = yield fetch(url, { headers });
19
+ const response = await (0, cross_fetch_1.default)(url, { headers });
26
20
  if (response.status >= 400 && response.status < 600) {
27
21
  throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
28
22
  }
29
- return yield response.text();
23
+ return await response.text();
30
24
  }
31
25
  catch (e) {
32
26
  console.error(e);
33
27
  return 'Error';
34
28
  }
35
- });
29
+ };
36
30
  exports.fetchPage = fetchPage;
File without changes
File without changes
File without changes
@@ -2,9 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseISO8601Duration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0;
4
4
  const parseIdFromUrl = (url) => {
5
- const idSlug = url.split('/')[2];
6
- const id = idSlug.split('-')[0];
7
- return +id;
5
+ if (url) {
6
+ const idSlug = url === null || url === void 0 ? void 0 : url.split('/')[2];
7
+ const id = idSlug === null || idSlug === void 0 ? void 0 : idSlug.split('-')[0];
8
+ return +id || null;
9
+ }
10
+ else {
11
+ return null;
12
+ }
8
13
  };
9
14
  exports.parseIdFromUrl = parseIdFromUrl;
10
15
  const getColor = (cls) => {
@@ -12,6 +12,8 @@ export declare const getYear: (el: string) => number;
12
12
  export declare const getDuration: (jsonLdRaw: string, el: HTMLElement) => number;
13
13
  export declare const getTitlesOther: (el: HTMLElement) => CSFDTitlesOther[];
14
14
  export declare const getPoster: (el: HTMLElement) => string;
15
+ export declare const getRandomPhoto: (el: HTMLElement) => string;
16
+ export declare const getTrivia: (el: HTMLElement) => string[];
15
17
  export declare const getDescriptions: (el: HTMLElement) => string[];
16
18
  export declare const parsePeople: (el: HTMLElement) => CSFDCreator[];
17
19
  export declare const getGroup: (el: HTMLElement, group: CSFDCreatorGroups) => CSFDCreator[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTags = exports.getPremieres = exports.getBoxMovies = exports.getBoxContent = exports.getVods = exports.getType = exports.getGroup = exports.parsePeople = exports.getDescriptions = exports.getPoster = exports.getTitlesOther = exports.getDuration = exports.getYear = exports.getRatingCount = exports.getRating = exports.getColorRating = exports.getOrigins = exports.getGenres = exports.getTitle = exports.getId = void 0;
3
+ exports.getTags = exports.getPremieres = exports.getBoxMovies = exports.getBoxContent = exports.getVods = exports.getType = exports.getGroup = exports.parsePeople = exports.getDescriptions = exports.getTrivia = exports.getRandomPhoto = exports.getPoster = exports.getTitlesOther = exports.getDuration = exports.getYear = exports.getRatingCount = exports.getRating = exports.getColorRating = exports.getOrigins = exports.getGenres = exports.getTitle = exports.getId = void 0;
4
4
  const global_helper_1 = require("./global.helper");
5
5
  const getId = (el) => {
6
6
  const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;
@@ -125,6 +125,28 @@ const getPoster = (el) => {
125
125
  }
126
126
  };
127
127
  exports.getPoster = getPoster;
128
+ const getRandomPhoto = (el) => {
129
+ var _a;
130
+ const imageNode = el.querySelector('.gallery-item picture img');
131
+ const image = (_a = imageNode === null || imageNode === void 0 ? void 0 : imageNode.attributes) === null || _a === void 0 ? void 0 : _a.src;
132
+ if (image) {
133
+ return image.replace(/\/w663\//, '/w1326/');
134
+ }
135
+ else {
136
+ return null;
137
+ }
138
+ };
139
+ exports.getRandomPhoto = getRandomPhoto;
140
+ const getTrivia = (el) => {
141
+ const triviaNodes = el.querySelectorAll('.article-trivia ul li');
142
+ if (triviaNodes === null || triviaNodes === void 0 ? void 0 : triviaNodes.length) {
143
+ return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
144
+ }
145
+ else {
146
+ return null;
147
+ }
148
+ };
149
+ exports.getTrivia = getTrivia;
128
150
  const getDescriptions = (el) => {
129
151
  return el
130
152
  .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
@@ -201,17 +223,20 @@ const getBoxMovies = (el, boxName) => {
201
223
  };
202
224
  exports.getBoxMovies = getBoxMovies;
203
225
  const getPremieres = (el) => {
204
- var _a;
205
- const premieresNode = el.querySelectorAll('.box-premieres li');
226
+ var _a, _b;
227
+ const premiereNodes = el.querySelectorAll('.box-premieres li');
206
228
  const premiere = [];
207
- for (const premiereNode of premieresNode) {
208
- const [date, ...company] = premiereNode.querySelector('p + span').attributes.title.split(' ');
209
- premiere.push({
210
- country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
211
- format: premiereNode.querySelector('p').textContent.trim().split(' od')[0],
212
- date,
213
- company: company.join(' ')
214
- });
229
+ for (const premiereNode of premiereNodes) {
230
+ const title = premiereNode.querySelector('p + span').attributes.title;
231
+ if (title) {
232
+ const [date, ...company] = title === null || title === void 0 ? void 0 : title.split(' ');
233
+ premiere.push({
234
+ country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
235
+ format: (_b = premiereNode.querySelector('p').textContent.trim()) === null || _b === void 0 ? void 0 : _b.split(' od')[0],
236
+ date,
237
+ company: company.join(' ')
238
+ });
239
+ }
215
240
  }
216
241
  return premiere;
217
242
  };
File without changes
File without changes
File without changes
File without changes
File without changes
package/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.csfd = exports.Csfd = void 0;
4
+ const creator_service_1 = require("./services/creator.service");
5
+ const movie_service_1 = require("./services/movie.service");
6
+ const search_service_1 = require("./services/search.service");
7
+ const user_ratings_service_1 = require("./services/user-ratings.service");
8
+ class Csfd {
9
+ constructor(userRatingsService, movieService, creatorService, searchService) {
10
+ this.userRatingsService = userRatingsService;
11
+ this.movieService = movieService;
12
+ this.creatorService = creatorService;
13
+ this.searchService = searchService;
14
+ }
15
+ async userRatings(user, config) {
16
+ return this.userRatingsService.userRatings(user, config);
17
+ }
18
+ async movie(movie) {
19
+ return this.movieService.movie(+movie);
20
+ }
21
+ async creator(creator) {
22
+ return this.creatorService.creator(+creator);
23
+ }
24
+ async search(text) {
25
+ return this.searchService.search(text);
26
+ }
27
+ }
28
+ exports.Csfd = Csfd;
29
+ const movieScraper = new movie_service_1.MovieScraper();
30
+ const userRatingsScraper = new user_ratings_service_1.UserRatingsScraper();
31
+ const creatorScraper = new creator_service_1.CreatorScraper();
32
+ const searchScraper = new search_service_1.SearchScraper();
33
+ exports.csfd = new Csfd(userRatingsScraper, movieScraper, creatorScraper, searchScraper);
File without changes
File without changes
@@ -2,11 +2,13 @@ import { CSFDScreening } from './global';
2
2
  export interface CSFDMovie extends CSFDScreening {
3
3
  rating: number | null;
4
4
  poster: string;
5
+ photo: string;
5
6
  ratingCount: number | null;
6
7
  duration: number | string;
7
8
  titlesOther: CSFDTitlesOther[];
8
9
  origins: string[];
9
10
  descriptions: string[];
11
+ trivia: string[];
10
12
  genres: CSFDGenres[] | string[];
11
13
  creators: CSFDCreators;
12
14
  vod: CSFDVod[];
package/package.json CHANGED
@@ -1,30 +1,29 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "2.4.0-next.0",
3
+ "version": "2.4.2",
4
4
  "description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
5
- "main": "./cjs/index.js",
5
+ "main": "./index.js",
6
6
  "author": "BART! <bart@bartweb.cz>",
7
7
  "scripts": {
8
8
  "start": "tsc -w",
9
9
  "prebuild": "rimraf dist",
10
- "build": "tsc && tsc -p tsconfig-cjs.json && yarn barrels",
11
- "barrels": "barrelsby --delete -c barrels.json",
12
- "postbuild": "npm-prepare-dist -s postinstall -s prepare && yarn fix-paths",
10
+ "build": "tsc",
11
+ "postbuild": "npm-prepare-dist -s postinstall -s prepare",
13
12
  "tsc": "tsc",
14
13
  "demo": "ts-node demo",
15
14
  "lint": "eslint ./src/**/**/* --fix",
16
15
  "test": "jest",
17
- "fix-paths": "yarn json -I -f ./dist/package.json -e \"this.module='./esm/index.js';this.main='./cjs/index.js';this.types='./types/index.d.ts'\"",
18
16
  "publish:next": "yarn && yarn build && yarn test --coverage true && npm publish --folder dist --tag beta",
19
17
  "postversion": "git push && git push --follow-tags",
20
18
  "release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
19
+ "prerelease:beta": "npm version prerelease --preid=beta -m \"chore(update): prelease %s β\"",
21
20
  "release:patch": "git checkout master && npm version patch -m \"chore(update): patch release %s 🐛\"",
22
21
  "release:minor": "git checkout master && npm version minor -m \"chore(update): release %s 🚀\"",
23
22
  "release:major": "git checkout master && npm version major -m \"chore(update): major release %s 💥\""
24
23
  },
25
24
  "dependencies": {
26
25
  "cross-fetch": "^3.1.5",
27
- "node-html-parser": "^5.3.2"
26
+ "node-html-parser": "^5.4.2-0"
28
27
  },
29
28
  "repository": {
30
29
  "url": "git+https://github.com/bartholomej/node-csfd-api.git",
@@ -51,6 +50,6 @@
51
50
  "node": ">= 12"
52
51
  },
53
52
  "license": "MIT",
54
- "module": "./esm/index.js",
55
- "types": "./types/index.d.ts"
56
- }
53
+ "module": "./index.js",
54
+ "types": "./index.d.ts"
55
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreatorScraper = void 0;
4
+ const node_html_parser_1 = require("node-html-parser");
5
+ const fetchers_1 = require("../fetchers");
6
+ const creator_helper_1 = require("../helpers/creator.helper");
7
+ const vars_1 = require("../vars");
8
+ class CreatorScraper {
9
+ async creator(creatorId) {
10
+ const url = (0, vars_1.creatorUrl)(+creatorId);
11
+ const response = await (0, fetchers_1.fetchPage)(url);
12
+ const creatorHtml = (0, node_html_parser_1.parse)(response);
13
+ const asideNode = creatorHtml.querySelector('.creator-about');
14
+ const filmsNode = creatorHtml.querySelector('.creator-filmography');
15
+ this.buildCreator(+creatorId, asideNode, filmsNode);
16
+ return this.person;
17
+ }
18
+ buildCreator(id, asideEl, filmsNode) {
19
+ var _a, _b, _c;
20
+ this.person = {
21
+ id,
22
+ name: (0, creator_helper_1.getName)(asideEl),
23
+ birthday: (_a = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _a === void 0 ? void 0 : _a.birthday,
24
+ birthplace: (_b = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _b === void 0 ? void 0 : _b.birthPlace,
25
+ photo: (0, creator_helper_1.getPhoto)(asideEl),
26
+ age: ((_c = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _c === void 0 ? void 0 : _c.age) || null,
27
+ bio: (0, creator_helper_1.getBio)(asideEl),
28
+ films: (0, creator_helper_1.getFilms)(filmsNode)
29
+ };
30
+ }
31
+ }
32
+ exports.CreatorScraper = CreatorScraper;
File without changes
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.MovieScraper = void 0;
13
4
  const node_html_parser_1 = require("node-html-parser");
@@ -15,18 +6,16 @@ const fetchers_1 = require("../fetchers");
15
6
  const movie_helper_1 = require("../helpers/movie.helper");
16
7
  const vars_1 = require("../vars");
17
8
  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
- });
9
+ async movie(movieId) {
10
+ const url = (0, vars_1.movieUrl)(+movieId);
11
+ const response = await (0, fetchers_1.fetchPage)(url);
12
+ const movieHtml = (0, node_html_parser_1.parse)(response);
13
+ const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');
14
+ const asideNode = movieHtml.querySelector('.aside-movie-profile');
15
+ const movieNode = movieHtml.querySelector('.main-movie-profile');
16
+ const jsonLd = movieHtml.querySelector('script[type="application/ld+json"]').innerText;
17
+ this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);
18
+ return this.film;
30
19
  }
31
20
  buildMovie(movieId, el, asideEl, pageClasses, jsonLd) {
32
21
  this.film = {
@@ -44,6 +33,8 @@ class MovieScraper {
44
33
  ratingCount: (0, movie_helper_1.getRatingCount)(asideEl),
45
34
  titlesOther: (0, movie_helper_1.getTitlesOther)(el),
46
35
  poster: (0, movie_helper_1.getPoster)(el),
36
+ photo: (0, movie_helper_1.getRandomPhoto)(el),
37
+ trivia: (0, movie_helper_1.getTrivia)(el),
47
38
  creators: {
48
39
  directors: (0, movie_helper_1.getGroup)(el, 'Režie'),
49
40
  writers: (0, movie_helper_1.getGroup)(el, 'Scénář'),
File without changes
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SearchScraper = void 0;
13
4
  const node_html_parser_1 = require("node-html-parser");
@@ -17,15 +8,13 @@ const search_user_helper_1 = require("../helpers/search-user.helper");
17
8
  const search_helper_1 = require("../helpers/search.helper");
18
9
  const vars_1 = require("../vars");
19
10
  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
- return this.parseSearch(moviesNode, usersNode);
28
- });
11
+ async search(text) {
12
+ const url = (0, vars_1.searchUrl)(text);
13
+ const response = await (0, fetchers_1.fetchPage)(url);
14
+ const html = (0, node_html_parser_1.parse)(response);
15
+ const moviesNode = html.querySelectorAll('.main-movies article');
16
+ const usersNode = html.querySelectorAll('.main-users article');
17
+ return this.parseSearch(moviesNode, usersNode);
29
18
  }
30
19
  parseSearch(moviesNode, usersNode) {
31
20
  const movies = [];
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.UserRatingsScraper = void 0;
13
4
  const node_html_parser_1 = require("node-html-parser");
@@ -18,36 +9,34 @@ class UserRatingsScraper {
18
9
  constructor() {
19
10
  this.films = [];
20
11
  }
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
- }
12
+ async userRatings(user, config) {
13
+ let allMovies = [];
14
+ const url = (0, vars_1.userRatingsUrl)(user);
15
+ const response = await (0, fetchers_1.fetchPage)(url);
16
+ const items = (0, node_html_parser_1.parse)(response);
17
+ const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
18
+ // Get number of pages
19
+ const pagesNode = items.querySelector('.pagination');
20
+ const pages = +(pagesNode === null || pagesNode === void 0 ? void 0 : pagesNode.childNodes[pagesNode.childNodes.length - 4].rawText) || 1;
21
+ allMovies = this.getPage(config, movies);
22
+ if (config === null || config === void 0 ? void 0 : config.allPages) {
23
+ console.log('User', user, url);
24
+ console.log('Fetching all pages', pages);
25
+ for (let i = 2; i <= pages; i++) {
26
+ console.log('Fetching page', i, 'out of', pages, '...');
27
+ const url = (0, vars_1.userRatingsUrl)(user, i);
28
+ const response = await (0, fetchers_1.fetchPage)(url);
29
+ const items = (0, node_html_parser_1.parse)(response);
30
+ const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
31
+ allMovies = [...this.getPage(config, movies)];
32
+ // Sleep
33
+ if (config.allPagesDelay) {
34
+ await (0, user_ratings_helper_1.sleep)(config.allPagesDelay);
46
35
  }
47
- return allMovies;
48
36
  }
49
37
  return allMovies;
50
- });
38
+ }
39
+ return allMovies;
51
40
  }
52
41
  getPage(config, movies) {
53
42
  var _a, _b, _c, _d;
File without changes
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.searchUrl = exports.creatorUrl = exports.movieUrl = exports.userRatingsUrl = void 0;
4
4
  const userRatingsUrl = (user, page) => `https://www.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/${page ? '?page=' + page : ''}`;
5
5
  exports.userRatingsUrl = userRatingsUrl;
6
- const movieUrl = (movie) => `https://www.csfd.cz/film/${encodeURIComponent(movie)}`;
6
+ const movieUrl = (movie) => `https://www.csfd.cz/film/${encodeURIComponent(movie)}/prehled/`;
7
7
  exports.movieUrl = movieUrl;
8
8
  const creatorUrl = (creator) => `https://www.csfd.cz/tvurce/${encodeURIComponent(creator)}`;
9
9
  exports.creatorUrl = creatorUrl;
package/cjs/index.js DELETED
@@ -1,50 +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.csfd = exports.Csfd = void 0;
13
- const creator_service_1 = require("./services/creator.service");
14
- const movie_service_1 = require("./services/movie.service");
15
- const search_service_1 = require("./services/search.service");
16
- const user_ratings_service_1 = require("./services/user-ratings.service");
17
- class Csfd {
18
- constructor(userRatingsService, movieService, creatorService, searchService) {
19
- this.userRatingsService = userRatingsService;
20
- this.movieService = movieService;
21
- this.creatorService = creatorService;
22
- this.searchService = searchService;
23
- }
24
- userRatings(user, config) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return this.userRatingsService.userRatings(user, config);
27
- });
28
- }
29
- movie(movie) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- return this.movieService.movie(+movie);
32
- });
33
- }
34
- creator(creator) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return this.creatorService.creator(+creator);
37
- });
38
- }
39
- search(text) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return this.searchService.search(text);
42
- });
43
- }
44
- }
45
- exports.Csfd = Csfd;
46
- const movieScraper = new movie_service_1.MovieScraper();
47
- const userRatingsScraper = new user_ratings_service_1.UserRatingsScraper();
48
- const creatorScraper = new creator_service_1.CreatorScraper();
49
- const searchScraper = new search_service_1.SearchScraper();
50
- exports.csfd = new Csfd(userRatingsScraper, movieScraper, creatorScraper, searchScraper);
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CreatorScraper = void 0;
13
- const node_html_parser_1 = require("node-html-parser");
14
- const fetchers_1 = require("../fetchers");
15
- const creator_helper_1 = require("../helpers/creator.helper");
16
- const vars_1 = require("../vars");
17
- class CreatorScraper {
18
- creator(creatorId) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const url = (0, vars_1.creatorUrl)(+creatorId);
21
- const response = yield (0, fetchers_1.fetchPage)(url);
22
- const creatorHtml = (0, node_html_parser_1.parse)(response);
23
- const asideNode = creatorHtml.querySelector('.creator-about');
24
- const filmsNode = creatorHtml.querySelector('.creator-filmography');
25
- this.buildCreator(+creatorId, asideNode, filmsNode);
26
- return this.person;
27
- });
28
- }
29
- buildCreator(id, asideEl, filmsNode) {
30
- var _a, _b, _c;
31
- this.person = {
32
- id,
33
- name: (0, creator_helper_1.getName)(asideEl),
34
- birthday: (_a = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _a === void 0 ? void 0 : _a.birthday,
35
- birthplace: (_b = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _b === void 0 ? void 0 : _b.birthPlace,
36
- photo: (0, creator_helper_1.getPhoto)(asideEl),
37
- age: ((_c = (0, creator_helper_1.getBirthdayInfo)(asideEl)) === null || _c === void 0 ? void 0 : _c.age) || null,
38
- bio: (0, creator_helper_1.getBio)(asideEl),
39
- films: (0, creator_helper_1.getFilms)(filmsNode)
40
- };
41
- }
42
- }
43
- exports.CreatorScraper = CreatorScraper;