node-csfd-api-racintom 1.6.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,109 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { csfd } from '../src';
|
|
3
|
+
import { fetchPage } from '../src/fetchers';
|
|
4
|
+
import { CSFDCreatorScreening } from '../src/interfaces/creator.interface';
|
|
5
|
+
import { CSFDColorRating, CSFDFilmTypes } from '../src/interfaces/global';
|
|
6
|
+
import { movieUrl, userRatingsUrl } from '../src/vars';
|
|
7
|
+
const badId = 999999999999999;
|
|
8
|
+
|
|
9
|
+
// User Ratings
|
|
10
|
+
describe('Live: Fetch rating page', () => {
|
|
11
|
+
test('Fetch `912-bart` user and check some movie', async () => {
|
|
12
|
+
const MOVIE_NAME = 'Návštěvník';
|
|
13
|
+
|
|
14
|
+
const movies = await csfd.userRatings('912-bart');
|
|
15
|
+
const movieSelected = movies.filter((x) => x.title === MOVIE_NAME)[0];
|
|
16
|
+
expect(movies.map((x) => x.title)).toEqual(expect.arrayContaining([MOVIE_NAME]));
|
|
17
|
+
expect(movieSelected?.year).toEqual<number>(2025);
|
|
18
|
+
expect(movieSelected?.type).toEqual<CSFDFilmTypes>('film');
|
|
19
|
+
expect(movieSelected?.userDate).toContain<string>('2025');
|
|
20
|
+
expect(movies.length).toEqual(50);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('Fetch rating page 2', () => {
|
|
25
|
+
test('Fetch `912-bart` user – page 2 and check html', async () => {
|
|
26
|
+
const url = userRatingsUrl(912, 2);
|
|
27
|
+
const html = await fetchPage(url);
|
|
28
|
+
expect(html).toContain('Můj soused Totoro');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Movie
|
|
33
|
+
describe('Live: Movie page', () => {
|
|
34
|
+
test('Fetch `10135-forrest-gump` movie', async () => {
|
|
35
|
+
const movie = await csfd.movie(10135);
|
|
36
|
+
expect(movie.title).toEqual<string>('Forrest Gump');
|
|
37
|
+
expect(movie.rating).toBeGreaterThan(90);
|
|
38
|
+
expect(movie.ratingCount).toBeGreaterThan(100000);
|
|
39
|
+
// More than 10 words in description
|
|
40
|
+
expect(movie.descriptions[0].split(' ').length).toBeGreaterThan(10);
|
|
41
|
+
expect(movie.tags.length).toBeGreaterThan(3);
|
|
42
|
+
expect(movie.year).toEqual(1994);
|
|
43
|
+
expect(movie.type).toEqual<CSFDFilmTypes>('film');
|
|
44
|
+
expect(movie.duration).toBeGreaterThan(140);
|
|
45
|
+
expect(movie.premieres.length).toBeGreaterThan(1);
|
|
46
|
+
expect(movie.colorRating).toEqual<CSFDColorRating>('good');
|
|
47
|
+
expect(movie.creators.directors[0]?.name).toEqual('Robert Zemeckis');
|
|
48
|
+
expect(movie.origins[0]).toEqual<string>('USA');
|
|
49
|
+
});
|
|
50
|
+
test('Fetch `71924-kralovstvi` serial years', async () => {
|
|
51
|
+
const movie = await csfd.movie(71924);
|
|
52
|
+
expect(movie.year).toEqual<number>(1994);
|
|
53
|
+
expect(movie.title).toEqual<string>('Království');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Search
|
|
58
|
+
describe('Live: Search', () => {
|
|
59
|
+
test('Search matrix', async () => {
|
|
60
|
+
const search = await csfd.search('matrix');
|
|
61
|
+
const matrix = search.movies.find((x) => x.title === 'Matrix');
|
|
62
|
+
expect(matrix?.year).toEqual<number>(1999);
|
|
63
|
+
expect(matrix?.creators?.directors.map((x) => x.name)).toEqual<string[]>(
|
|
64
|
+
expect.arrayContaining(['Lilly Wachowski'])
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Creator
|
|
70
|
+
describe('Live: Creator page', () => {
|
|
71
|
+
test('Fetch `2018-jan-werich` creator', async () => {
|
|
72
|
+
const creator = await csfd.creator(2018);
|
|
73
|
+
expect(creator.name).toEqual<string>('Jan Werich');
|
|
74
|
+
expect(creator.birthday).toEqual('06.02.1905');
|
|
75
|
+
expect(creator.birthplace).toContain('Rakousko-Uhersko');
|
|
76
|
+
expect(creator.birthplace).toContain('Praha');
|
|
77
|
+
expect(creator.films.find((film) => film.title === 'Hej-rup!')).toEqual<CSFDCreatorScreening>({
|
|
78
|
+
id: 3106,
|
|
79
|
+
title: 'Hej-rup!',
|
|
80
|
+
year: 1934,
|
|
81
|
+
colorRating: 'good'
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Edge cases
|
|
87
|
+
describe('User page 404', () => {
|
|
88
|
+
test('Fetch error URL', async () => {
|
|
89
|
+
try {
|
|
90
|
+
const url = userRatingsUrl(badId);
|
|
91
|
+
const html = await fetchPage(url);
|
|
92
|
+
expect(html).toBe('Error');
|
|
93
|
+
} catch (e) {
|
|
94
|
+
expect(e).toContain(Error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('Movie page 404', () => {
|
|
100
|
+
test('Fetch error URL', async () => {
|
|
101
|
+
try {
|
|
102
|
+
const url = movieUrl(badId);
|
|
103
|
+
const html = await fetchPage(url);
|
|
104
|
+
expect(html).toBe('Error');
|
|
105
|
+
} catch (e) {
|
|
106
|
+
expect(e).toThrow(Error);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { getDuration } from '../src/helpers/global.helper';
|
|
3
|
+
|
|
4
|
+
export const durationInput = [
|
|
5
|
+
'PT142M',
|
|
6
|
+
undefined,
|
|
7
|
+
undefined,
|
|
8
|
+
undefined,
|
|
9
|
+
undefined,
|
|
10
|
+
undefined,
|
|
11
|
+
undefined,
|
|
12
|
+
'142',
|
|
13
|
+
undefined,
|
|
14
|
+
{ index: 0 },
|
|
15
|
+
{ input: 'PT142M' },
|
|
16
|
+
{ groups: undefined }
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const result = {
|
|
20
|
+
sign: '+',
|
|
21
|
+
years: 0,
|
|
22
|
+
months: 0,
|
|
23
|
+
weeks: 0,
|
|
24
|
+
days: 0,
|
|
25
|
+
hours: 0,
|
|
26
|
+
minutes: '142',
|
|
27
|
+
seconds: 0
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('Live: Fetch rating page', () => {
|
|
31
|
+
test('Resolve duration', async () => {
|
|
32
|
+
const resolver = getDuration(durationInput);
|
|
33
|
+
expect(resolver).toEqual(result);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { addProtocol, parseColor, parseIdFromUrl } from '../src/helpers/global.helper';
|
|
3
|
+
|
|
4
|
+
describe('Add protocol', () => {
|
|
5
|
+
test('Handle without protocol', () => {
|
|
6
|
+
const url = addProtocol('//www.csfd.cz/uzivatel/912-bart/hodnoceni/');
|
|
7
|
+
expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart/hodnoceni/');
|
|
8
|
+
});
|
|
9
|
+
test('Handle with protocol', () => {
|
|
10
|
+
const url = addProtocol('https://www.csfd.cz/uzivatel/912-bart');
|
|
11
|
+
expect(url).toBe('https://www.csfd.cz/uzivatel/912-bart');
|
|
12
|
+
});
|
|
13
|
+
test('Handle http protocol', () => {
|
|
14
|
+
const url = addProtocol('http://www.csfd.cz/uzivatel/912-bart');
|
|
15
|
+
expect(url).toBe('http://www.csfd.cz/uzivatel/912-bart');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('Parse Id', () => {
|
|
20
|
+
test('Handle whole movie url', () => {
|
|
21
|
+
const url = parseIdFromUrl('https://www.csfd.cz/film/906693-projekt-adam/recenze/');
|
|
22
|
+
expect(url).toBe(null);
|
|
23
|
+
});
|
|
24
|
+
test('Handle movie url', () => {
|
|
25
|
+
const url = parseIdFromUrl('/film/906693-projekt-adam/recenze/');
|
|
26
|
+
expect(url).toBe(906693);
|
|
27
|
+
});
|
|
28
|
+
test('Handle bad url', () => {
|
|
29
|
+
const url = parseIdFromUrl(null as any);
|
|
30
|
+
expect(url).toBe(null);
|
|
31
|
+
});
|
|
32
|
+
test('bad string', () => {
|
|
33
|
+
const url = parseIdFromUrl('bad string');
|
|
34
|
+
expect(url).toBe(null);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('Parse color', () => {
|
|
39
|
+
test('Red', () => {
|
|
40
|
+
const url = parseColor('red');
|
|
41
|
+
expect(url).toBe('good');
|
|
42
|
+
});
|
|
43
|
+
test('Blue', () => {
|
|
44
|
+
const url = parseColor('blue');
|
|
45
|
+
expect(url).toBe('average');
|
|
46
|
+
});
|
|
47
|
+
test('Light grey', () => {
|
|
48
|
+
const url = parseColor('lightgrey');
|
|
49
|
+
expect(url).toBe('unknown');
|
|
50
|
+
});
|
|
51
|
+
test('Grey', () => {
|
|
52
|
+
const url = parseColor('grey');
|
|
53
|
+
expect(url).toBe('bad');
|
|
54
|
+
});
|
|
55
|
+
test('Wrong color', () => {
|
|
56
|
+
const url = parseColor('adas' as any);
|
|
57
|
+
expect(url).toBe('unknown');
|
|
58
|
+
});
|
|
59
|
+
});
|