node-csfd-api
Advanced tools
Comparing version 1.11.0-next.0 to 2.0.0-next.0
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.fetchPage = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
const USER_AGENTS = [ | ||
@@ -20,3 +20,3 @@ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', | ||
try { | ||
const response = await (0, node_fetch_1.default)(url, { headers }); | ||
const response = await (0, cross_fetch_1.default)(url, { headers }); | ||
if (response.status >= 400 && response.status < 600) { | ||
@@ -23,0 +23,0 @@ throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`); |
@@ -42,3 +42,4 @@ "use strict"; | ||
const getPhoto = (el) => { | ||
return el.querySelector('img').attributes.src; | ||
const image = el.querySelector('img').attributes.src; | ||
return (0, global_helper_1.addProtocol)(image); | ||
}; | ||
@@ -45,0 +46,0 @@ exports.getPhoto = getPhoto; |
@@ -6,1 +6,2 @@ import { CSFDColorRating } from '../interfaces/global'; | ||
export declare const parseColor: (quality: Colors) => CSFDColorRating; | ||
export declare const addProtocol: (url: string) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0; | ||
exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0; | ||
const parseIdFromUrl = (url) => { | ||
@@ -40,1 +40,5 @@ const idSlug = url.split('/')[2]; | ||
exports.parseColor = parseColor; | ||
const addProtocol = (url) => { | ||
return url.startsWith('//') ? 'https:' + url : url; | ||
}; | ||
exports.addProtocol = addProtocol; |
@@ -11,3 +11,3 @@ import { HTMLElement } from 'node-html-parser'; | ||
export declare const getRatingCount: (el: HTMLElement) => number; | ||
export declare const getYear: (el: HTMLElement) => string | number; | ||
export declare const getYear: (el: string) => number; | ||
export declare const getDuration: (el: HTMLElement) => number; | ||
@@ -17,3 +17,2 @@ export declare const getTitlesOther: (el: HTMLElement) => CSFDTitlesOther[]; | ||
export declare const getDescriptions: (el: HTMLElement) => string[]; | ||
export declare const getDirectors: (el: HTMLElement) => CSFDCreator[]; | ||
export declare const parsePeople: (el: HTMLElement) => CSFDCreator[]; | ||
@@ -20,0 +19,0 @@ export declare const getGroup: (el: HTMLElement, group: CSFDCreatorGroups) => CSFDCreator[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTags = exports.getPremieres = exports.getBoxMovies = exports.getBoxContent = exports.getVods = exports.getType = exports.getGroup = exports.parsePeople = exports.getDirectors = exports.getDescriptions = exports.getPoster = exports.getTitlesOther = exports.getDuration = exports.getYear = exports.getRatingCount = exports.getRating = exports.getColorRating = exports.getOrigins = exports.getGenres = exports.getTitle = exports.getId = void 0; | ||
exports.getTags = exports.getPremieres = exports.getBoxMovies = exports.getBoxContent = exports.getVods = exports.getType = exports.getGroup = exports.parsePeople = exports.getDescriptions = exports.getPoster = exports.getTitlesOther = exports.getDuration = exports.getYear = exports.getRatingCount = exports.getRating = exports.getColorRating = exports.getOrigins = exports.getGenres = exports.getTitle = exports.getId = void 0; | ||
const global_helper_1 = require("./global.helper"); | ||
@@ -53,3 +53,10 @@ const getId = (el) => { | ||
const getYear = (el) => { | ||
return el.querySelector('.origin span').innerText.replace(/[{()}]/g, ''); | ||
try { | ||
const jsonLd = JSON.parse(el); | ||
return +jsonLd.dateCreated; | ||
} | ||
catch (error) { | ||
console.error('node-csfd-api: Error parsing JSON-LD', error); | ||
return null; | ||
} | ||
}; | ||
@@ -102,3 +109,4 @@ exports.getYear = getYear; | ||
const imageThumb = poster.attributes.src.split('?')[0]; | ||
return imageThumb.replace(/\/w140\//, '/w1080/'); | ||
const image = imageThumb.replace(/\/w140\//, '/w1080/'); | ||
return (0, global_helper_1.addProtocol)(image); | ||
} | ||
@@ -119,8 +127,2 @@ } | ||
exports.getDescriptions = getDescriptions; | ||
const getDirectors = (el) => { | ||
const creators = el.querySelectorAll('.creators span'); | ||
const directorsSpan = creators.filter((creator) => creator.attributes.itemprop === 'director')[0]; | ||
return (directorsSpan && (0, exports.parsePeople)(directorsSpan)) || []; | ||
}; | ||
exports.getDirectors = getDirectors; | ||
const parsePeople = (el) => { | ||
@@ -127,0 +129,0 @@ const people = el.querySelectorAll('a'); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getUserUrl = exports.getAvatar = exports.getUserRealName = exports.getUser = void 0; | ||
const global_helper_1 = require("./global.helper"); | ||
const getUser = (el) => { | ||
@@ -14,3 +15,4 @@ return el.querySelector('.user-title-name').text; | ||
const getAvatar = (el) => { | ||
return el.querySelector('.article-img img').attributes.src; | ||
const image = el.querySelector('.article-img img').attributes.src; | ||
return (0, global_helper_1.addProtocol)(image); | ||
}; | ||
@@ -17,0 +19,0 @@ exports.getAvatar = getAvatar; |
@@ -6,3 +6,3 @@ import { HTMLElement } from 'node-html-parser'; | ||
export declare const getTitle: (el: HTMLElement) => string; | ||
export declare const getYear: (el: HTMLElement) => string; | ||
export declare const getYear: (el: HTMLElement) => number; | ||
export declare const getUrl: (el: HTMLElement) => string; | ||
@@ -9,0 +9,0 @@ export declare const getColorRating: (el: HTMLElement) => CSFDColorRating; |
@@ -16,3 +16,3 @@ "use strict"; | ||
var _a; | ||
return (_a = el.querySelectorAll('.film-title-info .info')[0]) === null || _a === void 0 ? void 0 : _a.innerText.replace(/[{()}]/g, ''); | ||
return +((_a = el.querySelectorAll('.film-title-info .info')[0]) === null || _a === void 0 ? void 0 : _a.innerText.replace(/[{()}]/g, '')); | ||
}; | ||
@@ -29,10 +29,11 @@ exports.getYear = getYear; | ||
const getPoster = (el) => { | ||
return el.querySelector('img').attributes.src; | ||
const image = el.querySelector('img').attributes.src; | ||
return (0, global_helper_1.addProtocol)(image); | ||
}; | ||
exports.getPoster = getPoster; | ||
const getOrigins = (el) => { | ||
var _a; | ||
const originsRaw = el.querySelector('.article-content p .info').text; | ||
const origins = originsRaw === null || originsRaw === void 0 ? void 0 : originsRaw.split(', '); | ||
origins.pop(); | ||
return origins; | ||
const originsAll = (_a = originsRaw === null || originsRaw === void 0 ? void 0 : originsRaw.split(', ')) === null || _a === void 0 ? void 0 : _a[0]; | ||
return originsAll === null || originsAll === void 0 ? void 0 : originsAll.split('/').map((country) => country.trim()); | ||
}; | ||
@@ -39,0 +40,0 @@ exports.getOrigins = getOrigins; |
export interface CSFDScreening { | ||
id: number; | ||
title: string; | ||
year: number | string; | ||
year: number; | ||
url: string; | ||
@@ -22,2 +22,2 @@ type: CSFDFilmTypes; | ||
export declare type CSFDStars = 0 | 1 | 2 | 3 | 4 | 5; | ||
export declare type CSFDFilmTypes = 'film' | 'TV film' | 'TV pořad' | 'TV seriál' | 'divadelní záznam' | 'koncert' | 'série' | 'studentský film' | 'amatérský film' | 'hudební videoklip' | 'epizoda'; | ||
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'; |
@@ -19,3 +19,3 @@ import { CSFDScreening } from './global'; | ||
export interface CSFDVod { | ||
title: 'Netflix' | 'hbogo' | 'Prime Video' | 'Apple TV+' | 'ivysilani' | 'Aerovod' | 'o2tv' | 'Voyo' | 'FILMY ČESKY A ZADARMO' | 'VAPET' | 'VOREL FILM' | string; | ||
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; | ||
url: string; | ||
@@ -22,0 +22,0 @@ } |
{ | ||
"name": "node-csfd-api", | ||
"version": "1.11.0-next.0", | ||
"description": "Simple NPM library for scraping CSFD", | ||
"version": "2.0.0-next.0", | ||
"description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)", | ||
"main": "./index.js", | ||
@@ -24,3 +24,3 @@ "author": "BART! <bart@bartweb.cz>", | ||
"dependencies": { | ||
"node-fetch": "cjs", | ||
"cross-fetch": "^3.1.4", | ||
"node-html-parser": "^5.1.0" | ||
@@ -50,3 +50,3 @@ }, | ||
"engines": { | ||
"node": ">= 10" | ||
"node": ">= 12" | ||
}, | ||
@@ -53,0 +53,0 @@ "license": "MIT", |
@@ -8,29 +8,29 @@ [![npm version](https://badge.fury.io/js/node-csfd-api.svg)](https://badge.fury.io/js/node-csfd-api) | ||
> Tiny NPM library for scraping csfd.cz | ||
> JavaScript NPM library for scraping **Czech Movie Database (csfd.cz)** | ||
> | ||
> - Browser + Node.js (SSR) | ||
> - TypeScript 100% | ||
> - ✅ Ready for CSFD 2021! | ||
> - JavaScript / TypeScript | ||
> - Tested (~100% Code coverage) | ||
> - ✅ Ready for new ČSFD 2021! | ||
> - You can use in: | ||
> - Firebase function | ||
> - AWS λ (lambda function) | ||
> - Chrome extension | ||
> - React native app | ||
> - ... | ||
Scraper: | ||
> - [Movies and TV Series](#Movie) | ||
> - [User Ratings](#User-Ratings) | ||
> - [Search](#Search) | ||
## Install | ||
via yarn | ||
```bash | ||
yarn add node-csfd-api | ||
npm install node-csfd-api --save | ||
# yarn add node-csfd-api | ||
``` | ||
via npm | ||
## Usage and examples | ||
```bash | ||
npm install node-csfd-api | ||
``` | ||
- [Movies and TV Series](#Movie) | ||
- [User Ratings](#User-Ratings) | ||
- [Search](#Search) | ||
## Movie | ||
### Movie | ||
@@ -45,3 +45,3 @@ Get info about [this movie](https://www.csfd.cz/film/535121-na-spatne-strane/komentare/) _(id: 535121)_ | ||
### Results | ||
#### Results | ||
@@ -71,3 +71,3 @@ ```javascript | ||
], | ||
poster: '//image.pmgstatic.com/cache/resized/w1080/files/images/film/posters/163/579/163579352_bf8737.jpg', | ||
poster: 'https://image.pmgstatic.com/cache/resized/w1080/files/images/film/posters/163/579/163579352_bf8737.jpg', | ||
creators: { | ||
@@ -139,3 +139,3 @@ directors: [ | ||
## Search | ||
### Search | ||
@@ -150,3 +150,3 @@ > Search movies and users | ||
### Results | ||
#### Results | ||
@@ -183,3 +183,3 @@ ```javascript | ||
userRealName: 'Lukáš Barták', | ||
avatar: '//image.pmgstatic.com/cache/resized/w45h60/files/images/user/avatars/000/281/281554_1c0fef.jpg', | ||
avatar: 'https://image.pmgstatic.com/cache/resized/w45h60/files/images/user/avatars/000/281/281554_1c0fef.jpg', | ||
url: 'https://www.csfd.cz/uzivatel/912-bart/' | ||
@@ -190,3 +190,3 @@ } | ||
## Creators | ||
### Creators | ||
@@ -201,3 +201,3 @@ > Search creators and filmography | ||
### Results | ||
#### Results | ||
@@ -210,3 +210,3 @@ ```javascript | ||
birthplace: 'Knoxville, Tennessee, USA', | ||
photo: '//image.pmgstatic.com/cache/resized/w100h132crop/files/images/creator/photos/164/515/164515525_b98f8a.jpg', | ||
photo: 'https://image.pmgstatic.com/cache/resized/w100h132crop/files/images/creator/photos/164/515/164515525_b98f8a.jpg', | ||
age: 58, | ||
@@ -280,5 +280,5 @@ bio: 'Quentin Tarantino se narodil 27. března roku 1963 v americkém Knoxville teprve šestnáctileté Connie Tarantinové. Své jméno Quentin dostal podle matčiny oblíbené televizní postavy Quinta ze seriálu "Gunsmoke". Quentinův otec byl jistý Tony Tarantino, který rodinu opustil když byl Quentin ještě malinký. Jeho dětství a dospívání ovlivnily nejen filmy, ale pop kultura obecně. Televizní seriály, komiksy, populární hudba, to vše jako mladý hltal ve velkém a stále neměl…', | ||
## User Ratings | ||
### User Ratings | ||
### Last ratings (last page) | ||
#### Last ratings (last page) | ||
@@ -293,3 +293,3 @@ Get [my last 50 ratings](https://www.csfd.cz/uzivatel/912-bart/hodnoceni/) | ||
### All ratings (all pages) | ||
#### All ratings (all pages) | ||
@@ -311,3 +311,3 @@ > Warning: Use it wisely. Can be detected and banned. Consider using it together with `allPagesDelay` attribute. | ||
### Results | ||
#### Results | ||
@@ -337,10 +337,10 @@ ```javascript | ||
### Options | ||
#### Options | ||
| Option | Type | Default | Description | | ||
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | --------------------------------------------------------- | | ||
| **includesOnly** | [CSFDFilmTypes[]](https://github.com/bartholomej/node-csfd-api/blob/8fa5f9cbc7e7f2b62b0bd2c2b5a24c9a63444f6a/src/interfaces/global.ts#L25) | null | Including only film types. eg. `['TV Seriál', 'koncert']` | | ||
| **exclude** | [CSFDFilmTypes[]](https://github.com/bartholomej/node-csfd-api/blob/8fa5f9cbc7e7f2b62b0bd2c2b5a24c9a63444f6a/src/interfaces/global.ts#L25) | null | Excluding film types eg. `['epizoda', 'série']` | | ||
| **allPages** | boolean | false | Get all pages | | ||
| **allPagesDelay** | number | 0 | Delay on each page request. In milliseconds | | ||
| Option | Type | Default | Description | | ||
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- | ------------------------------------------------------ | | ||
| **includesOnly** | [CSFDFilmTypes[]](https://github.com/bartholomej/node-csfd-api/blob/8fa5f9cbc7e7f2b62b0bd2c2b5a24c9a63444f6a/src/interfaces/global.ts#L25) | null | Including only film types. eg. `['seriál', 'koncert']` | | ||
| **exclude** | [CSFDFilmTypes[]](https://github.com/bartholomej/node-csfd-api/blob/8fa5f9cbc7e7f2b62b0bd2c2b5a24c9a63444f6a/src/interfaces/global.ts#L25) | null | Excluding film types eg. `['epizoda', 'série']` | | ||
| **allPages** | boolean | false | Get all pages | | ||
| **allPagesDelay** | number | 0 | Delay on each page request. In milliseconds | | ||
@@ -347,0 +347,0 @@ _Note: You can not use both parameters 'includesOnly' and 'excludes'. Parameter 'includesOnly' has a priority._ |
@@ -16,10 +16,11 @@ "use strict"; | ||
const movieNode = movieHtml.querySelector('.main-movie-profile'); | ||
this.buildMovie(+movieId, movieNode, asideNode, pageClasses); | ||
const jsonLd = movieHtml.querySelector('script[type="application/ld+json"]').innerText; | ||
this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd); | ||
return this.film; | ||
} | ||
buildMovie(movieId, el, asideEl, pageClasses) { | ||
buildMovie(movieId, el, asideEl, pageClasses, jsonLd) { | ||
this.film = { | ||
id: movieId, | ||
title: (0, movie_helper_1.getTitle)(el), | ||
year: (0, movie_helper_1.getYear)(el), | ||
year: (0, movie_helper_1.getYear)(jsonLd), | ||
duration: (0, movie_helper_1.getDuration)(el), | ||
@@ -37,3 +38,3 @@ descriptions: (0, movie_helper_1.getDescriptions)(el), | ||
creators: { | ||
directors: (0, movie_helper_1.getDirectors)(el), | ||
directors: (0, movie_helper_1.getGroup)(el, 'Režie'), | ||
writers: (0, movie_helper_1.getGroup)(el, 'Scénář'), | ||
@@ -40,0 +41,0 @@ cinematography: (0, movie_helper_1.getGroup)(el, 'Kamera'), |
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
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
58486
1058
38
+ Addedcross-fetch@^3.1.4
+ Addedcross-fetch@3.1.8(transitive)
+ Addednode-fetch@2.7.0(transitive)
- Removednode-fetch@cjs
- Removednode-fetch@2.6.7(transitive)