node-csfd-api 3.0.0-next.1 → 3.0.0-next.3

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 2022
6
+ # CSFD API 2023
7
7
 
8
8
  > JavaScript NPM library for scraping **Czech Movie Database (csfd.cz)**
9
9
  >
@@ -173,6 +173,19 @@ movies: [
173
173
  }
174
174
  }
175
175
  ],
176
+ tvSeries: [
177
+ {
178
+ id: 71924,
179
+ title: 'Království',
180
+ year: 1994,
181
+ url: 'https://www.csfd.cz/film/71924-kralovstvi/',
182
+ type: 'seriál',
183
+ colorRating: 'good',
184
+ poster: 'https://image.pmgstatic.com/cache/resized/w60h85/files/images/film/posters/166/708/166708064_2da697.jpg',
185
+ origins: ['Dánsko'],
186
+ creators: []
187
+ }
188
+ ],
176
189
  users: [
177
190
  {
178
191
  id: 912,
@@ -381,8 +394,8 @@ _Note: You can not use both parameters 'includesOnly' and 'excludes'. Parameter
381
394
  - [ ] Search
382
395
  - [x] Movies
383
396
  - [x] Users
397
+ - [x] TV Series
384
398
  - [ ] Creators
385
- - [ ] TV Series
386
399
  - [x] Creators
387
400
  - [x] Bio
388
401
  - [x] Movies (TODO categories)
@@ -443,7 +456,7 @@ That's why, with node-csfd-api, what happens on your device stays on your device
443
456
 
444
457
  ## License
445
458
 
446
- Copyright © 2022 [Lukas Bartak](http://bartweb.cz)
459
+ Copyright © 2020 – 2023 [Lukas Bartak](http://bartweb.cz)
447
460
 
448
461
  Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)
449
462
 
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // import fetch from 'cross-fetch';
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
10
9
  });
11
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
12
14
  Object.defineProperty(exports, "__esModule", { value: true });
13
15
  exports.fetchPage = void 0;
16
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
14
17
  const USER_AGENTS = [
15
18
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
16
19
  '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',
@@ -22,7 +25,7 @@ const headers = {
22
25
  };
23
26
  const fetchPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
24
27
  try {
25
- const response = yield fetch(url, { headers });
28
+ const response = yield (0, cross_fetch_1.default)(url, { headers });
26
29
  if (response.status >= 400 && response.status < 600) {
27
30
  throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
28
31
  }
@@ -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;
@@ -24,12 +24,14 @@ class SearchScraper {
24
24
  const html = (0, node_html_parser_1.parse)(response);
25
25
  const moviesNode = html.querySelectorAll('.main-movies article');
26
26
  const usersNode = html.querySelectorAll('.main-users article');
27
- return this.parseSearch(moviesNode, usersNode);
27
+ const tvSeriesNode = html.querySelectorAll('.main-series article');
28
+ return this.parseSearch(moviesNode, usersNode, tvSeriesNode);
28
29
  });
29
30
  }
30
- parseSearch(moviesNode, usersNode) {
31
+ parseSearch(moviesNode, usersNode, tvSeriesNode) {
31
32
  const movies = [];
32
33
  const users = [];
34
+ const tvSeries = [];
33
35
  moviesNode.map((m) => {
34
36
  const url = (0, search_helper_1.getUrl)(m);
35
37
  const movie = {
@@ -42,7 +44,7 @@ class SearchScraper {
42
44
  poster: (0, search_helper_1.getPoster)(m),
43
45
  origins: (0, search_helper_1.getOrigins)(m),
44
46
  creators: {
45
- directors: (0, search_helper_1.parsePeople)(m, 'director'),
47
+ directors: (0, search_helper_1.parsePeople)(m, 'directors'),
46
48
  actors: (0, search_helper_1.parsePeople)(m, 'actors')
47
49
  }
48
50
  };
@@ -59,10 +61,28 @@ class SearchScraper {
59
61
  };
60
62
  users.push(user);
61
63
  });
64
+ tvSeriesNode.map((m) => {
65
+ const url = (0, search_helper_1.getUrl)(m);
66
+ const user = {
67
+ id: (0, global_helper_1.parseIdFromUrl)(url),
68
+ title: (0, search_helper_1.getTitle)(m),
69
+ year: (0, search_helper_1.getYear)(m),
70
+ url: `https://www.csfd.cz${url}`,
71
+ type: (0, search_helper_1.getType)(m),
72
+ colorRating: (0, search_helper_1.getColorRating)(m),
73
+ poster: (0, search_helper_1.getPoster)(m),
74
+ origins: (0, search_helper_1.getOrigins)(m),
75
+ creators: {
76
+ directors: (0, search_helper_1.parsePeople)(m, 'directors'),
77
+ actors: (0, search_helper_1.parsePeople)(m, 'actors')
78
+ }
79
+ };
80
+ tvSeries.push(user);
81
+ });
62
82
  const search = {
63
83
  movies: movies,
64
84
  users: users,
65
- tvSeries: [],
85
+ tvSeries: tvSeries,
66
86
  creators: []
67
87
  };
68
88
  return search;
@@ -1,4 +1,3 @@
1
- // import fetch from 'cross-fetch';
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
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',
@@ -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
  };
@@ -21,12 +21,14 @@ export class SearchScraper {
21
21
  const html = parse(response);
22
22
  const moviesNode = html.querySelectorAll('.main-movies article');
23
23
  const usersNode = html.querySelectorAll('.main-users article');
24
- return this.parseSearch(moviesNode, usersNode);
24
+ const tvSeriesNode = html.querySelectorAll('.main-series article');
25
+ return this.parseSearch(moviesNode, usersNode, tvSeriesNode);
25
26
  });
26
27
  }
27
- parseSearch(moviesNode, usersNode) {
28
+ parseSearch(moviesNode, usersNode, tvSeriesNode) {
28
29
  const movies = [];
29
30
  const users = [];
31
+ const tvSeries = [];
30
32
  moviesNode.map((m) => {
31
33
  const url = getUrl(m);
32
34
  const movie = {
@@ -39,7 +41,7 @@ export class SearchScraper {
39
41
  poster: getPoster(m),
40
42
  origins: getOrigins(m),
41
43
  creators: {
42
- directors: parsePeople(m, 'director'),
44
+ directors: parsePeople(m, 'directors'),
43
45
  actors: parsePeople(m, 'actors')
44
46
  }
45
47
  };
@@ -56,10 +58,28 @@ export class SearchScraper {
56
58
  };
57
59
  users.push(user);
58
60
  });
61
+ tvSeriesNode.map((m) => {
62
+ const url = getUrl(m);
63
+ const user = {
64
+ id: parseIdFromUrl(url),
65
+ title: getTitle(m),
66
+ year: getYear(m),
67
+ url: `https://www.csfd.cz${url}`,
68
+ type: getType(m),
69
+ colorRating: getColorRating(m),
70
+ poster: getPoster(m),
71
+ origins: getOrigins(m),
72
+ creators: {
73
+ directors: parsePeople(m, 'directors'),
74
+ actors: parsePeople(m, 'actors')
75
+ }
76
+ };
77
+ tvSeries.push(user);
78
+ });
59
79
  const search = {
60
80
  movies: movies,
61
81
  users: users,
62
- tvSeries: [],
82
+ tvSeries: tvSeries,
63
83
  creators: []
64
84
  };
65
85
  return search;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "3.0.0-next.1",
3
+ "version": "3.0.0-next.3",
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>",
@@ -15,7 +15,7 @@
15
15
  "lint": "eslint ./src/**/**/* --fix",
16
16
  "test": "jest",
17
17
  "fix-paths": "yarn json -I -f ./dist/package.json -e \"this.module='./esm/index.js';this.main='./cjs/index.js';this.types='./types/index.d.ts'\"",
18
- "publish:next": "yarn && yarn build && yarn test --coverage true && npm publish --folder dist --tag beta",
18
+ "publish:next": "yarn && yarn build && yarn test --coverage true && cd dist && npm publish --tag beta",
19
19
  "postversion": "git push && git push --follow-tags",
20
20
  "release:beta": "npm version preminor --preid=beta -m \"chore(update): prelease %s β\"",
21
21
  "prerelease:beta": "npm version prerelease --preid=beta -m \"chore(update): prelease %s β\"",
@@ -23,9 +23,13 @@
23
23
  "release:minor": "git checkout master && npm version minor -m \"chore(update): release %s 🚀\"",
24
24
  "release:major": "git checkout master && npm version major -m \"chore(update): major release %s 💥\""
25
25
  },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org"
29
+ },
26
30
  "dependencies": {
27
31
  "cross-fetch": "^3.1.5",
28
- "node-html-parser": "^6.1.1"
32
+ "node-html-parser": "^6.1.4"
29
33
  },
30
34
  "repository": {
31
35
  "url": "git+https://github.com/bartholomej/node-csfd-api.git",
@@ -49,7 +53,7 @@
49
53
  "api"
50
54
  ],
51
55
  "engines": {
52
- "node": ">= 12"
56
+ "node": ">= 14"
53
57
  },
54
58
  "license": "MIT",
55
59
  "module": "./esm/index.js",
@@ -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';