node-csfd-api-racintom 1.7.0 → 1.8.0

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 (111) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintrc.json +33 -0
  3. package/.gitattributes +2 -0
  4. package/.github/FUNDING.yml +8 -0
  5. package/.github/pull_request_template.md +19 -0
  6. package/.github/workflows/main.yml +40 -0
  7. package/.github/workflows/publish.yml +73 -0
  8. package/.github/workflows/test.yml +43 -0
  9. package/.husky/pre-commit +1 -0
  10. package/.idea/codeStyles/Project.xml +72 -0
  11. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  12. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  13. package/.idea/misc.xml +6 -0
  14. package/.idea/modules.xml +8 -0
  15. package/.idea/node-csfd-api.iml +9 -0
  16. package/.idea/prettier.xml +6 -0
  17. package/.idea/vcs.xml +7 -0
  18. package/.nvmrc +1 -0
  19. package/.prettierignore +8 -0
  20. package/.prettierrc +10 -0
  21. package/.vscode/settings.json +16 -0
  22. package/Dockerfile +19 -0
  23. package/demo.ts +35 -0
  24. package/eslint.config.mjs +55 -0
  25. package/package.json +86 -62
  26. package/server.ts +66 -0
  27. package/src/fetchers/fetch.polyfill.ts +7 -0
  28. package/src/fetchers/index.ts +25 -0
  29. package/src/helpers/creator.helper.ts +95 -0
  30. package/src/helpers/global.helper.ts +70 -0
  31. package/src/helpers/movie.helper.ts +276 -0
  32. package/src/helpers/search-user.helper.ts +19 -0
  33. package/src/helpers/search.helper.ts +66 -0
  34. package/src/helpers/user-ratings.helper.ts +62 -0
  35. package/src/index.ts +50 -0
  36. package/src/interfaces/creator.interface.ts +14 -0
  37. package/src/interfaces/global.ts +36 -0
  38. package/src/interfaces/movie.interface.ts +157 -0
  39. package/src/interfaces/search.interface.ts +32 -0
  40. package/src/interfaces/season.interface.ts +12 -0
  41. package/src/interfaces/user-ratings.interface.ts +21 -0
  42. package/src/services/creator.service.ts +34 -0
  43. package/src/services/movie.service.ts +89 -0
  44. package/src/services/search.service.ts +101 -0
  45. package/src/services/season.service.ts +55 -0
  46. package/src/services/user-ratings.service.ts +106 -0
  47. package/src/vars.ts +16 -0
  48. package/tests/creator.test.ts +182 -0
  49. package/tests/fetchers.test.ts +109 -0
  50. package/tests/global.test.ts +35 -0
  51. package/tests/helpers.test.ts +59 -0
  52. package/tests/mocks/creator-actor.html.ts +2244 -0
  53. package/tests/mocks/creator-composer-empty.html.ts +683 -0
  54. package/tests/mocks/creator-director.html.ts +3407 -0
  55. package/tests/mocks/movie1.html.ts +1430 -0
  56. package/tests/mocks/movie2.html.ts +740 -0
  57. package/tests/mocks/movie3.html.ts +1843 -0
  58. package/tests/mocks/movie4.html.ts +1568 -0
  59. package/tests/mocks/search.html.ts +838 -0
  60. package/tests/mocks/series1.html.ts +1540 -0
  61. package/tests/mocks/userRatings.html.ts +1354 -0
  62. package/tests/movie.test.ts +606 -0
  63. package/tests/search.test.ts +379 -0
  64. package/tests/season.test.ts +115 -0
  65. package/tests/services.test.ts +106 -0
  66. package/tests/user-ratings.test.ts +142 -0
  67. package/tests/vars.test.ts +34 -0
  68. package/tsconfig.json +23 -0
  69. package/vitest.config.mts +10 -0
  70. package/fetchers/fetch.polyfill.d.ts +0 -1
  71. package/fetchers/fetch.polyfill.js +0 -9
  72. package/fetchers/index.d.ts +0 -1
  73. package/fetchers/index.js +0 -27
  74. package/helpers/creator.helper.d.ts +0 -17
  75. package/helpers/creator.helper.js +0 -87
  76. package/helpers/global.helper.d.ts +0 -17
  77. package/helpers/global.helper.js +0 -68
  78. package/helpers/movie.helper.d.ts +0 -26
  79. package/helpers/movie.helper.js +0 -270
  80. package/helpers/search-user.helper.d.ts +0 -5
  81. package/helpers/search-user.helper.js +0 -22
  82. package/helpers/search.helper.d.ts +0 -11
  83. package/helpers/search.helper.js +0 -62
  84. package/helpers/user-ratings.helper.d.ts +0 -13
  85. package/helpers/user-ratings.helper.js +0 -61
  86. package/index.d.ts +0 -24
  87. package/index.js +0 -39
  88. package/interfaces/creator.interface.d.ts +0 -12
  89. package/interfaces/creator.interface.js +0 -2
  90. package/interfaces/global.d.ts +0 -22
  91. package/interfaces/global.js +0 -2
  92. package/interfaces/movie.interface.d.ts +0 -73
  93. package/interfaces/movie.interface.js +0 -2
  94. package/interfaces/search.interface.d.ts +0 -27
  95. package/interfaces/search.interface.js +0 -2
  96. package/interfaces/season.interface.d.ts +0 -11
  97. package/interfaces/season.interface.js +0 -2
  98. package/interfaces/user-ratings.interface.d.ts +0 -18
  99. package/interfaces/user-ratings.interface.js +0 -2
  100. package/services/creator.service.d.ts +0 -6
  101. package/services/creator.service.js +0 -32
  102. package/services/movie.service.d.ts +0 -6
  103. package/services/movie.service.js +0 -59
  104. package/services/search.service.d.ts +0 -5
  105. package/services/search.service.js +0 -80
  106. package/services/season.service.d.ts +0 -9
  107. package/services/season.service.js +0 -42
  108. package/services/user-ratings.service.d.ts +0 -7
  109. package/services/user-ratings.service.js +0 -84
  110. package/vars.d.ts +0 -5
  111. package/vars.js +0 -13
@@ -1,270 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSeasonsInfo = 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
- const global_helper_1 = require("./global.helper");
5
- const getId = (el) => {
6
- const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;
7
- return (0, global_helper_1.parseIdFromUrl)(url);
8
- };
9
- exports.getId = getId;
10
- const getTitle = (el) => {
11
- return el.querySelector('h1').innerText.split(`(`)[0].trim();
12
- };
13
- exports.getTitle = getTitle;
14
- const getGenres = (el) => {
15
- const genresRaw = el.querySelector('.genres').textContent;
16
- return genresRaw.split(' / ');
17
- };
18
- exports.getGenres = getGenres;
19
- const getOrigins = (el) => {
20
- const originsRaw = el.querySelector('.origin').textContent;
21
- const origins = originsRaw.split(',')[0];
22
- return origins.split(' / ');
23
- };
24
- exports.getOrigins = getOrigins;
25
- const getColorRating = (bodyClasses) => {
26
- return (0, global_helper_1.getColor)(bodyClasses[1]);
27
- };
28
- exports.getColorRating = getColorRating;
29
- const getRating = (el) => {
30
- const ratingRaw = el.querySelector('.film-rating-average').textContent;
31
- const rating = ratingRaw === null || ratingRaw === void 0 ? void 0 : ratingRaw.replace(/%/g, '').trim();
32
- const ratingInt = parseInt(rating);
33
- if (Number.isInteger(ratingInt)) {
34
- return ratingInt;
35
- }
36
- else {
37
- return null;
38
- }
39
- };
40
- exports.getRating = getRating;
41
- const getRatingCount = (el) => {
42
- var _a;
43
- const ratingCountRaw = (_a = el.querySelector('.box-rating-container .counter')) === null || _a === void 0 ? void 0 : _a.textContent;
44
- const ratingCount = +(ratingCountRaw === null || ratingCountRaw === void 0 ? void 0 : ratingCountRaw.replace(/[(\s)]/g, ''));
45
- if (Number.isInteger(ratingCount)) {
46
- return ratingCount;
47
- }
48
- else {
49
- return null;
50
- }
51
- };
52
- exports.getRatingCount = getRatingCount;
53
- const getYear = (el) => {
54
- try {
55
- const jsonLd = JSON.parse(el);
56
- return +jsonLd.dateCreated;
57
- }
58
- catch (error) {
59
- console.error('node-csfd-api: Error parsing JSON-LD', error);
60
- return null;
61
- }
62
- };
63
- exports.getYear = getYear;
64
- const getDuration = (jsonLdRaw, el) => {
65
- let duration = null;
66
- try {
67
- const jsonLd = JSON.parse(jsonLdRaw);
68
- duration = jsonLd.duration;
69
- return (0, global_helper_1.parseISO8601Duration)(duration);
70
- }
71
- catch (error) {
72
- const origin = el.querySelector('.origin').innerText;
73
- const timeString = origin.split(',');
74
- if (timeString.length > 2) {
75
- // Get last time elelment
76
- const timeString2 = timeString.pop().trim();
77
- // Clean it
78
- const timeRaw = timeString2.split('(')[0].trim();
79
- // Split by minutes and hours
80
- const hoursMinsRaw = timeRaw.split('min')[0];
81
- const hoursMins = hoursMinsRaw.split('h');
82
- // Resolve hours + minutes format
83
- duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];
84
- return duration;
85
- }
86
- else {
87
- return null;
88
- }
89
- }
90
- };
91
- exports.getDuration = getDuration;
92
- const getTitlesOther = (el) => {
93
- const namesNode = el.querySelectorAll('.film-names li');
94
- if (!namesNode.length) {
95
- return [];
96
- }
97
- const titlesOther = namesNode.map((el) => {
98
- const country = el.querySelector('img.flag').attributes.alt;
99
- const title = el.textContent.trim().split('\n')[0];
100
- if (country && title) {
101
- return {
102
- country,
103
- title
104
- };
105
- }
106
- else {
107
- return null;
108
- }
109
- });
110
- return titlesOther.filter((x) => x);
111
- };
112
- exports.getTitlesOther = getTitlesOther;
113
- const getPoster = (el) => {
114
- var _a;
115
- const poster = el.querySelector('.film-posters img');
116
- // Resolve empty image
117
- if (poster) {
118
- if ((_a = poster.classNames) === null || _a === void 0 ? void 0 : _a.includes('empty-image')) {
119
- return null;
120
- }
121
- else {
122
- // Full sized image (not thumb)
123
- const imageThumb = poster.attributes.src.split('?')[0];
124
- const image = imageThumb.replace(/\/w140\//, '/w1080/');
125
- return (0, global_helper_1.addProtocol)(image);
126
- }
127
- }
128
- else {
129
- return null;
130
- }
131
- };
132
- exports.getPoster = getPoster;
133
- const getRandomPhoto = (el) => {
134
- var _a;
135
- const imageNode = el.querySelector('.gallery-item picture img');
136
- const image = (_a = imageNode === null || imageNode === void 0 ? void 0 : imageNode.attributes) === null || _a === void 0 ? void 0 : _a.src;
137
- if (image) {
138
- return image.replace(/\/w663\//, '/w1326/');
139
- }
140
- else {
141
- return null;
142
- }
143
- };
144
- exports.getRandomPhoto = getRandomPhoto;
145
- const getTrivia = (el) => {
146
- const triviaNodes = el.querySelectorAll('.article-trivia ul li');
147
- if (triviaNodes === null || triviaNodes === void 0 ? void 0 : triviaNodes.length) {
148
- return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, ''));
149
- }
150
- else {
151
- return null;
152
- }
153
- };
154
- exports.getTrivia = getTrivia;
155
- const getDescriptions = (el) => {
156
- return el
157
- .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
158
- .map((movie) => { var _a; return (_a = movie.textContent) === null || _a === void 0 ? void 0 : _a.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); });
159
- };
160
- exports.getDescriptions = getDescriptions;
161
- const parsePeople = (el) => {
162
- const people = el.querySelectorAll('a');
163
- return (people
164
- // Filter out "more" links
165
- .filter((x) => x.classNames.length === 0)
166
- .map((person) => {
167
- return {
168
- id: (0, global_helper_1.parseIdFromUrl)(person.attributes.href),
169
- name: person.innerText.trim(),
170
- url: `https://www.csfd.cz${person.attributes.href}`
171
- };
172
- }));
173
- };
174
- exports.parsePeople = parsePeople;
175
- const getGroup = (el, group) => {
176
- const creators = el.querySelectorAll('.creators h4');
177
- const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];
178
- if (element === null || element === void 0 ? void 0 : element.parentNode) {
179
- return (0, exports.parsePeople)(element.parentNode);
180
- }
181
- else {
182
- return [];
183
- }
184
- };
185
- exports.getGroup = getGroup;
186
- const getType = (el) => {
187
- var _a;
188
- const type = el.querySelector('.film-header-name .type');
189
- return ((_a = type === null || type === void 0 ? void 0 : type.innerText) === null || _a === void 0 ? void 0 : _a.replace(/[{()}]/g, '')) || 'film';
190
- };
191
- exports.getType = getType;
192
- const getVods = (el) => {
193
- let vods = [];
194
- if (el) {
195
- const buttons = el.querySelectorAll('.box-buttons .button');
196
- const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));
197
- vods = buttonsVod.map((btn) => {
198
- return {
199
- title: btn.textContent.trim(),
200
- url: btn.attributes.href
201
- };
202
- });
203
- }
204
- return vods.length ? vods : [];
205
- };
206
- exports.getVods = getVods;
207
- // Get box content
208
- const getBoxContent = (el, box) => {
209
- var _a;
210
- const headers = el.querySelectorAll('section.box .box-header');
211
- return (_a = headers.find((header) => header.querySelector('h3').textContent.trim().includes(box))) === null || _a === void 0 ? void 0 : _a.parentNode;
212
- };
213
- exports.getBoxContent = getBoxContent;
214
- const getBoxMovies = (el, boxName) => {
215
- const movieListItem = [];
216
- const box = (0, exports.getBoxContent)(el, boxName);
217
- const movieTitleNodes = box === null || box === void 0 ? void 0 : box.querySelectorAll('.article-header .film-title-name');
218
- if (movieTitleNodes === null || movieTitleNodes === void 0 ? void 0 : movieTitleNodes.length) {
219
- for (const item of movieTitleNodes) {
220
- movieListItem.push({
221
- id: (0, global_helper_1.parseIdFromUrl)(item.attributes.href),
222
- title: item.textContent.trim(),
223
- url: `https://www.csfd.cz${item.attributes.href}`
224
- });
225
- }
226
- }
227
- return movieListItem;
228
- };
229
- exports.getBoxMovies = getBoxMovies;
230
- const getPremieres = (el) => {
231
- var _a, _b;
232
- const premiereNodes = el.querySelectorAll('.box-premieres li');
233
- const premiere = [];
234
- for (const premiereNode of premiereNodes) {
235
- const title = premiereNode.querySelector('p + span').attributes.title;
236
- if (title) {
237
- const [date, ...company] = title === null || title === void 0 ? void 0 : title.split(' ');
238
- premiere.push({
239
- country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
240
- format: (_b = premiereNode.querySelector('p').textContent.trim()) === null || _b === void 0 ? void 0 : _b.split(' od')[0],
241
- date,
242
- company: company.join(' ')
243
- });
244
- }
245
- }
246
- return premiere;
247
- };
248
- exports.getPremieres = getPremieres;
249
- const getTags = (el) => {
250
- const tagsRaw = el.querySelectorAll('.box-content a[href*="/podrobne-vyhledavani/?tag="]');
251
- return tagsRaw.map((tag) => tag.textContent);
252
- };
253
- exports.getTags = getTags;
254
- const getSeasonsInfo = (el) => {
255
- const seasonsList = el.querySelector('.film-episodes-list');
256
- if (seasonsList === null) {
257
- return null;
258
- }
259
- const seasons = seasonsList.querySelectorAll('.film-title');
260
- return seasons.map(season => {
261
- const nameContainer = season.querySelector('.film-title-name');
262
- const infoContainer = season.querySelector('.film-title-info');
263
- return {
264
- linkToDetail: nameContainer.getAttribute('href'),
265
- name: nameContainer.textContent,
266
- additionalInfo: infoContainer.textContent
267
- };
268
- });
269
- };
270
- exports.getSeasonsInfo = getSeasonsInfo;
@@ -1,5 +0,0 @@
1
- import { HTMLElement } from 'node-html-parser';
2
- export declare const getUser: (el: HTMLElement) => string;
3
- export declare const getUserRealName: (el: HTMLElement) => string;
4
- export declare const getAvatar: (el: HTMLElement) => string;
5
- export declare const getUserUrl: (el: HTMLElement) => string;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserUrl = exports.getAvatar = exports.getUserRealName = exports.getUser = void 0;
4
- const global_helper_1 = require("./global.helper");
5
- const getUser = (el) => {
6
- return el.querySelector('.user-title-name').text;
7
- };
8
- exports.getUser = getUser;
9
- const getUserRealName = (el) => {
10
- var _a;
11
- return ((_a = el.querySelector('.user-real-name')) === null || _a === void 0 ? void 0 : _a.text.trim()) || null;
12
- };
13
- exports.getUserRealName = getUserRealName;
14
- const getAvatar = (el) => {
15
- const image = el.querySelector('.article-img img').attributes.src;
16
- return (0, global_helper_1.addProtocol)(image);
17
- };
18
- exports.getAvatar = getAvatar;
19
- const getUserUrl = (el) => {
20
- return el.querySelector('.user-title-name').attributes.href;
21
- };
22
- exports.getUserUrl = getUserUrl;
@@ -1,11 +0,0 @@
1
- import { HTMLElement } from 'node-html-parser';
2
- import { CSFDColorRating, CSFDFilmTypes } from '../interfaces/global';
3
- import { CSFDCreator } from '../interfaces/movie.interface';
4
- export declare const getType: (el: HTMLElement) => CSFDFilmTypes;
5
- export declare const getTitle: (el: HTMLElement) => string;
6
- export declare const getYear: (el: HTMLElement) => number;
7
- export declare const getUrl: (el: HTMLElement) => string;
8
- export declare const getColorRating: (el: HTMLElement) => CSFDColorRating;
9
- export declare const getPoster: (el: HTMLElement) => string;
10
- export declare const getOrigins: (el: HTMLElement) => string[];
11
- export declare const parsePeople: (el: HTMLElement, type: "directors" | "actors") => CSFDCreator[];
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePeople = exports.getOrigins = exports.getPoster = exports.getColorRating = exports.getUrl = exports.getYear = exports.getTitle = exports.getType = void 0;
4
- const global_helper_1 = require("./global.helper");
5
- const getType = (el) => {
6
- const type = el.querySelectorAll('.film-title-info .info')[1];
7
- return ((type === null || type === void 0 ? void 0 : type.innerText.replace(/[{()}]/g, '')) || 'film');
8
- };
9
- exports.getType = getType;
10
- const getTitle = (el) => {
11
- return el.querySelector('.film-title-name').text;
12
- };
13
- exports.getTitle = getTitle;
14
- const getYear = (el) => {
15
- var _a;
16
- return +((_a = el.querySelectorAll('.film-title-info .info')[0]) === null || _a === void 0 ? void 0 : _a.innerText.replace(/[{()}]/g, ''));
17
- };
18
- exports.getYear = getYear;
19
- const getUrl = (el) => {
20
- return el.querySelector('.film-title-name').attributes.href;
21
- };
22
- exports.getUrl = getUrl;
23
- const getColorRating = (el) => {
24
- return (0, global_helper_1.parseColor)(el.querySelector('.article-header i.icon').classNames.split(' ').pop());
25
- };
26
- exports.getColorRating = getColorRating;
27
- const getPoster = (el) => {
28
- const image = el.querySelector('img').attributes.src;
29
- return (0, global_helper_1.addProtocol)(image);
30
- };
31
- exports.getPoster = getPoster;
32
- const getOrigins = (el) => {
33
- var _a, _b;
34
- const originsRaw = (_a = el.querySelector('.article-content p .info')) === null || _a === void 0 ? void 0 : _a.text;
35
- if (!originsRaw)
36
- return [];
37
- const originsAll = (_b = originsRaw === null || originsRaw === void 0 ? void 0 : originsRaw.split(', ')) === null || _b === void 0 ? void 0 : _b[0];
38
- return originsAll === null || originsAll === void 0 ? void 0 : originsAll.split('/').map((country) => country.trim());
39
- };
40
- exports.getOrigins = getOrigins;
41
- const parsePeople = (el, type) => {
42
- let who;
43
- if (type === 'directors')
44
- who = 'Režie:';
45
- if (type === 'actors')
46
- who = 'Hrají:';
47
- const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) => el.textContent.includes(who));
48
- if (peopleNode) {
49
- const people = Array.from(peopleNode.querySelectorAll('a'));
50
- return people.map((person) => {
51
- return {
52
- id: (0, global_helper_1.parseIdFromUrl)(person.attributes.href),
53
- name: person.innerText.trim(),
54
- url: `https://www.csfd.cz${person.attributes.href}`
55
- };
56
- });
57
- }
58
- else {
59
- return [];
60
- }
61
- };
62
- exports.parsePeople = parsePeople;
@@ -1,13 +0,0 @@
1
- import { HTMLElement } from 'node-html-parser';
2
- import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../interfaces/global';
3
- import { Colors } from '../interfaces/user-ratings.interface';
4
- export declare const getId: (el: HTMLElement) => number;
5
- export declare const getUserRating: (el: HTMLElement) => CSFDStars;
6
- export declare const getType: (el: HTMLElement) => CSFDFilmTypes;
7
- export declare const getTitle: (el: HTMLElement) => string;
8
- export declare const getYear: (el: HTMLElement) => number;
9
- export declare const getColorRating: (el: HTMLElement) => CSFDColorRating;
10
- export declare const getDate: (el: HTMLElement) => string;
11
- export declare const getUrl: (el: HTMLElement) => string;
12
- export declare const parseColor: (quality: Colors) => CSFDColorRating;
13
- export declare const sleep: (ms: number) => Promise<unknown>;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = exports.parseColor = exports.getUrl = exports.getDate = exports.getColorRating = exports.getYear = exports.getTitle = exports.getType = exports.getUserRating = exports.getId = void 0;
4
- const global_helper_1 = require("./global.helper");
5
- const getId = (el) => {
6
- const url = el.querySelector('td.name .film-title-name').attributes.href;
7
- return (0, global_helper_1.parseIdFromUrl)(url);
8
- };
9
- exports.getId = getId;
10
- const getUserRating = (el) => {
11
- const ratingText = el.querySelector('td.star-rating-only .stars').classNames.split(' ').pop();
12
- const rating = ratingText.includes('stars-') ? +ratingText.split('-').pop() : 0;
13
- return rating;
14
- };
15
- exports.getUserRating = getUserRating;
16
- const getType = (el) => {
17
- const typeText = el.querySelectorAll('td.name .film-title-info .info');
18
- return (typeText.length > 1 ? typeText[1].text.slice(1, -1) : 'film');
19
- };
20
- exports.getType = getType;
21
- const getTitle = (el) => {
22
- return el.querySelector('td.name .film-title-name').text;
23
- };
24
- exports.getTitle = getTitle;
25
- const getYear = (el) => {
26
- var _a;
27
- return +((_a = el.querySelectorAll('td.name .film-title-info .info')[0]) === null || _a === void 0 ? void 0 : _a.text.slice(1, -1)) || null;
28
- };
29
- exports.getYear = getYear;
30
- const getColorRating = (el) => {
31
- const color = (0, exports.parseColor)(el.querySelector('td.name .icon').classNames.split(' ').pop());
32
- return color;
33
- };
34
- exports.getColorRating = getColorRating;
35
- const getDate = (el) => {
36
- return el.querySelector('td.date-only').text.trim();
37
- };
38
- exports.getDate = getDate;
39
- const getUrl = (el) => {
40
- const url = el.querySelector('td.name .film-title-name').attributes.href;
41
- return `https://www.csfd.cz${url}`;
42
- };
43
- exports.getUrl = getUrl;
44
- const parseColor = (quality) => {
45
- switch (quality) {
46
- case 'lightgrey':
47
- return 'unknown';
48
- case 'red':
49
- return 'good';
50
- case 'blue':
51
- return 'average';
52
- case 'grey':
53
- return 'bad';
54
- default:
55
- return 'unknown';
56
- }
57
- };
58
- exports.parseColor = parseColor;
59
- // Sleep in loop
60
- const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
61
- exports.sleep = sleep;
package/index.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { CSFDCreator } from './interfaces/creator.interface';
2
- import { CSFDMovie } from './interfaces/movie.interface';
3
- import { CSFDSearch } from './interfaces/search.interface';
4
- import { CSFDUserRatingConfig, CSFDUserRatings } from './interfaces/user-ratings.interface';
5
- import { CreatorScraper } from './services/creator.service';
6
- import { MovieScraper } from './services/movie.service';
7
- import { SearchScraper } from './services/search.service';
8
- import { UserRatingsScraper } from './services/user-ratings.service';
9
- import { SeasonScraper } from './services/season.service';
10
- import { CSFDSeason } from './interfaces/season.interface';
11
- export declare class Csfd {
12
- private userRatingsService;
13
- private movieService;
14
- private creatorService;
15
- private searchService;
16
- private seasonService;
17
- constructor(userRatingsService: UserRatingsScraper, movieService: MovieScraper, creatorService: CreatorScraper, searchService: SearchScraper, seasonService: SeasonScraper);
18
- userRatings(user: string | number, config?: CSFDUserRatingConfig): Promise<CSFDUserRatings[]>;
19
- movie(movie: number): Promise<CSFDMovie>;
20
- creator(creator: number): Promise<CSFDCreator>;
21
- search(text: string): Promise<CSFDSearch>;
22
- seasonDetails(url: string): Promise<CSFDSeason>;
23
- }
24
- export declare const csfd: Csfd;
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 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
- const season_service_1 = require("./services/season.service");
9
- class Csfd {
10
- constructor(userRatingsService, movieService, creatorService, searchService, seasonService) {
11
- this.userRatingsService = userRatingsService;
12
- this.movieService = movieService;
13
- this.creatorService = creatorService;
14
- this.searchService = searchService;
15
- this.seasonService = seasonService;
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 seasonDetails(url) {
30
- return this.seasonService.season(url);
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 creatorScraper = new creator_service_1.CreatorScraper();
37
- const searchScraper = new search_service_1.SearchScraper();
38
- const seasonScraper = new season_service_1.SeasonScraper();
39
- exports.csfd = new Csfd(userRatingsScraper, movieScraper, creatorScraper, searchScraper, seasonScraper);
@@ -1,12 +0,0 @@
1
- import { CSFDScreening } from './global';
2
- export interface CSFDCreator {
3
- id: number;
4
- name: string;
5
- birthday: string;
6
- birthplace: string;
7
- photo: string;
8
- age: number | string;
9
- bio: string;
10
- films: CSFDCreatorScreening[];
11
- }
12
- export type CSFDCreatorScreening = Omit<CSFDScreening, 'url' | 'type'>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +0,0 @@
1
- export interface CSFDScreening {
2
- id: number;
3
- title: string;
4
- year: number;
5
- url: string;
6
- type: CSFDFilmTypes;
7
- /**
8
- * Overall aggregated rating. (On the web usually represented by colors).
9
- *
10
- * 'unknown': unknown (gray color)
11
- *
12
- * 'good': 70% – 100 % (red color)
13
- *
14
- * 'average': 30% - 69% (blue color)
15
- *
16
- * 'bad': 0% - 29% (black color)
17
- */
18
- colorRating: CSFDColorRating;
19
- }
20
- export type CSFDColorRating = 'bad' | 'average' | 'good' | 'unknown';
21
- export type CSFDStars = 0 | 1 | 2 | 3 | 4 | 5;
22
- export type CSFDFilmTypes = 'film' | 'TV film' | 'pořad' | 'seriál' | 'divadelní záznam' | 'koncert' | 'série' | 'studentský film' | 'amatérský film' | 'hudební videoklip' | 'epizoda';
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,73 +0,0 @@
1
- import { CSFDScreening } from './global';
2
- export interface CSFDMovie extends CSFDScreening {
3
- rating: number | null;
4
- poster: string;
5
- photo: string;
6
- ratingCount: number | null;
7
- duration: number | string;
8
- titlesOther: CSFDTitlesOther[];
9
- origins: string[];
10
- descriptions: string[];
11
- trivia: string[];
12
- genres: CSFDGenres[] | string[];
13
- creators: CSFDCreators;
14
- vod: CSFDVod[];
15
- tags: string[];
16
- premieres: CSFDPremiere[];
17
- related: CSFDMovieListItem[];
18
- similar: CSFDMovieListItem[];
19
- seasons: CSFDSeasons | null;
20
- }
21
- export type CSFDVodService = 'Netflix' | 'hbogo' | 'Prime Video' | 'Apple TV+' | 'iTunes' | 'KVIFF.TV' | 'Edisonline' | 'o2tv' | 'SledovaniTV' | 'Starmax' | 'DAFilms' | 'FILMY ČESKY A ZADARMO' | 'Youtube Česká filmová klasika' | 'VAPET' | 'VOREL FILM' | 'ivysilani' | 'Google Play' | 'Voyo' | 'DVD';
22
- export interface CSFDVod {
23
- title: CSFDVodService;
24
- url: string;
25
- }
26
- export interface CSFDCreators {
27
- directors: CSFDCreator[];
28
- writers: CSFDCreator[];
29
- cinematography: CSFDCreator[];
30
- music: CSFDCreator[];
31
- actors: CSFDCreator[];
32
- basedOn: CSFDCreator[];
33
- producers: CSFDCreator[];
34
- filmEditing: CSFDCreator[];
35
- costumeDesign: CSFDCreator[];
36
- productionDesign: CSFDCreator[];
37
- }
38
- export interface CSFDTitlesOther {
39
- country: string;
40
- title: string;
41
- }
42
- export interface CSFDCreator {
43
- /**
44
- * CSFD person ID.
45
- *
46
- * You can always assemble url from ID like this:
47
- *
48
- * `https://www.csfd.cz/tvurce/${id}`
49
- */
50
- id: number;
51
- name: string;
52
- url: string;
53
- }
54
- export interface CSFDMovieListItem {
55
- id: number;
56
- title: string;
57
- url: string;
58
- }
59
- export type CSFDGenres = 'Akční' | 'Animovaný' | 'Dobrodružný' | 'Dokumentární' | 'Drama' | 'Experimentální' | 'Fantasy' | 'Film-Noir' | 'Historický' | 'Horor' | 'Hudební' | 'IMAX' | 'Katastrofický' | 'Komedie' | 'Krátkometrážní' | 'Krimi' | 'Loutkový' | 'Muzikál' | 'Mysteriózní' | 'Naučný' | 'Podobenství' | 'Poetický' | 'Pohádka' | 'Povídkový' | 'Psychologický' | 'Publicistický' | 'Reality-TV' | 'Road movie' | 'Rodinný' | 'Romantický' | 'Sci-Fi' | 'Soutěžní' | 'Sportovní' | 'Stand-up' | 'Talk-show' | 'Taneční' | 'Telenovela' | 'Thriller' | 'Válečný' | 'Western' | 'Zábavný' | 'Životopisný';
60
- export type CSFDCreatorGroups = 'Režie' | 'Scénář' | 'Kamera' | 'Hudba' | 'Hrají' | 'Produkce' | 'Střih' | 'Předloha' | 'Scénografie' | 'Kostýmy';
61
- export interface CSFDPremiere {
62
- country: string;
63
- format: string;
64
- date: string;
65
- company: string;
66
- }
67
- export type CSFDBoxContent = 'Související' | 'Podobné';
68
- export type CSFDSeasons = CSFDSeasonInfo[];
69
- export interface CSFDSeasonInfo {
70
- name: string;
71
- linkToDetail: string;
72
- additionalInfo: string;
73
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +0,0 @@
1
- import { CSFDScreening } from './global';
2
- import { CSFDCreator } from './movie.interface';
3
- export interface CSFDSearch {
4
- movies: CSFDSearchMovie[];
5
- tvSeries: CSFDSearchMovie[];
6
- creators: CSFDSearchCreator[];
7
- users: CSFDSearchUser[];
8
- }
9
- export interface CSFDSearchMovie extends CSFDScreening {
10
- poster: string;
11
- origins: string[];
12
- creators: CSFDSearchCreators;
13
- }
14
- export interface CSFDSearchUser {
15
- id: number;
16
- user: string;
17
- userRealName: string;
18
- avatar: string;
19
- url: string;
20
- }
21
- export interface CSFDSearchCreator extends CSFDCreator {
22
- image: string;
23
- }
24
- export interface CSFDSearchCreators {
25
- directors: CSFDCreator[];
26
- actors: CSFDCreator[];
27
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });