node-csfd-api 2.0.1 → 2.1.0-next.1
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.
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-csfd-api",
|
|
3
|
-
"version": "2.0.1",
|
|
3
|
+
"version": "2.1.0-next.1",
|
|
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,7 +21,7 @@
|
|
|
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.
|
|
24
|
+
"cross-fetch": "^3.1.5",
|
|
25
25
|
"node-html-parser": "^5.2.0"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
@@ -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),
|