node-csfd-api 2.0.0 → 2.1.1-next.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/README.md +8 -5
- package/helpers/global.helper.d.ts +1 -0
- package/helpers/global.helper.js +17 -1
- package/helpers/movie.helper.d.ts +1 -1
- package/helpers/movie.helper.js +25 -14
- package/package.json +3 -3
- package/services/movie.service.js +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://github.com/bartholomej/node-csfd-api/actions)
|
|
4
4
|
[](https://codecov.io/gh/bartholomej/node-csfd-api)
|
|
5
5
|
|
|
6
|
-
# CSFD API
|
|
6
|
+
# CSFD API 2022
|
|
7
7
|
|
|
8
8
|
> JavaScript NPM library for scraping **Czech Movie Database (csfd.cz)**
|
|
9
9
|
>
|
|
@@ -30,6 +30,7 @@ npm install node-csfd-api --save
|
|
|
30
30
|
- [Movies and TV Series](#Movie)
|
|
31
31
|
- [User Ratings](#User-Ratings)
|
|
32
32
|
- [Search](#Search)
|
|
33
|
+
- [Creators](#Creators)
|
|
33
34
|
|
|
34
35
|
### Movie
|
|
35
36
|
|
|
@@ -396,7 +397,7 @@ yarn start
|
|
|
396
397
|
|
|
397
398
|
### Run demo locally
|
|
398
399
|
|
|
399
|
-
You can find and modify it in [`./demo.ts`](https://
|
|
400
|
+
You can find and modify it in [`./demo.ts`](https://github.com/bartholomej/node-csfd-api/blob/master/demo.ts) file
|
|
400
401
|
|
|
401
402
|
```bash
|
|
402
403
|
yarn demo
|
|
@@ -423,9 +424,11 @@ I welcome you to customize this according to your needs ;)
|
|
|
423
424
|
|
|
424
425
|
Pull requests for any improvements would be great!
|
|
425
426
|
|
|
426
|
-
##
|
|
427
|
+
## ⭐️ Show your support
|
|
427
428
|
|
|
428
|
-
|
|
429
|
+
Give a ⭐️ if this project helped you!
|
|
430
|
+
|
|
431
|
+
Or if you are brave enough consider [making a donation](https://github.com/sponsors/bartholomej) for some 🍺 or 🍵 ;)
|
|
429
432
|
|
|
430
433
|
## Privacy Policy
|
|
431
434
|
|
|
@@ -437,7 +440,7 @@ That's why, with CSFD Api, what happens on your device stays on your device till
|
|
|
437
440
|
|
|
438
441
|
## License
|
|
439
442
|
|
|
440
|
-
Copyright ©
|
|
443
|
+
Copyright © 2022 [Lukas Bartak](http://bartweb.cz)
|
|
441
444
|
|
|
442
445
|
Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)
|
|
443
446
|
|
|
@@ -4,3 +4,4 @@ export declare const parseIdFromUrl: (url: string) => number;
|
|
|
4
4
|
export declare const getColor: (cls: string) => CSFDColorRating;
|
|
5
5
|
export declare const parseColor: (quality: Colors) => CSFDColorRating;
|
|
6
6
|
export declare const addProtocol: (url: string) => string;
|
|
7
|
+
export declare const parseISO8601Duration: (iso: string) => number;
|
package/helpers/global.helper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0;
|
|
3
|
+
exports.parseISO8601Duration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0;
|
|
4
4
|
const parseIdFromUrl = (url) => {
|
|
5
5
|
const idSlug = url.split('/')[2];
|
|
6
6
|
const id = idSlug.split('-')[0];
|
|
@@ -41,3 +41,19 @@ const addProtocol = (url) => {
|
|
|
41
41
|
return url.startsWith('//') ? 'https:' + url : url;
|
|
42
42
|
};
|
|
43
43
|
exports.addProtocol = addProtocol;
|
|
44
|
+
const parseISO8601Duration = (iso) => {
|
|
45
|
+
const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
|
|
46
|
+
const matches = iso.match(iso8601DurationRegex);
|
|
47
|
+
const duration = {
|
|
48
|
+
sign: matches[1] === undefined ? '+' : '-',
|
|
49
|
+
years: matches[2] === undefined ? 0 : matches[2],
|
|
50
|
+
months: matches[3] === undefined ? 0 : matches[3],
|
|
51
|
+
weeks: matches[4] === undefined ? 0 : matches[4],
|
|
52
|
+
days: matches[5] === undefined ? 0 : matches[5],
|
|
53
|
+
hours: matches[6] === undefined ? 0 : matches[6],
|
|
54
|
+
minutes: matches[7] === undefined ? 0 : matches[7],
|
|
55
|
+
seconds: matches[8] === undefined ? 0 : matches[8]
|
|
56
|
+
};
|
|
57
|
+
return +duration.minutes;
|
|
58
|
+
};
|
|
59
|
+
exports.parseISO8601Duration = parseISO8601Duration;
|
|
@@ -9,7 +9,7 @@ export declare const getColorRating: (bodyClasses: string[]) => CSFDColorRating;
|
|
|
9
9
|
export declare const getRating: (el: HTMLElement) => number;
|
|
10
10
|
export declare const getRatingCount: (el: HTMLElement) => number;
|
|
11
11
|
export declare const getYear: (el: string) => number;
|
|
12
|
-
export declare const getDuration: (el: HTMLElement) => number;
|
|
12
|
+
export declare const getDuration: (jsonLdRaw: string, el: HTMLElement) => number;
|
|
13
13
|
export declare const getTitlesOther: (el: HTMLElement) => CSFDTitlesOther[];
|
|
14
14
|
export declare const getPoster: (el: HTMLElement) => string;
|
|
15
15
|
export declare const getDescriptions: (el: HTMLElement) => string[];
|
package/helpers/movie.helper.js
CHANGED
|
@@ -60,20 +60,31 @@ const getYear = (el) => {
|
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
exports.getYear = getYear;
|
|
63
|
-
const getDuration = (el) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const hoursMinsRaw = timeRaw.split('min')[0];
|
|
70
|
-
const hoursMins = hoursMinsRaw.split('h');
|
|
71
|
-
// Resolve hours + minutes format
|
|
72
|
-
const duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];
|
|
73
|
-
return duration;
|
|
63
|
+
const getDuration = (jsonLdRaw, el) => {
|
|
64
|
+
let duration = null;
|
|
65
|
+
try {
|
|
66
|
+
const jsonLd = JSON.parse(jsonLdRaw);
|
|
67
|
+
duration = jsonLd.duration;
|
|
68
|
+
return (0, global_helper_1.parseISO8601Duration)(duration);
|
|
74
69
|
}
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
catch (error) {
|
|
71
|
+
const origin = el.querySelector('.origin').innerText;
|
|
72
|
+
const timeString = origin.split(',');
|
|
73
|
+
if (timeString.length > 2) {
|
|
74
|
+
// Get last time elelment
|
|
75
|
+
const timeString2 = timeString.pop().trim();
|
|
76
|
+
// Clean it
|
|
77
|
+
const timeRaw = timeString2.split('(')[0].trim();
|
|
78
|
+
// Split by minutes and hours
|
|
79
|
+
const hoursMinsRaw = timeRaw.split('min')[0];
|
|
80
|
+
const hoursMins = hoursMinsRaw.split('h');
|
|
81
|
+
// Resolve hours + minutes format
|
|
82
|
+
duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];
|
|
83
|
+
return duration;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
89
|
};
|
|
79
90
|
exports.getDuration = getDuration;
|
|
@@ -118,7 +129,7 @@ const getDescriptions = (el) => {
|
|
|
118
129
|
var _a;
|
|
119
130
|
// TODO more plots
|
|
120
131
|
const plot = (_a = el
|
|
121
|
-
.querySelector('.body--plots .plot-
|
|
132
|
+
.querySelector('.body--plots .plot-full p')) === null || _a === void 0 ? void 0 : _a.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, '');
|
|
122
133
|
return plot ? [plot] : [];
|
|
123
134
|
};
|
|
124
135
|
exports.getDescriptions = getDescriptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-csfd-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1-next.0",
|
|
4
4
|
"description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"author": "BART! <bart@bartweb.cz>",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"release:major": "git checkout master && npm version major -m \"chore(update): major release %s 💥\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"cross-fetch": "^3.1.
|
|
25
|
-
"node-html-parser": "^5.
|
|
24
|
+
"cross-fetch": "^3.1.5",
|
|
25
|
+
"node-html-parser": "^5.2.0"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"url": "git+https://github.com/bartholomej/node-csfd-api.git",
|
|
@@ -22,7 +22,7 @@ class MovieScraper {
|
|
|
22
22
|
id: movieId,
|
|
23
23
|
title: (0, movie_helper_1.getTitle)(el),
|
|
24
24
|
year: (0, movie_helper_1.getYear)(jsonLd),
|
|
25
|
-
duration: (0, movie_helper_1.getDuration)(el),
|
|
25
|
+
duration: (0, movie_helper_1.getDuration)(jsonLd, el),
|
|
26
26
|
descriptions: (0, movie_helper_1.getDescriptions)(el),
|
|
27
27
|
genres: (0, movie_helper_1.getGenres)(el),
|
|
28
28
|
type: (0, movie_helper_1.getType)(el),
|