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.
Files changed (71) hide show
  1. package/{fetchers → cjs/fetchers}/index.js +13 -4
  2. package/{helpers → cjs/helpers}/cinema.helper.js +6 -6
  3. package/cjs/index.js +58 -0
  4. package/cjs/services/cinema.service.js +45 -0
  5. package/cjs/services/creator.service.js +43 -0
  6. package/{services → cjs/services}/movie.service.js +21 -10
  7. package/{services → cjs/services}/search.service.js +22 -11
  8. package/{services → cjs/services}/user-ratings.service.js +36 -25
  9. package/esm/fetchers/fetch.polyfill.js +6 -0
  10. package/esm/fetchers/index.js +32 -0
  11. package/esm/helpers/cinema.helper.js +93 -0
  12. package/esm/helpers/creator.helper.js +74 -0
  13. package/esm/helpers/global.helper.js +59 -0
  14. package/esm/helpers/movie.helper.js +228 -0
  15. package/esm/helpers/search-user.helper.js +15 -0
  16. package/esm/helpers/search.helper.js +51 -0
  17. package/esm/helpers/user-ratings.helper.js +48 -0
  18. package/esm/index.js +54 -0
  19. package/esm/interfaces/cinema.interface.js +1 -0
  20. package/esm/interfaces/creator.interface.js +1 -0
  21. package/esm/interfaces/global.js +1 -0
  22. package/esm/interfaces/movie.interface.js +1 -0
  23. package/esm/interfaces/search.interface.js +1 -0
  24. package/esm/interfaces/user-ratings.interface.js +1 -0
  25. package/esm/services/cinema.service.js +41 -0
  26. package/esm/services/creator.service.js +39 -0
  27. package/esm/services/movie.service.js +65 -0
  28. package/esm/services/search.service.js +87 -0
  29. package/esm/services/user-ratings.service.js +91 -0
  30. package/esm/vars.js +7 -0
  31. package/package.json +9 -7
  32. package/{helpers → types/helpers}/cinema.helper.d.ts +2 -3
  33. package/{index.d.ts → types/index.d.ts} +1 -1
  34. package/types/index.ts +26 -0
  35. package/index.js +0 -39
  36. package/services/cinema.service.js +0 -34
  37. package/services/creator.service.js +0 -32
  38. /package/{fetchers → cjs/fetchers}/fetch.polyfill.js +0 -0
  39. /package/{helpers → cjs/helpers}/creator.helper.js +0 -0
  40. /package/{helpers → cjs/helpers}/global.helper.js +0 -0
  41. /package/{helpers → cjs/helpers}/movie.helper.js +0 -0
  42. /package/{helpers → cjs/helpers}/search-user.helper.js +0 -0
  43. /package/{helpers → cjs/helpers}/search.helper.js +0 -0
  44. /package/{helpers → cjs/helpers}/user-ratings.helper.js +0 -0
  45. /package/{interfaces → cjs/interfaces}/cinema.interface.js +0 -0
  46. /package/{interfaces → cjs/interfaces}/creator.interface.js +0 -0
  47. /package/{interfaces → cjs/interfaces}/global.js +0 -0
  48. /package/{interfaces → cjs/interfaces}/movie.interface.js +0 -0
  49. /package/{interfaces → cjs/interfaces}/search.interface.js +0 -0
  50. /package/{interfaces → cjs/interfaces}/user-ratings.interface.js +0 -0
  51. /package/{vars.js → cjs/vars.js} +0 -0
  52. /package/{fetchers → types/fetchers}/fetch.polyfill.d.ts +0 -0
  53. /package/{fetchers → types/fetchers}/index.d.ts +0 -0
  54. /package/{helpers → types/helpers}/creator.helper.d.ts +0 -0
  55. /package/{helpers → types/helpers}/global.helper.d.ts +0 -0
  56. /package/{helpers → types/helpers}/movie.helper.d.ts +0 -0
  57. /package/{helpers → types/helpers}/search-user.helper.d.ts +0 -0
  58. /package/{helpers → types/helpers}/search.helper.d.ts +0 -0
  59. /package/{helpers → types/helpers}/user-ratings.helper.d.ts +0 -0
  60. /package/{interfaces → types/interfaces}/cinema.interface.d.ts +0 -0
  61. /package/{interfaces → types/interfaces}/creator.interface.d.ts +0 -0
  62. /package/{interfaces → types/interfaces}/global.d.ts +0 -0
  63. /package/{interfaces → types/interfaces}/movie.interface.d.ts +0 -0
  64. /package/{interfaces → types/interfaces}/search.interface.d.ts +0 -0
  65. /package/{interfaces → types/interfaces}/user-ratings.interface.d.ts +0 -0
  66. /package/{services → types/services}/cinema.service.d.ts +0 -0
  67. /package/{services → types/services}/creator.service.d.ts +0 -0
  68. /package/{services → types/services}/movie.service.d.ts +0 -0
  69. /package/{services → types/services}/search.service.d.ts +0 -0
  70. /package/{services → types/services}/user-ratings.service.d.ts +0 -0
  71. /package/{vars.d.ts → types/vars.d.ts} +0 -0
@@ -0,0 +1,87 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { parse } from 'node-html-parser';
11
+ import { fetchPage } from '../fetchers';
12
+ import { parseIdFromUrl } from '../helpers/global.helper';
13
+ import { getAvatar, getUser, getUserRealName, getUserUrl } from '../helpers/search-user.helper';
14
+ import { getColorRating, getOrigins, getPoster, getTitle, getType, getUrl, getYear, parsePeople } from '../helpers/search.helper';
15
+ import { searchUrl } from '../vars';
16
+ export class SearchScraper {
17
+ search(text) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const url = searchUrl(text);
20
+ const response = yield fetchPage(url);
21
+ const html = parse(response);
22
+ const moviesNode = html.querySelectorAll('.main-movies article');
23
+ const usersNode = html.querySelectorAll('.main-users article');
24
+ const tvSeriesNode = html.querySelectorAll('.main-series article');
25
+ return this.parseSearch(moviesNode, usersNode, tvSeriesNode);
26
+ });
27
+ }
28
+ parseSearch(moviesNode, usersNode, tvSeriesNode) {
29
+ const movies = [];
30
+ const users = [];
31
+ const tvSeries = [];
32
+ moviesNode.forEach((m) => {
33
+ const url = getUrl(m);
34
+ const movie = {
35
+ id: parseIdFromUrl(url),
36
+ title: getTitle(m),
37
+ year: getYear(m),
38
+ url: `https://www.csfd.cz${url}`,
39
+ type: getType(m),
40
+ colorRating: getColorRating(m),
41
+ poster: getPoster(m),
42
+ origins: getOrigins(m),
43
+ creators: {
44
+ directors: parsePeople(m, 'directors'),
45
+ actors: parsePeople(m, 'actors')
46
+ }
47
+ };
48
+ movies.push(movie);
49
+ });
50
+ usersNode.forEach((m) => {
51
+ const url = getUserUrl(m);
52
+ const user = {
53
+ id: parseIdFromUrl(url),
54
+ user: getUser(m),
55
+ userRealName: getUserRealName(m),
56
+ avatar: getAvatar(m),
57
+ url: `https://www.csfd.cz${url}`
58
+ };
59
+ users.push(user);
60
+ });
61
+ tvSeriesNode.forEach((m) => {
62
+ const url = getUrl(m);
63
+ const user = {
64
+ id: parseIdFromUrl(url),
65
+ title: getTitle(m),
66
+ year: getYear(m),
67
+ url: `https://www.csfd.cz${url}`,
68
+ type: getType(m),
69
+ colorRating: getColorRating(m),
70
+ poster: getPoster(m),
71
+ origins: getOrigins(m),
72
+ creators: {
73
+ directors: parsePeople(m, 'directors'),
74
+ actors: parsePeople(m, 'actors')
75
+ }
76
+ };
77
+ tvSeries.push(user);
78
+ });
79
+ const search = {
80
+ movies: movies,
81
+ users: users,
82
+ tvSeries: tvSeries,
83
+ creators: []
84
+ };
85
+ return search;
86
+ }
87
+ }
@@ -0,0 +1,91 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { parse } from 'node-html-parser';
11
+ import { fetchPage } from '../fetchers';
12
+ import { getColorRating, getDate, getId, getTitle, getType, getUrl, getUserRating, getYear, sleep } from '../helpers/user-ratings.helper';
13
+ import { userRatingsUrl } from '../vars';
14
+ export class UserRatingsScraper {
15
+ constructor() {
16
+ this.films = [];
17
+ }
18
+ userRatings(user, config) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ let allMovies = [];
21
+ const url = userRatingsUrl(user);
22
+ const response = yield fetchPage(url);
23
+ const items = parse(response);
24
+ const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
25
+ // Get number of pages
26
+ const pagesNode = items.querySelector('.pagination');
27
+ const pages = +(pagesNode === null || pagesNode === void 0 ? void 0 : pagesNode.childNodes[pagesNode.childNodes.length - 4].rawText) || 1;
28
+ allMovies = this.getPage(config, movies);
29
+ if (config === null || config === void 0 ? void 0 : config.allPages) {
30
+ console.log('User', user, url);
31
+ console.log('Fetching all pages', pages);
32
+ for (let i = 2; i <= pages; i++) {
33
+ console.log('Fetching page', i, 'out of', pages, '...');
34
+ const url = userRatingsUrl(user, i);
35
+ const response = yield fetchPage(url);
36
+ const items = parse(response);
37
+ const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr');
38
+ allMovies = [...this.getPage(config, movies)];
39
+ // Sleep
40
+ if (config.allPagesDelay) {
41
+ yield sleep(config.allPagesDelay);
42
+ }
43
+ }
44
+ return allMovies;
45
+ }
46
+ return allMovies;
47
+ });
48
+ }
49
+ getPage(config, movies) {
50
+ var _a, _b, _c, _d;
51
+ if (config) {
52
+ if (((_a = config.includesOnly) === null || _a === void 0 ? void 0 : _a.length) && ((_b = config.excludes) === null || _b === void 0 ? void 0 : _b.length)) {
53
+ console.warn(`node-csfd-api:
54
+ You can not use both parameters 'includesOnly' and 'excludes'.
55
+ Parameter 'includesOnly' will be used now:`, config.includesOnly);
56
+ }
57
+ }
58
+ for (const el of movies) {
59
+ const type = getType(el);
60
+ // Filtering includesOnly
61
+ if ((_c = config === null || config === void 0 ? void 0 : config.includesOnly) === null || _c === void 0 ? void 0 : _c.length) {
62
+ if (config.includesOnly.some((include) => type === include)) {
63
+ this.buildUserRatings(el);
64
+ }
65
+ // Filter exludes
66
+ }
67
+ else if ((_d = config === null || config === void 0 ? void 0 : config.excludes) === null || _d === void 0 ? void 0 : _d.length) {
68
+ if (!config.excludes.some((exclude) => type === exclude)) {
69
+ this.buildUserRatings(el);
70
+ }
71
+ }
72
+ else {
73
+ // Without filtering
74
+ this.buildUserRatings(el);
75
+ }
76
+ }
77
+ return this.films;
78
+ }
79
+ buildUserRatings(el) {
80
+ this.films.push({
81
+ id: getId(el),
82
+ title: getTitle(el),
83
+ year: getYear(el),
84
+ type: getType(el),
85
+ url: getUrl(el),
86
+ colorRating: getColorRating(el),
87
+ userDate: getDate(el),
88
+ userRating: getUserRating(el)
89
+ });
90
+ }
91
+ }
package/esm/vars.js ADDED
@@ -0,0 +1,7 @@
1
+ export const userRatingsUrl = (user, page) => `https://www.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/${page ? '?page=' + page : ''}`;
2
+ export const movieUrl = (movie) => `https://www.csfd.cz/film/${encodeURIComponent(movie)}/prehled/`;
3
+ export const creatorUrl = (creator) => `https://www.csfd.cz/tvurce/${encodeURIComponent(creator)}`;
4
+ export const cinemasUrl = (district, period) => {
5
+ return `https://www.csfd.cz/kino/?period=${period}&district=${district}`;
6
+ };
7
+ export const searchUrl = (text) => `https://www.csfd.cz/hledat/?q=${encodeURIComponent(text)}`;
package/package.json CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "3.0.0-next.21",
3
+ "version": "3.0.0-next.23",
4
4
  "description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
5
- "main": "./index.js",
5
+ "main": "./cjs/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",
11
- "postbuild": "npm-prepare-dist -s postinstall -s prepare",
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",
12
13
  "tsc": "tsc",
13
14
  "demo": "tsx demo",
14
15
  "lint": "eslint ./src/**/**/* --fix",
15
16
  "test": "vitest",
16
17
  "test:coverage": "yarn test run --coverage",
18
+ "fix-paths": "yarn json -I -f ./dist/package.json -e \"this.module='./esm/index.js';this.main='./cjs/index.js';this.types='./cjs/index.d.ts'\"",
17
19
  "publish:next": "yarn && yarn build && yarn test:coverage && cd dist && npm publish --tag next",
18
20
  "postversion": "git push && git push --follow-tags",
19
21
  "release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
@@ -58,6 +60,6 @@
58
60
  "lint-staged": {
59
61
  "*.ts": "eslint --cache --fix"
60
62
  },
61
- "module": "./index.js",
62
- "types": "./index.d.ts"
63
- }
63
+ "module": "./esm/index.js",
64
+ "types": "./cjs/index.d.ts"
65
+ }
@@ -3,12 +3,11 @@ import { HTMLElement } from 'node-html-parser';
3
3
  import { CSFDColorRating } from '../interfaces/global';
4
4
  export declare const getColorRating: (el: HTMLElement) => CSFDColorRating;
5
5
  export declare const getCinemaId: (el: HTMLElement | null) => number;
6
- export declare const getId: (url: string) => number;
7
- export declare const getName: (el: HTMLElement | null) => string;
6
+ export declare const getId: (url: string) => number | null;
8
7
  export declare const getCoords: (el: HTMLElement | null) => {
9
8
  lat: number;
10
9
  lng: number;
11
- };
10
+ } | null;
12
11
  export declare const getCinemaUrl: (el: HTMLElement | null) => string;
13
12
  export declare const parseCinema: (el: HTMLElement | null) => {
14
13
  city: string;
@@ -19,6 +19,6 @@ export declare class Csfd {
19
19
  movie(movie: number): Promise<CSFDMovie>;
20
20
  creator(creator: number): Promise<CSFDCreator>;
21
21
  search(text: string): Promise<CSFDSearch>;
22
- cinema(district: number, period: CSFDCinemaPeriod): Promise<CSFDCinema[]>;
22
+ cinema(district: number | string, period: CSFDCinemaPeriod): Promise<CSFDCinema[]>;
23
23
  }
24
24
  export declare const csfd: Csfd;
package/types/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+
5
+ export * from "./index";
6
+ export * from "./vars";
7
+ export * from "./fetchers/fetch.polyfill";
8
+ export * from "./fetchers/index";
9
+ export * from "./helpers/cinema.helper";
10
+ export * from "./helpers/creator.helper";
11
+ export * from "./helpers/global.helper";
12
+ export * from "./helpers/movie.helper";
13
+ export * from "./helpers/search-user.helper";
14
+ export * from "./helpers/search.helper";
15
+ export * from "./helpers/user-ratings.helper";
16
+ export * from "./interfaces/cinema.interface";
17
+ export * from "./interfaces/creator.interface";
18
+ export * from "./interfaces/global";
19
+ export * from "./interfaces/movie.interface";
20
+ export * from "./interfaces/search.interface";
21
+ export * from "./interfaces/user-ratings.interface";
22
+ export * from "./services/cinema.service";
23
+ export * from "./services/creator.service";
24
+ export * from "./services/movie.service";
25
+ export * from "./services/search.service";
26
+ export * from "./services/user-ratings.service";
package/index.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.csfd = exports.Csfd = void 0;
4
- const cinema_service_1 = require("./services/cinema.service");
5
- const creator_service_1 = require("./services/creator.service");
6
- const movie_service_1 = require("./services/movie.service");
7
- const search_service_1 = require("./services/search.service");
8
- const user_ratings_service_1 = require("./services/user-ratings.service");
9
- class Csfd {
10
- constructor(userRatingsService, movieService, creatorService, searchService, cinemaService) {
11
- this.userRatingsService = userRatingsService;
12
- this.movieService = movieService;
13
- this.creatorService = creatorService;
14
- this.searchService = searchService;
15
- this.cinemaService = cinemaService;
16
- }
17
- async userRatings(user, config) {
18
- return this.userRatingsService.userRatings(user, config);
19
- }
20
- async movie(movie) {
21
- return this.movieService.movie(+movie);
22
- }
23
- async creator(creator) {
24
- return this.creatorService.creator(+creator);
25
- }
26
- async search(text) {
27
- return this.searchService.search(text);
28
- }
29
- async cinema(district, period) {
30
- return this.cinemaService.cinemas(+district, period);
31
- }
32
- }
33
- exports.Csfd = Csfd;
34
- const movieScraper = new movie_service_1.MovieScraper();
35
- const userRatingsScraper = new user_ratings_service_1.UserRatingsScraper();
36
- const cinemaScraper = new cinema_service_1.CinemaScraper();
37
- const creatorScraper = new creator_service_1.CreatorScraper();
38
- const searchScraper = new search_service_1.SearchScraper();
39
- exports.csfd = new Csfd(userRatingsScraper, movieScraper, creatorScraper, searchScraper, cinemaScraper);
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CinemaScraper = void 0;
4
- const node_html_parser_1 = require("node-html-parser");
5
- const fetchers_1 = require("../fetchers");
6
- const vars_1 = require("../vars");
7
- const cinema_helper_1 = require("./../helpers/cinema.helper");
8
- class CinemaScraper {
9
- async cinemas(district = 1, period = 'today') {
10
- const url = (0, vars_1.cinemasUrl)(district, period);
11
- const response = await (0, fetchers_1.fetchPage)(url);
12
- const cinemasHtml = (0, node_html_parser_1.parse)(response);
13
- const contentNode = cinemasHtml.querySelectorAll('#snippet--cinemas section.box');
14
- this.buildCinemas(contentNode);
15
- return this.cinema;
16
- }
17
- buildCinemas(contentNode) {
18
- const cinemas = [];
19
- contentNode.map((x) => {
20
- var _a, _b;
21
- const cinema = {
22
- id: (0, cinema_helper_1.getCinemaId)(x),
23
- name: (_a = (0, cinema_helper_1.parseCinema)(x)) === null || _a === void 0 ? void 0 : _a.name,
24
- city: (_b = (0, cinema_helper_1.parseCinema)(x)) === null || _b === void 0 ? void 0 : _b.city,
25
- url: (0, cinema_helper_1.getCinemaUrl)(x),
26
- coords: (0, cinema_helper_1.getCoords)(x),
27
- screenings: (0, cinema_helper_1.getGroupedFilmsByDate)(x)
28
- };
29
- cinemas.push(cinema);
30
- });
31
- this.cinema = cinemas;
32
- }
33
- }
34
- exports.CinemaScraper = CinemaScraper;
@@ -1,32 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes