node-csfd-api 2.0.1 → 2.2.0-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 CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build & Publish](https://github.com/bartholomej/node-csfd-api/workflows/Publish/badge.svg)](https://github.com/bartholomej/node-csfd-api/actions)
4
4
  [![codecov](https://codecov.io/gh/bartholomej/node-csfd-api/branch/master/graph/badge.svg?token=YQH9UoVrGP)](https://codecov.io/gh/bartholomej/node-csfd-api)
5
5
 
6
- # CSFD API 2021
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://raw.githubusercontent.com/bartholomej/node-csfd-api/search/demo.ts) file
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
- ## Donation
427
+ ## ⭐️ Show your support
427
428
 
428
- If this project have helped you save time please consider [making a donation](https://github.com/sponsors/bartholomej) for some 🍺 or 🍵 ;)
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 © 2021 [Lukas Bartak](http://bartweb.cz)
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;
@@ -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[];
@@ -60,20 +60,31 @@ const getYear = (el) => {
60
60
  }
61
61
  };
62
62
  exports.getYear = getYear;
63
- const getDuration = (el) => {
64
- const origin = el.querySelector('.origin').innerText;
65
- const timeString = origin.split(',');
66
- if (timeString.length > 2) {
67
- const timeString2 = timeString.pop().trim();
68
- const timeRaw = timeString2.split('(')[0].trim();
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
- else {
76
- return null;
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;
@@ -115,11 +126,9 @@ const getPoster = (el) => {
115
126
  };
116
127
  exports.getPoster = getPoster;
117
128
  const getDescriptions = (el) => {
118
- var _a;
119
- // TODO more plots
120
- const plot = (_a = el
121
- .querySelector('.body--plots .plot-preview p')) === null || _a === void 0 ? void 0 : _a.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, '');
122
- return plot ? [plot] : [];
129
+ return el
130
+ .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')
131
+ .map((movie) => { var _a; return (_a = movie.textContent) === null || _a === void 0 ? void 0 : _a.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); });
123
132
  };
124
133
  exports.getDescriptions = getDescriptions;
125
134
  const parsePeople = (el) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "2.0.1",
3
+ "version": "2.2.0-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,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.4",
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),