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.
- package/.editorconfig +13 -0
- package/.eslintrc.json +33 -0
- package/.gitattributes +2 -0
- package/.github/FUNDING.yml +8 -0
- package/.github/pull_request_template.md +19 -0
- package/.github/workflows/main.yml +40 -0
- package/.github/workflows/publish.yml +73 -0
- package/.github/workflows/test.yml +43 -0
- package/.husky/pre-commit +1 -0
- package/.idea/codeStyles/Project.xml +72 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/node-csfd-api.iml +9 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +7 -0
- package/.nvmrc +1 -0
- package/.prettierignore +8 -0
- package/.prettierrc +10 -0
- package/.vscode/settings.json +16 -0
- package/Dockerfile +19 -0
- package/demo.ts +35 -0
- package/eslint.config.mjs +55 -0
- package/package.json +86 -62
- package/server.ts +66 -0
- package/src/fetchers/fetch.polyfill.ts +7 -0
- package/src/fetchers/index.ts +25 -0
- package/src/helpers/creator.helper.ts +95 -0
- package/src/helpers/global.helper.ts +70 -0
- package/src/helpers/movie.helper.ts +276 -0
- package/src/helpers/search-user.helper.ts +19 -0
- package/src/helpers/search.helper.ts +66 -0
- package/src/helpers/user-ratings.helper.ts +62 -0
- package/src/index.ts +50 -0
- package/src/interfaces/creator.interface.ts +14 -0
- package/src/interfaces/global.ts +36 -0
- package/src/interfaces/movie.interface.ts +157 -0
- package/src/interfaces/search.interface.ts +32 -0
- package/src/interfaces/season.interface.ts +12 -0
- package/src/interfaces/user-ratings.interface.ts +21 -0
- package/src/services/creator.service.ts +34 -0
- package/src/services/movie.service.ts +89 -0
- package/src/services/search.service.ts +101 -0
- package/src/services/season.service.ts +55 -0
- package/src/services/user-ratings.service.ts +106 -0
- package/src/vars.ts +16 -0
- package/tests/creator.test.ts +182 -0
- package/tests/fetchers.test.ts +109 -0
- package/tests/global.test.ts +35 -0
- package/tests/helpers.test.ts +59 -0
- package/tests/mocks/creator-actor.html.ts +2244 -0
- package/tests/mocks/creator-composer-empty.html.ts +683 -0
- package/tests/mocks/creator-director.html.ts +3407 -0
- package/tests/mocks/movie1.html.ts +1430 -0
- package/tests/mocks/movie2.html.ts +740 -0
- package/tests/mocks/movie3.html.ts +1843 -0
- package/tests/mocks/movie4.html.ts +1568 -0
- package/tests/mocks/search.html.ts +838 -0
- package/tests/mocks/series1.html.ts +1540 -0
- package/tests/mocks/userRatings.html.ts +1354 -0
- package/tests/movie.test.ts +606 -0
- package/tests/search.test.ts +379 -0
- package/tests/season.test.ts +115 -0
- package/tests/services.test.ts +106 -0
- package/tests/user-ratings.test.ts +142 -0
- package/tests/vars.test.ts +34 -0
- package/tsconfig.json +23 -0
- package/vitest.config.mts +10 -0
- package/fetchers/fetch.polyfill.d.ts +0 -1
- package/fetchers/fetch.polyfill.js +0 -9
- package/fetchers/index.d.ts +0 -1
- package/fetchers/index.js +0 -27
- package/helpers/creator.helper.d.ts +0 -17
- package/helpers/creator.helper.js +0 -87
- package/helpers/global.helper.d.ts +0 -17
- package/helpers/global.helper.js +0 -68
- package/helpers/movie.helper.d.ts +0 -26
- package/helpers/movie.helper.js +0 -270
- package/helpers/search-user.helper.d.ts +0 -5
- package/helpers/search-user.helper.js +0 -22
- package/helpers/search.helper.d.ts +0 -11
- package/helpers/search.helper.js +0 -62
- package/helpers/user-ratings.helper.d.ts +0 -13
- package/helpers/user-ratings.helper.js +0 -61
- package/index.d.ts +0 -24
- package/index.js +0 -39
- package/interfaces/creator.interface.d.ts +0 -12
- package/interfaces/creator.interface.js +0 -2
- package/interfaces/global.d.ts +0 -22
- package/interfaces/global.js +0 -2
- package/interfaces/movie.interface.d.ts +0 -73
- package/interfaces/movie.interface.js +0 -2
- package/interfaces/search.interface.d.ts +0 -27
- package/interfaces/search.interface.js +0 -2
- package/interfaces/season.interface.d.ts +0 -11
- package/interfaces/season.interface.js +0 -2
- package/interfaces/user-ratings.interface.d.ts +0 -18
- package/interfaces/user-ratings.interface.js +0 -2
- package/services/creator.service.d.ts +0 -6
- package/services/creator.service.js +0 -32
- package/services/movie.service.d.ts +0 -6
- package/services/movie.service.js +0 -59
- package/services/search.service.d.ts +0 -5
- package/services/search.service.js +0 -80
- package/services/season.service.d.ts +0 -9
- package/services/season.service.js +0 -42
- package/services/user-ratings.service.d.ts +0 -7
- package/services/user-ratings.service.js +0 -84
- package/vars.d.ts +0 -5
- package/vars.js +0 -13
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { HTMLElement, parse } from 'node-html-parser';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import {
|
|
4
|
+
getColorRating,
|
|
5
|
+
getDate,
|
|
6
|
+
getId,
|
|
7
|
+
getTitle,
|
|
8
|
+
getType,
|
|
9
|
+
getUrl,
|
|
10
|
+
getUserRating,
|
|
11
|
+
getYear
|
|
12
|
+
} from '../src/helpers/user-ratings.helper';
|
|
13
|
+
import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../src/interfaces/global';
|
|
14
|
+
import { userRatingsMock } from './mocks/userRatings.html';
|
|
15
|
+
|
|
16
|
+
const items = parse(userRatingsMock);
|
|
17
|
+
const movies: HTMLElement[] = items.querySelectorAll('.box-user-rating .table-container tbody tr');
|
|
18
|
+
|
|
19
|
+
describe('Get Ratings', () => {
|
|
20
|
+
test('First rating', () => {
|
|
21
|
+
const movie = getUserRating(movies[0]);
|
|
22
|
+
expect(movie).toEqual<CSFDStars>(4);
|
|
23
|
+
});
|
|
24
|
+
test('Last rating', () => {
|
|
25
|
+
const movie = getUserRating(movies[movies.length - 1]);
|
|
26
|
+
expect(movie).toEqual<CSFDStars>(3);
|
|
27
|
+
});
|
|
28
|
+
// TODO
|
|
29
|
+
// test('Zero Rating', () => {
|
|
30
|
+
// const movie = getUserRating(movies[5]);
|
|
31
|
+
// expect(movie).toEqual<CSFDStars>(0);
|
|
32
|
+
// });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('Get ID', () => {
|
|
36
|
+
test('First ID', () => {
|
|
37
|
+
const movie = getId(movies[0]);
|
|
38
|
+
expect(movie).toEqual<number>(1254361);
|
|
39
|
+
});
|
|
40
|
+
test('Last ID', () => {
|
|
41
|
+
const movie = getId(movies[movies.length - 1]);
|
|
42
|
+
expect(movie).toEqual<number>(1169425);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('Get type', () => {
|
|
47
|
+
test('Film', () => {
|
|
48
|
+
const movie = getType(movies[0]);
|
|
49
|
+
expect(movie).toEqual<CSFDFilmTypes>('film');
|
|
50
|
+
});
|
|
51
|
+
test('TV series', () => {
|
|
52
|
+
const movie = getType(movies[23]);
|
|
53
|
+
expect(movie).toEqual<CSFDFilmTypes>('seriál');
|
|
54
|
+
});
|
|
55
|
+
test('Episode', () => {
|
|
56
|
+
const movie = getType(movies[4]);
|
|
57
|
+
expect(movie).toEqual<CSFDFilmTypes>('epizoda');
|
|
58
|
+
});
|
|
59
|
+
// test('TV film', () => {
|
|
60
|
+
// const movie = getType(movies[18]);
|
|
61
|
+
// expect(movie).toEqual<CSFDFilmTypes>('TV film');
|
|
62
|
+
// });
|
|
63
|
+
// test('Pořad', () => {
|
|
64
|
+
// const movie = getType(movies[6]);
|
|
65
|
+
// expect(movie).toEqual<CSFDFilmTypes>('pořad');
|
|
66
|
+
// });
|
|
67
|
+
test('Amateur film', () => {
|
|
68
|
+
const movie = getType(movies[31]);
|
|
69
|
+
expect(movie).toEqual<CSFDFilmTypes>('amatérský film');
|
|
70
|
+
});
|
|
71
|
+
test('Season', () => {
|
|
72
|
+
const movie = getType(movies[11]);
|
|
73
|
+
expect(movie).toEqual<CSFDFilmTypes>('série');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('Get title', () => {
|
|
78
|
+
test('First title', () => {
|
|
79
|
+
const movie = getTitle(movies[0]);
|
|
80
|
+
expect(movie).toEqual<string>('Stutz');
|
|
81
|
+
});
|
|
82
|
+
test('Last title', () => {
|
|
83
|
+
const movie = getTitle(movies[movies.length - 1]);
|
|
84
|
+
expect(movie).toEqual<string>('Kouření způsobuje kašel');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('Get year', () => {
|
|
89
|
+
test('First year', () => {
|
|
90
|
+
const movie = getYear(movies[0]);
|
|
91
|
+
expect(movie).toEqual<number>(2022);
|
|
92
|
+
});
|
|
93
|
+
test('Some year', () => {
|
|
94
|
+
const movie = getYear(movies[7]);
|
|
95
|
+
expect(movie).toEqual<number>(2016);
|
|
96
|
+
});
|
|
97
|
+
test('Almost last year', () => {
|
|
98
|
+
const movie = getYear(movies[movies.length - 7]);
|
|
99
|
+
expect(movie).toEqual<number>(2000);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('Get color rating', () => {
|
|
104
|
+
// test('Black', () => {
|
|
105
|
+
// const movie = getColorRating(movies[7]);
|
|
106
|
+
// expect(movie).toEqual<CSFDColorRating>('bad');
|
|
107
|
+
// });
|
|
108
|
+
// test('Gray', () => {
|
|
109
|
+
// const movie = getColorRating(movies[29]);
|
|
110
|
+
// expect(movie).toEqual<CSFDColorRating>('unknown');
|
|
111
|
+
// });
|
|
112
|
+
test('Blue', () => {
|
|
113
|
+
const movie = getColorRating(movies[3]);
|
|
114
|
+
expect(movie).toEqual<CSFDColorRating>('average');
|
|
115
|
+
});
|
|
116
|
+
test('Red', () => {
|
|
117
|
+
const movie = getColorRating(movies[1]);
|
|
118
|
+
expect(movie).toEqual<CSFDColorRating>('good');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('Get date', () => {
|
|
123
|
+
test('First date', () => {
|
|
124
|
+
const movie = getDate(movies[0]);
|
|
125
|
+
expect(movie).toEqual<string>('16.12.2022');
|
|
126
|
+
});
|
|
127
|
+
test('Last date', () => {
|
|
128
|
+
const movie = getDate(movies[movies.length - 1]);
|
|
129
|
+
expect(movie).toEqual<string>('05.07.2022');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('Get Url', () => {
|
|
134
|
+
test('First url', () => {
|
|
135
|
+
const movie = getUrl(movies[0]);
|
|
136
|
+
expect(movie).toEqual<string>('https://www.csfd.cz/film/1254361-stutz/');
|
|
137
|
+
});
|
|
138
|
+
test('Last url', () => {
|
|
139
|
+
const movie = getUrl(movies[movies.length - 1]);
|
|
140
|
+
expect(movie).toEqual<string>('https://www.csfd.cz/film/1169425-koureni-zpusobuje-kasel/');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { creatorUrl, movieUrl, searchUrl, userRatingsUrl } from '../src/vars';
|
|
3
|
+
|
|
4
|
+
describe('Vars User Ratings', () => {
|
|
5
|
+
test('Assemble User rating url', () => {
|
|
6
|
+
const url = userRatingsUrl('912-bart');
|
|
7
|
+
expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/');
|
|
8
|
+
});
|
|
9
|
+
test('Assemble User rating. Page 2', () => {
|
|
10
|
+
const url = userRatingsUrl('912-bart', 2);
|
|
11
|
+
expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/?page=2');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('Vars Movies', () => {
|
|
16
|
+
test('Assemble movieUrl', () => {
|
|
17
|
+
const url = movieUrl(535121);
|
|
18
|
+
expect(url).toBe('https://www.csfd.cz/film/535121/prehled/');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('Vars Search', () => {
|
|
23
|
+
test('Assemble searchUrl', () => {
|
|
24
|
+
const url = searchUrl('matrix');
|
|
25
|
+
expect(url).toBe('https://www.csfd.cz/hledat/?q=matrix');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('Vars Creator', () => {
|
|
30
|
+
test('Assemble creatorUrl', () => {
|
|
31
|
+
const url = creatorUrl('1');
|
|
32
|
+
expect(url).toBe('https://www.csfd.cz/tvurce/1');
|
|
33
|
+
});
|
|
34
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2017",
|
|
4
|
+
"lib": ["dom"],
|
|
5
|
+
"types": ["node"],
|
|
6
|
+
"baseUrl": "./src",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"module": "commonjs",
|
|
9
|
+
"strictNullChecks": false,
|
|
10
|
+
"sourceMap": false,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"pretty": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"alwaysStrict": true,
|
|
18
|
+
"noImplicitAny": true,
|
|
19
|
+
"noImplicitReturns": true
|
|
20
|
+
},
|
|
21
|
+
"include": ["src"],
|
|
22
|
+
"exclude": ["dist/**/*", "*/tests/**/*"]
|
|
23
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const fetchSafe: typeof fetch;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchSafe = void 0;
|
|
4
|
-
// Check if `fetch` is available in global scope (nodejs 18+) or in window (browser). If not, use cross-fetch polyfill.
|
|
5
|
-
const cross_fetch_1 = require("cross-fetch");
|
|
6
|
-
exports.fetchSafe = (typeof fetch === 'function' && fetch) || // ServiceWorker fetch (Cloud Functions + Chrome extension)
|
|
7
|
-
(typeof global === 'object' && global.fetch) || // Node.js 18+ fetch
|
|
8
|
-
(typeof window !== 'undefined' && window.fetch) || // Browser fetch
|
|
9
|
-
cross_fetch_1.fetch; // Polyfill fetch
|
package/fetchers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const fetchPage: (url: string) => Promise<string>;
|
package/fetchers/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchPage = void 0;
|
|
4
|
-
const fetch_polyfill_1 = require("./fetch.polyfill");
|
|
5
|
-
const USER_AGENTS = [
|
|
6
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
|
|
7
|
-
'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',
|
|
8
|
-
'Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36',
|
|
9
|
-
'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36'
|
|
10
|
-
];
|
|
11
|
-
const headers = {
|
|
12
|
-
'User-Agent': USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)]
|
|
13
|
-
};
|
|
14
|
-
const fetchPage = async (url) => {
|
|
15
|
-
try {
|
|
16
|
-
const response = await (0, fetch_polyfill_1.fetchSafe)(url, { headers });
|
|
17
|
-
if (response.status >= 400 && response.status < 600) {
|
|
18
|
-
throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
19
|
-
}
|
|
20
|
-
return await response.text();
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
console.error(e);
|
|
24
|
-
return 'Error';
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
exports.fetchPage = fetchPage;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { HTMLElement } from 'node-html-parser';
|
|
2
|
-
import { CSFDCreatorScreening } from '../interfaces/creator.interface';
|
|
3
|
-
import { CSFDColorRating } from '../interfaces/global';
|
|
4
|
-
export declare const getColorRating: (el: HTMLElement) => CSFDColorRating;
|
|
5
|
-
export declare const getId: (url: string) => number;
|
|
6
|
-
export declare const getName: (el: HTMLElement | null) => string;
|
|
7
|
-
export declare const getBirthdayInfo: (el: HTMLElement | null) => {
|
|
8
|
-
birthday: string;
|
|
9
|
-
age: number;
|
|
10
|
-
birthPlace: string;
|
|
11
|
-
};
|
|
12
|
-
export declare const getBio: (el: HTMLElement | null) => string;
|
|
13
|
-
export declare const getPhoto: (el: HTMLElement | null) => string;
|
|
14
|
-
export declare const parseBirthday: (text: string) => any;
|
|
15
|
-
export declare const parseAge: (text: string) => any;
|
|
16
|
-
export declare const parseBirthPlace: (text: string) => any;
|
|
17
|
-
export declare const getFilms: (el: HTMLElement | null) => CSFDCreatorScreening[];
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFilms = exports.parseBirthPlace = exports.parseAge = exports.parseBirthday = exports.getPhoto = exports.getBio = exports.getBirthdayInfo = exports.getName = exports.getId = exports.getColorRating = void 0;
|
|
4
|
-
const global_helper_1 = require("./global.helper");
|
|
5
|
-
const getColorRating = (el) => {
|
|
6
|
-
return (0, global_helper_1.parseColor)(el === null || el === void 0 ? void 0 : el.classNames.split(' ').pop());
|
|
7
|
-
};
|
|
8
|
-
exports.getColorRating = getColorRating;
|
|
9
|
-
const getId = (url) => {
|
|
10
|
-
if (url) {
|
|
11
|
-
return (0, global_helper_1.parseIdFromUrl)(url);
|
|
12
|
-
}
|
|
13
|
-
return null;
|
|
14
|
-
};
|
|
15
|
-
exports.getId = getId;
|
|
16
|
-
const getName = (el) => {
|
|
17
|
-
return el.querySelector('h1').innerText.trim();
|
|
18
|
-
};
|
|
19
|
-
exports.getName = getName;
|
|
20
|
-
const getBirthdayInfo = (el) => {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const infoBlock = el.querySelector('h1 + p');
|
|
23
|
-
const text = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.innerHTML.trim();
|
|
24
|
-
const birthPlaceRow = (_a = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.querySelector('.info-place')) === null || _a === void 0 ? void 0 : _a.innerHTML.trim();
|
|
25
|
-
const ageRow = (_b = infoBlock === null || infoBlock === void 0 ? void 0 : infoBlock.querySelector('.info')) === null || _b === void 0 ? void 0 : _b.innerHTML.trim();
|
|
26
|
-
let birthday = '';
|
|
27
|
-
if (text) {
|
|
28
|
-
const parts = text.split('\n');
|
|
29
|
-
const birthdayRow = parts.find((x) => x.includes('nar.'));
|
|
30
|
-
birthday = birthdayRow ? (0, exports.parseBirthday)(birthdayRow) : '';
|
|
31
|
-
}
|
|
32
|
-
const age = ageRow ? +(0, exports.parseAge)(ageRow) : null;
|
|
33
|
-
const birthPlace = birthPlaceRow ? (0, exports.parseBirthPlace)(birthPlaceRow) : '';
|
|
34
|
-
return { birthday, age, birthPlace };
|
|
35
|
-
};
|
|
36
|
-
exports.getBirthdayInfo = getBirthdayInfo;
|
|
37
|
-
const getBio = (el) => {
|
|
38
|
-
var _a;
|
|
39
|
-
return ((_a = el.querySelector('.article-content p')) === null || _a === void 0 ? void 0 : _a.text.trim().split('\n')[0].trim()) || null;
|
|
40
|
-
};
|
|
41
|
-
exports.getBio = getBio;
|
|
42
|
-
const getPhoto = (el) => {
|
|
43
|
-
const image = el.querySelector('img').attributes.src;
|
|
44
|
-
return (0, global_helper_1.addProtocol)(image);
|
|
45
|
-
};
|
|
46
|
-
exports.getPhoto = getPhoto;
|
|
47
|
-
const parseBirthday = (text) => {
|
|
48
|
-
return text.replace(/nar./g, '').trim();
|
|
49
|
-
};
|
|
50
|
-
exports.parseBirthday = parseBirthday;
|
|
51
|
-
const parseAge = (text) => {
|
|
52
|
-
return text.trim().replace(/\(/g, '').replace(/let\)/g, '').trim();
|
|
53
|
-
};
|
|
54
|
-
exports.parseAge = parseAge;
|
|
55
|
-
const parseBirthPlace = (text) => {
|
|
56
|
-
return text.trim().replace(/<br>/g, '').trim();
|
|
57
|
-
};
|
|
58
|
-
exports.parseBirthPlace = parseBirthPlace;
|
|
59
|
-
const getFilms = (el) => {
|
|
60
|
-
var _a;
|
|
61
|
-
const filmNodes = (_a = el.querySelectorAll('.box')[0]) === null || _a === void 0 ? void 0 : _a.querySelectorAll('table tr');
|
|
62
|
-
let yearCache;
|
|
63
|
-
const films = filmNodes.map((filmNode) => {
|
|
64
|
-
var _a, _b, _c;
|
|
65
|
-
const id = (0, exports.getId)((_a = filmNode.querySelector('td.name .film-title-name')) === null || _a === void 0 ? void 0 : _a.attributes.href);
|
|
66
|
-
const title = (_b = filmNode.querySelector('.name')) === null || _b === void 0 ? void 0 : _b.text.trim();
|
|
67
|
-
const year = +((_c = filmNode.querySelector('.year')) === null || _c === void 0 ? void 0 : _c.text.trim());
|
|
68
|
-
const colorRating = (0, exports.getColorRating)(filmNode.querySelector('.name .icon'));
|
|
69
|
-
// Cache year from previous film because there is a gap between movies with same year
|
|
70
|
-
if (year) {
|
|
71
|
-
yearCache = +year;
|
|
72
|
-
}
|
|
73
|
-
if (id && title) {
|
|
74
|
-
return {
|
|
75
|
-
id,
|
|
76
|
-
title,
|
|
77
|
-
year: year || yearCache,
|
|
78
|
-
colorRating
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return {};
|
|
82
|
-
});
|
|
83
|
-
// Remove empty objects
|
|
84
|
-
const filmsUnique = films.filter((value) => Object.keys(value).length !== 0);
|
|
85
|
-
return filmsUnique;
|
|
86
|
-
};
|
|
87
|
-
exports.getFilms = getFilms;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CSFDColorRating } from '../interfaces/global';
|
|
2
|
-
import { Colors } from '../interfaces/user-ratings.interface';
|
|
3
|
-
export declare const parseIdFromUrl: (url: string) => number;
|
|
4
|
-
export declare const getColor: (cls: string) => CSFDColorRating;
|
|
5
|
-
export declare const parseColor: (quality: Colors) => CSFDColorRating;
|
|
6
|
-
export declare const addProtocol: (url: string) => string;
|
|
7
|
-
export declare const getDuration: (matches: any[]) => {
|
|
8
|
-
sign: string;
|
|
9
|
-
years: any;
|
|
10
|
-
months: any;
|
|
11
|
-
weeks: any;
|
|
12
|
-
days: any;
|
|
13
|
-
hours: any;
|
|
14
|
-
minutes: any;
|
|
15
|
-
seconds: any;
|
|
16
|
-
};
|
|
17
|
-
export declare const parseISO8601Duration: (iso: string) => number;
|
package/helpers/global.helper.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseISO8601Duration = exports.getDuration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0;
|
|
4
|
-
const parseIdFromUrl = (url) => {
|
|
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
|
-
}
|
|
13
|
-
};
|
|
14
|
-
exports.parseIdFromUrl = parseIdFromUrl;
|
|
15
|
-
const getColor = (cls) => {
|
|
16
|
-
switch (cls) {
|
|
17
|
-
case 'page-lightgrey':
|
|
18
|
-
return 'unknown';
|
|
19
|
-
case 'page-red':
|
|
20
|
-
return 'good';
|
|
21
|
-
case 'page-blue':
|
|
22
|
-
return 'average';
|
|
23
|
-
case 'page-grey':
|
|
24
|
-
return 'bad';
|
|
25
|
-
default:
|
|
26
|
-
return 'unknown';
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.getColor = getColor;
|
|
30
|
-
const parseColor = (quality) => {
|
|
31
|
-
switch (quality) {
|
|
32
|
-
case 'lightgrey':
|
|
33
|
-
return 'unknown';
|
|
34
|
-
case 'red':
|
|
35
|
-
return 'good';
|
|
36
|
-
case 'blue':
|
|
37
|
-
return 'average';
|
|
38
|
-
case 'grey':
|
|
39
|
-
return 'bad';
|
|
40
|
-
default:
|
|
41
|
-
return 'unknown';
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
exports.parseColor = parseColor;
|
|
45
|
-
const addProtocol = (url) => {
|
|
46
|
-
return url.startsWith('//') ? 'https:' + url : url;
|
|
47
|
-
};
|
|
48
|
-
exports.addProtocol = addProtocol;
|
|
49
|
-
const getDuration = (matches) => {
|
|
50
|
-
return {
|
|
51
|
-
sign: matches[1] === undefined ? '+' : '-',
|
|
52
|
-
years: matches[2] === undefined ? 0 : matches[2],
|
|
53
|
-
months: matches[3] === undefined ? 0 : matches[3],
|
|
54
|
-
weeks: matches[4] === undefined ? 0 : matches[4],
|
|
55
|
-
days: matches[5] === undefined ? 0 : matches[5],
|
|
56
|
-
hours: matches[6] === undefined ? 0 : matches[6],
|
|
57
|
-
minutes: matches[7] === undefined ? 0 : matches[7],
|
|
58
|
-
seconds: matches[8] === undefined ? 0 : matches[8]
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
exports.getDuration = getDuration;
|
|
62
|
-
const parseISO8601Duration = (iso) => {
|
|
63
|
-
const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
|
|
64
|
-
const matches = iso.match(iso8601DurationRegex);
|
|
65
|
-
const duration = (0, exports.getDuration)(matches);
|
|
66
|
-
return +duration.minutes;
|
|
67
|
-
};
|
|
68
|
-
exports.parseISO8601Duration = parseISO8601Duration;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { HTMLElement } from 'node-html-parser';
|
|
2
|
-
import { CSFDColorRating } from '../interfaces/global';
|
|
3
|
-
import { CSFDBoxContent, CSFDCreator, CSFDCreatorGroups, CSFDGenres, CSFDMovieListItem, CSFDPremiere, CSFDSeasons, CSFDTitlesOther, CSFDVod } from '../interfaces/movie.interface';
|
|
4
|
-
export declare const getId: (el: HTMLElement) => number;
|
|
5
|
-
export declare const getTitle: (el: HTMLElement) => string;
|
|
6
|
-
export declare const getGenres: (el: HTMLElement) => CSFDGenres[];
|
|
7
|
-
export declare const getOrigins: (el: HTMLElement) => string[];
|
|
8
|
-
export declare const getColorRating: (bodyClasses: string[]) => CSFDColorRating;
|
|
9
|
-
export declare const getRating: (el: HTMLElement) => number;
|
|
10
|
-
export declare const getRatingCount: (el: HTMLElement) => number;
|
|
11
|
-
export declare const getYear: (el: string) => number;
|
|
12
|
-
export declare const getDuration: (jsonLdRaw: string, el: HTMLElement) => number;
|
|
13
|
-
export declare const getTitlesOther: (el: HTMLElement) => CSFDTitlesOther[];
|
|
14
|
-
export declare const getPoster: (el: HTMLElement | null) => string;
|
|
15
|
-
export declare const getRandomPhoto: (el: HTMLElement | null) => string;
|
|
16
|
-
export declare const getTrivia: (el: HTMLElement | null) => string[];
|
|
17
|
-
export declare const getDescriptions: (el: HTMLElement) => string[];
|
|
18
|
-
export declare const parsePeople: (el: HTMLElement) => CSFDCreator[];
|
|
19
|
-
export declare const getGroup: (el: HTMLElement, group: CSFDCreatorGroups) => CSFDCreator[];
|
|
20
|
-
export declare const getType: (el: HTMLElement) => string;
|
|
21
|
-
export declare const getVods: (el: HTMLElement | null) => CSFDVod[];
|
|
22
|
-
export declare const getBoxContent: (el: HTMLElement, box: string) => HTMLElement;
|
|
23
|
-
export declare const getBoxMovies: (el: HTMLElement, boxName: CSFDBoxContent) => CSFDMovieListItem[];
|
|
24
|
-
export declare const getPremieres: (el: HTMLElement) => CSFDPremiere[];
|
|
25
|
-
export declare const getTags: (el: HTMLElement) => string[];
|
|
26
|
-
export declare const getSeasonsInfo: (el: HTMLElement) => CSFDSeasons;
|