node-csfd-api 3.0.0-next.0 → 3.0.0-next.2

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
@@ -340,7 +340,7 @@ _Note: You can not use both parameters 'includesOnly' and 'excludes'. Parameter
340
340
 
341
341
  - [Dafilms web extension](https://chrome.google.com/webstore/detail/dafilms/hgcgneddmgflnbmhkjnefiobjgobbmdm?hl=en) ([code](https://github.com/bartholomej/dafilms-ext)) – Parser for film ratings (web extension)
342
342
  - [bartweb.cz](https://bartweb.cz) – **Last seen** section (Firebase function)
343
- - KinoKlub – Mobile application for Aerofilms (native Adnroid + iOS application)
343
+ - KinoKlub – Mobile application for AeroFilms (native Android + iOS application)
344
344
 
345
345
  ## Roadmap
346
346
 
@@ -439,7 +439,7 @@ I DO NOT STORE ANY DATA. PERIOD.
439
439
 
440
440
  I physically can't. I have nowhere to store it. I don't even have a server database to store it. So even if Justin Bieber asked nicely to see your data, I wouldn't have anything to show him.
441
441
 
442
- That's why, with CSFD Api, what happens on your device stays on your device till disappear.
442
+ That's why, with node-csfd-api, what happens on your device stays on your device till disappear.
443
443
 
444
444
  ## License
445
445
 
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ // import fetch from 'cross-fetch';
2
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,12 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
9
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
10
  });
10
11
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
12
  Object.defineProperty(exports, "__esModule", { value: true });
15
13
  exports.fetchPage = void 0;
16
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
17
14
  const USER_AGENTS = [
18
15
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
19
16
  'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
@@ -25,7 +22,7 @@ const headers = {
25
22
  };
26
23
  const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
27
24
  try {
28
- const response = yield (0, cross_fetch_1.default)(url, { headers });
25
+ const response = yield fetch(url, { headers });
29
26
  if (response.status >= 400 && response.status < 600) {
30
27
  throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
31
28
  }
@@ -56,7 +56,8 @@ const parseBirthPlace = (text) => {
56
56
  };
57
57
  exports.parseBirthPlace = parseBirthPlace;
58
58
  const getFilms = (el) => {
59
- const filmNodes = el.querySelectorAll('.box:first-of-type table tr');
59
+ var _a;
60
+ const filmNodes = (_a = el.querySelectorAll('.box')[0]) === null || _a === void 0 ? void 0 : _a.querySelectorAll('table tr');
60
61
  let yearCache;
61
62
  const films = filmNodes.map((filmNode) => {
62
63
  var _a, _b, _c;
@@ -223,17 +223,20 @@ const getBoxMovies = (el, boxName) => {
223
223
  };
224
224
  exports.getBoxMovies = getBoxMovies;
225
225
  const getPremieres = (el) => {
226
- var _a;
227
- const premieresNode = el.querySelectorAll('.box-premieres li');
226
+ var _a, _b;
227
+ const premiereNodes = el.querySelectorAll('.box-premieres li');
228
228
  const premiere = [];
229
- for (const premiereNode of premieresNode) {
230
- const [date, ...company] = premiereNode.querySelector('p + span').attributes.title.split(' ');
231
- premiere.push({
232
- country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
233
- format: premiereNode.querySelector('p').textContent.trim().split(' od')[0],
234
- date,
235
- company: company.join(' ')
236
- });
229
+ for (const premiereNode of premiereNodes) {
230
+ const title = premiereNode.querySelector('p + span').attributes.title;
231
+ if (title) {
232
+ const [date, ...company] = title === null || title === void 0 ? void 0 : title.split(' ');
233
+ premiere.push({
234
+ country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
235
+ format: (_b = premiereNode.querySelector('p').textContent.trim()) === null || _b === void 0 ? void 0 : _b.split(' od')[0],
236
+ date,
237
+ company: company.join(' ')
238
+ });
239
+ }
237
240
  }
238
241
  return premiere;
239
242
  };
@@ -37,13 +37,24 @@ const getOrigins = (el) => {
37
37
  };
38
38
  exports.getOrigins = getOrigins;
39
39
  const parsePeople = (el, type) => {
40
- const people = el.querySelectorAll(`.article-content .${type} a`);
41
- return people.map((person) => {
42
- return {
43
- id: (0, global_helper_1.parseIdFromUrl)(person.attributes.href),
44
- name: person.innerText.trim(),
45
- url: `https://www.csfd.cz${person.attributes.href}`
46
- };
47
- });
40
+ let who;
41
+ if (type === 'directors')
42
+ who = 'Režie:';
43
+ if (type === 'actors')
44
+ who = 'Hrají:';
45
+ const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) => el.textContent.includes(who));
46
+ if (peopleNode) {
47
+ const people = Array.from(peopleNode.querySelectorAll('a'));
48
+ return people.map((person) => {
49
+ return {
50
+ id: (0, global_helper_1.parseIdFromUrl)(person.attributes.href),
51
+ name: person.innerText.trim(),
52
+ url: `https://www.csfd.cz${person.attributes.href}`
53
+ };
54
+ });
55
+ }
56
+ else {
57
+ return [];
58
+ }
48
59
  };
49
60
  exports.parsePeople = parsePeople;
@@ -42,7 +42,7 @@ class SearchScraper {
42
42
  poster: (0, search_helper_1.getPoster)(m),
43
43
  origins: (0, search_helper_1.getOrigins)(m),
44
44
  creators: {
45
- directors: (0, search_helper_1.parsePeople)(m, 'director'),
45
+ directors: (0, search_helper_1.parsePeople)(m, 'directors'),
46
46
  actors: (0, search_helper_1.parsePeople)(m, 'actors')
47
47
  }
48
48
  };
@@ -1,3 +1,4 @@
1
+ // import fetch from 'cross-fetch';
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,7 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import fetch from 'cross-fetch';
11
11
  const USER_AGENTS = [
12
12
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
13
13
  'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1',
@@ -44,7 +44,8 @@ export const parseBirthPlace = (text) => {
44
44
  return text.trim().replace(/<br>/g, '').trim();
45
45
  };
46
46
  export const getFilms = (el) => {
47
- const filmNodes = el.querySelectorAll('.box:first-of-type table tr');
47
+ var _a;
48
+ const filmNodes = (_a = el.querySelectorAll('.box')[0]) === null || _a === void 0 ? void 0 : _a.querySelectorAll('table tr');
48
49
  let yearCache;
49
50
  const films = filmNodes.map((filmNode) => {
50
51
  var _a, _b, _c;
@@ -200,17 +200,20 @@ export const getBoxMovies = (el, boxName) => {
200
200
  return movieListItem;
201
201
  };
202
202
  export const getPremieres = (el) => {
203
- var _a;
204
- const premieresNode = el.querySelectorAll('.box-premieres li');
203
+ var _a, _b;
204
+ const premiereNodes = el.querySelectorAll('.box-premieres li');
205
205
  const premiere = [];
206
- for (const premiereNode of premieresNode) {
207
- const [date, ...company] = premiereNode.querySelector('p + span').attributes.title.split(' ');
208
- premiere.push({
209
- country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
210
- format: premiereNode.querySelector('p').textContent.trim().split(' od')[0],
211
- date,
212
- company: company.join(' ')
213
- });
206
+ for (const premiereNode of premiereNodes) {
207
+ const title = premiereNode.querySelector('p + span').attributes.title;
208
+ if (title) {
209
+ const [date, ...company] = title === null || title === void 0 ? void 0 : title.split(' ');
210
+ premiere.push({
211
+ country: ((_a = premiereNode.querySelector('.flag')) === null || _a === void 0 ? void 0 : _a.attributes.title) || null,
212
+ format: (_b = premiereNode.querySelector('p').textContent.trim()) === null || _b === void 0 ? void 0 : _b.split(' od')[0],
213
+ date,
214
+ company: company.join(' ')
215
+ });
216
+ }
214
217
  }
215
218
  return premiere;
216
219
  };
@@ -27,12 +27,23 @@ export const getOrigins = (el) => {
27
27
  return originsAll === null || originsAll === void 0 ? void 0 : originsAll.split('/').map((country) => country.trim());
28
28
  };
29
29
  export const parsePeople = (el, type) => {
30
- const people = el.querySelectorAll(`.article-content .${type} a`);
31
- return people.map((person) => {
32
- return {
33
- id: parseIdFromUrl(person.attributes.href),
34
- name: person.innerText.trim(),
35
- url: `https://www.csfd.cz${person.attributes.href}`
36
- };
37
- });
30
+ let who;
31
+ if (type === 'directors')
32
+ who = 'Režie:';
33
+ if (type === 'actors')
34
+ who = 'Hrají:';
35
+ const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) => el.textContent.includes(who));
36
+ if (peopleNode) {
37
+ const people = Array.from(peopleNode.querySelectorAll('a'));
38
+ return people.map((person) => {
39
+ return {
40
+ id: parseIdFromUrl(person.attributes.href),
41
+ name: person.innerText.trim(),
42
+ url: `https://www.csfd.cz${person.attributes.href}`
43
+ };
44
+ });
45
+ }
46
+ else {
47
+ return [];
48
+ }
38
49
  };
@@ -39,7 +39,7 @@ export class SearchScraper {
39
39
  poster: getPoster(m),
40
40
  origins: getOrigins(m),
41
41
  creators: {
42
- directors: parsePeople(m, 'director'),
42
+ directors: parsePeople(m, 'directors'),
43
43
  actors: parsePeople(m, 'actors')
44
44
  }
45
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "3.0.0-next.0",
3
+ "version": "3.0.0-next.2",
4
4
  "description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
5
5
  "main": "./cjs/index.js",
6
6
  "author": "BART! <bart@bartweb.cz>",
@@ -24,8 +24,7 @@
24
24
  "release:major": "git checkout master && npm version major -m \"chore(update): major release %s 💥\""
25
25
  },
26
26
  "dependencies": {
27
- "cross-fetch": "^3.1.5",
28
- "node-html-parser": "^5.3.3"
27
+ "node-html-parser": "^6.1.4"
29
28
  },
30
29
  "repository": {
31
30
  "url": "git+https://github.com/bartholomej/node-csfd-api.git",
@@ -3,15 +3,15 @@ import { CSFDCreatorScreening } from '../interfaces/creator.interface';
3
3
  import { CSFDColorRating } from '../interfaces/global';
4
4
  export declare const getColorRating: (el: HTMLElement) => CSFDColorRating;
5
5
  export declare const getId: (url: string) => number;
6
- export declare const getName: (el: HTMLElement) => string;
7
- export declare const getBirthdayInfo: (el: HTMLElement) => {
6
+ export declare const getName: (el: HTMLElement | null) => string;
7
+ export declare const getBirthdayInfo: (el: HTMLElement | null) => {
8
8
  birthday: string;
9
9
  age: number;
10
10
  birthPlace: string;
11
11
  };
12
- export declare const getBio: (el: HTMLElement) => string;
13
- export declare const getPhoto: (el: HTMLElement) => string;
12
+ export declare const getBio: (el: HTMLElement | null) => string;
13
+ export declare const getPhoto: (el: HTMLElement | null) => string;
14
14
  export declare const parseBirthday: (text: string) => any;
15
15
  export declare const parseAge: (text: string) => any;
16
16
  export declare const parseBirthPlace: (text: string) => any;
17
- export declare const getFilms: (el: HTMLElement) => CSFDCreatorScreening[];
17
+ export declare const getFilms: (el: HTMLElement | null) => CSFDCreatorScreening[];
@@ -11,14 +11,14 @@ export declare const getRatingCount: (el: HTMLElement) => number;
11
11
  export declare const getYear: (el: string) => number;
12
12
  export declare const getDuration: (jsonLdRaw: string, el: HTMLElement) => number;
13
13
  export declare const getTitlesOther: (el: HTMLElement) => CSFDTitlesOther[];
14
- export declare const getPoster: (el: HTMLElement) => string;
15
- export declare const getRandomPhoto: (el: HTMLElement) => string;
16
- export declare const getTrivia: (el: HTMLElement) => string[];
14
+ export declare const getPoster: (el: HTMLElement | null) => string;
15
+ export declare const getRandomPhoto: (el: HTMLElement | null) => string;
16
+ export declare const getTrivia: (el: HTMLElement | null) => string[];
17
17
  export declare const getDescriptions: (el: HTMLElement) => string[];
18
18
  export declare const parsePeople: (el: HTMLElement) => CSFDCreator[];
19
19
  export declare const getGroup: (el: HTMLElement, group: CSFDCreatorGroups) => CSFDCreator[];
20
20
  export declare const getType: (el: HTMLElement) => string;
21
- export declare const getVods: (el: HTMLElement) => CSFDVod[];
21
+ export declare const getVods: (el: HTMLElement | null) => CSFDVod[];
22
22
  export declare const getBoxContent: (el: HTMLElement, box: string) => HTMLElement;
23
23
  export declare const getBoxMovies: (el: HTMLElement, boxName: CSFDBoxContent) => CSFDMovieListItem[];
24
24
  export declare const getPremieres: (el: HTMLElement) => CSFDPremiere[];
@@ -8,4 +8,4 @@ export declare const getUrl: (el: HTMLElement) => string;
8
8
  export declare const getColorRating: (el: HTMLElement) => CSFDColorRating;
9
9
  export declare const getPoster: (el: HTMLElement) => string;
10
10
  export declare const getOrigins: (el: HTMLElement) => string[];
11
- export declare const parsePeople: (el: HTMLElement, type: 'director' | 'actors') => CSFDCreator[];
11
+ export declare const parsePeople: (el: HTMLElement, type: 'directors' | 'actors') => CSFDCreator[];
@@ -9,4 +9,4 @@ export interface CSFDCreator {
9
9
  bio: string;
10
10
  films: CSFDCreatorScreening[];
11
11
  }
12
- export declare type CSFDCreatorScreening = Omit<CSFDScreening, 'url' | 'type'>;
12
+ export type CSFDCreatorScreening = Omit<CSFDScreening, 'url' | 'type'>;
@@ -17,6 +17,6 @@ export interface CSFDScreening {
17
17
  */
18
18
  colorRating: CSFDColorRating;
19
19
  }
20
- export declare type CSFDColorRating = 'bad' | 'average' | 'good' | 'unknown';
21
- export declare type CSFDStars = 0 | 1 | 2 | 3 | 4 | 5;
22
- export declare type CSFDFilmTypes = 'film' | 'TV film' | 'pořad' | 'seriál' | 'divadelní záznam' | 'koncert' | 'série' | 'studentský film' | 'amatérský film' | 'hudební videoklip' | 'epizoda';
20
+ export type CSFDColorRating = 'bad' | 'average' | 'good' | 'unknown';
21
+ export type CSFDStars = 0 | 1 | 2 | 3 | 4 | 5;
22
+ export type CSFDFilmTypes = 'film' | 'TV film' | 'pořad' | 'seriál' | 'divadelní záznam' | 'koncert' | 'série' | 'studentský film' | 'amatérský film' | 'hudební videoklip' | 'epizoda';
@@ -17,8 +17,9 @@ export interface CSFDMovie extends CSFDScreening {
17
17
  related: CSFDMovieListItem[];
18
18
  similar: CSFDMovieListItem[];
19
19
  }
20
+ export type CSFDVodService = 'Netflix' | 'hbogo' | 'Prime Video' | 'Apple TV+' | 'iTunes' | 'KVIFF.TV' | 'Edisonline' | 'o2tv' | 'SledovaniTV' | 'Starmax' | 'DAFilms' | 'FILMY ČESKY A ZADARMO' | 'Youtube Česká filmová klasika' | 'VAPET' | 'VOREL FILM' | 'ivysilani' | 'Google Play' | 'Voyo' | 'DVD';
20
21
  export interface CSFDVod {
21
- title: 'Netflix' | 'hbogo' | 'Prime Video' | 'Apple TV+' | 'iTunes' | 'Aerovod' | 'Edisonline' | 'o2tv' | 'SledovaniTV' | 'Starmax' | 'DAFilms' | 'FILMY ČESKY A ZADARMO' | 'Youtube Česká filmová klasika' | 'VAPET' | 'VOREL FILM' | 'ivysilani' | 'Google Play' | 'Voyo' | string;
22
+ title: CSFDVodService;
22
23
  url: string;
23
24
  }
24
25
  export interface CSFDCreators {
@@ -54,12 +55,12 @@ export interface CSFDMovieListItem {
54
55
  title: string;
55
56
  url: string;
56
57
  }
57
- export declare type CSFDGenres = 'Akční' | 'Animovaný' | 'Dobrodružný' | 'Dokumentární' | 'Drama' | 'Experimentální' | 'Fantasy' | 'Film-Noir' | 'Historický' | 'Horor' | 'Hudební' | 'IMAX' | 'Katastrofický' | 'Komedie' | 'Krátkometrážní' | 'Krimi' | 'Loutkový' | 'Muzikál' | 'Mysteriózní' | 'Naučný' | 'Podobenství' | 'Poetický' | 'Pohádka' | 'Povídkový' | 'Psychologický' | 'Publicistický' | 'Reality-TV' | 'Road movie' | 'Rodinný' | 'Romantický' | 'Sci-Fi' | 'Soutěžní' | 'Sportovní' | 'Stand-up' | 'Talk-show' | 'Taneční' | 'Telenovela' | 'Thriller' | 'Válečný' | 'Western' | 'Zábavný' | 'Životopisný';
58
- export declare type CSFDCreatorGroups = 'Režie' | 'Scénář' | 'Kamera' | 'Hudba' | 'Hrají' | 'Produkce' | 'Střih' | 'Předloha' | 'Scénografie' | 'Kostýmy';
58
+ export type CSFDGenres = 'Akční' | 'Animovaný' | 'Dobrodružný' | 'Dokumentární' | 'Drama' | 'Experimentální' | 'Fantasy' | 'Film-Noir' | 'Historický' | 'Horor' | 'Hudební' | 'IMAX' | 'Katastrofický' | 'Komedie' | 'Krátkometrážní' | 'Krimi' | 'Loutkový' | 'Muzikál' | 'Mysteriózní' | 'Naučný' | 'Podobenství' | 'Poetický' | 'Pohádka' | 'Povídkový' | 'Psychologický' | 'Publicistický' | 'Reality-TV' | 'Road movie' | 'Rodinný' | 'Romantický' | 'Sci-Fi' | 'Soutěžní' | 'Sportovní' | 'Stand-up' | 'Talk-show' | 'Taneční' | 'Telenovela' | 'Thriller' | 'Válečný' | 'Western' | 'Zábavný' | 'Životopisný';
59
+ export type CSFDCreatorGroups = 'Režie' | 'Scénář' | 'Kamera' | 'Hudba' | 'Hrají' | 'Produkce' | 'Střih' | 'Předloha' | 'Scénografie' | 'Kostýmy';
59
60
  export interface CSFDPremiere {
60
61
  country: string;
61
62
  format: string;
62
63
  date: string;
63
64
  company: string;
64
65
  }
65
- export declare type CSFDBoxContent = 'Související' | 'Podobné';
66
+ export type CSFDBoxContent = 'Související' | 'Podobné';
@@ -15,4 +15,4 @@ export interface CSFDUserRatingConfig {
15
15
  */
16
16
  allPagesDelay?: number;
17
17
  }
18
- export declare type Colors = 'lightgrey' | 'blue' | 'red' | 'grey';
18
+ export type Colors = 'lightgrey' | 'blue' | 'red' | 'grey';