node-csfd-api
Advanced tools
Comparing version 2.0.1 to 2.1.0-next.1
@@ -7,1 +7,2 @@ import { CSFDColorRating } from '../interfaces/global'; | ||
export declare const addProtocol: (url: string) => string; | ||
export declare const parseISO8601Duration: (iso: string) => number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0; | ||
exports.parseISO8601Duration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0; | ||
const parseIdFromUrl = (url) => { | ||
@@ -44,1 +44,17 @@ const idSlug = url.split('/')[2]; | ||
exports.addProtocol = addProtocol; | ||
const parseISO8601Duration = (iso) => { | ||
const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/; | ||
const matches = iso.match(iso8601DurationRegex); | ||
const duration = { | ||
sign: matches[1] === undefined ? '+' : '-', | ||
years: matches[2] === undefined ? 0 : matches[2], | ||
months: matches[3] === undefined ? 0 : matches[3], | ||
weeks: matches[4] === undefined ? 0 : matches[4], | ||
days: matches[5] === undefined ? 0 : matches[5], | ||
hours: matches[6] === undefined ? 0 : matches[6], | ||
minutes: matches[7] === undefined ? 0 : matches[7], | ||
seconds: matches[8] === undefined ? 0 : matches[8] | ||
}; | ||
return +duration.minutes; | ||
}; | ||
exports.parseISO8601Duration = parseISO8601Duration; |
@@ -12,3 +12,3 @@ import { HTMLElement } from 'node-html-parser'; | ||
export declare const getYear: (el: string) => number; | ||
export declare const getDuration: (el: HTMLElement) => number; | ||
export declare const getDuration: (jsonLdRaw: string, el: HTMLElement) => number; | ||
export declare const getTitlesOther: (el: HTMLElement) => CSFDTitlesOther[]; | ||
@@ -15,0 +15,0 @@ export declare const getPoster: (el: HTMLElement) => string; |
@@ -63,16 +63,27 @@ "use strict"; | ||
exports.getYear = getYear; | ||
const getDuration = (el) => { | ||
const origin = el.querySelector('.origin').innerText; | ||
const timeString = origin.split(','); | ||
if (timeString.length > 2) { | ||
const timeString2 = timeString.pop().trim(); | ||
const timeRaw = timeString2.split('(')[0].trim(); | ||
const hoursMinsRaw = timeRaw.split('min')[0]; | ||
const hoursMins = hoursMinsRaw.split('h'); | ||
// Resolve hours + minutes format | ||
const duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0]; | ||
return duration; | ||
const getDuration = (jsonLdRaw, el) => { | ||
let duration = null; | ||
try { | ||
const jsonLd = JSON.parse(jsonLdRaw); | ||
duration = jsonLd.duration; | ||
return (0, global_helper_1.parseISO8601Duration)(duration); | ||
} | ||
else { | ||
return null; | ||
catch (error) { | ||
const origin = el.querySelector('.origin').innerText; | ||
const timeString = origin.split(','); | ||
if (timeString.length > 2) { | ||
// Get last time elelment | ||
const timeString2 = timeString.pop().trim(); | ||
// Clean it | ||
const timeRaw = timeString2.split('(')[0].trim(); | ||
// Split by minutes and hours | ||
const hoursMinsRaw = timeRaw.split('min')[0]; | ||
const hoursMins = hoursMinsRaw.split('h'); | ||
// Resolve hours + minutes format | ||
duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0]; | ||
return duration; | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
@@ -79,0 +90,0 @@ }; |
{ | ||
"name": "node-csfd-api", | ||
"version": "2.0.1", | ||
"version": "2.1.0-next.1", | ||
"description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)", | ||
@@ -24,3 +24,3 @@ "main": "./index.js", | ||
"dependencies": { | ||
"cross-fetch": "^3.1.4", | ||
"cross-fetch": "^3.1.5", | ||
"node-html-parser": "^5.2.0" | ||
@@ -27,0 +27,0 @@ }, |
@@ -25,3 +25,3 @@ "use strict"; | ||
year: (0, movie_helper_1.getYear)(jsonLd), | ||
duration: (0, movie_helper_1.getDuration)(el), | ||
duration: (0, movie_helper_1.getDuration)(jsonLd, el), | ||
descriptions: (0, movie_helper_1.getDescriptions)(el), | ||
@@ -28,0 +28,0 @@ genres: (0, movie_helper_1.getGenres)(el), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59812
1086
1
Updatedcross-fetch@^3.1.5