node-csfd-api
Advanced tools
Comparing version 0.6.2 to 1.0.0-beta.0
export declare const fetchUserRatings: (user: string | number) => Promise<string>; | ||
export declare const fetchMovie: (movie: string | number) => Promise<string>; | ||
export declare const fetchMovie: (movieId: number) => Promise<string>; |
@@ -15,4 +15,4 @@ "use strict"; | ||
exports.fetchUserRatings = fetchUserRatings; | ||
const fetchMovie = async (movie) => { | ||
const url = vars_1.movieUrl(movie); | ||
const fetchMovie = async (movieId) => { | ||
const url = vars_1.movieUrl(+movieId); | ||
const response = await cross_fetch_1.default(url); | ||
@@ -19,0 +19,0 @@ return await response.text(); |
@@ -11,2 +11,3 @@ import { CSFDColorRating } from 'interfaces/global'; | ||
export declare const getYear: (el: HTMLElement) => string | number; | ||
export declare const getDuration: (el: HTMLElement) => number; | ||
export declare const getOtherTitles: (el: HTMLElement) => CSFDOtherTitles[]; | ||
@@ -19,2 +20,3 @@ export declare const getPoster: (el: HTMLElement) => string; | ||
export declare const getType: (el: HTMLElement) => string; | ||
export declare const getBoxContent: (el: HTMLElement, box: string) => HTMLElement; | ||
export declare const getTags: (el: HTMLElement) => string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTags = exports.getType = exports.getGroup = exports.parsePeople = exports.getDirectors = exports.getDescriptions = exports.getPoster = exports.getOtherTitles = exports.getYear = exports.getRating = exports.getColorRating = exports.getOrigins = exports.getGenres = exports.getTitle = exports.getId = void 0; | ||
exports.getTags = exports.getBoxContent = exports.getType = exports.getGroup = exports.parsePeople = exports.getDirectors = exports.getDescriptions = exports.getPoster = exports.getOtherTitles = exports.getDuration = exports.getYear = exports.getRating = exports.getColorRating = exports.getOrigins = exports.getGenres = exports.getTitle = exports.getId = void 0; | ||
const global_helper_1 = require("./global.helper"); | ||
const getId = (el) => { | ||
const url = el.querySelector('.navigation a').attributes.href; | ||
const url = el.querySelector('.tabs .tab-nav-list a').attributes.href; | ||
return global_helper_1.parseIdFromUrl(url); | ||
@@ -15,3 +15,3 @@ }; | ||
const getGenres = (el) => { | ||
const genresRaw = el.querySelector('.genre').text; | ||
const genresRaw = el.querySelector('.genres').text; | ||
return genresRaw.split(' / '); | ||
@@ -27,11 +27,10 @@ }; | ||
const getColorRating = (bodyClasses) => { | ||
const colorRatingClass = bodyClasses.find((cls) => cls.includes('th')); | ||
switch (colorRatingClass) { | ||
case 'th-0': | ||
switch (bodyClasses[1]) { | ||
case 'page-lightgrey': | ||
return 'unknown'; | ||
case 'th-1': | ||
case 'page-red': | ||
return 'good'; | ||
case 'th-2': | ||
case 'page-blue': | ||
return 'average'; | ||
case 'th-3': | ||
case 'page-grey': | ||
return 'bad'; | ||
@@ -44,5 +43,6 @@ default: | ||
const getRating = (el) => { | ||
const ratingRaw = el.querySelector('#rating .average').text; | ||
if (ratingRaw !== '') { | ||
return +ratingRaw.replace(/%/g, ''); | ||
const ratingRaw = el.querySelector('.rating-average').text; | ||
const rating = +(ratingRaw === null || ratingRaw === void 0 ? void 0 : ratingRaw.replace(/%/g, '').trim()); | ||
if (Number.isInteger(rating)) { | ||
return rating; | ||
} | ||
@@ -58,7 +58,18 @@ else { | ||
exports.getYear = getYear; | ||
const getDuration = (el) => { | ||
const origin = el.querySelector('.origin').innerText; | ||
const timeString = origin.split(',').pop().trim(); | ||
const timeRaw = timeString.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; | ||
}; | ||
exports.getDuration = getDuration; | ||
const getOtherTitles = (el) => { | ||
const namesNode = el.querySelectorAll('ul.names li'); | ||
const namesNode = el.querySelectorAll('.film-names li'); | ||
return namesNode.map((el) => { | ||
const country = el.querySelector('img').attributes.alt; | ||
const title = el.querySelector('h3').text; | ||
const country = el.querySelector('img.flag').attributes.alt; | ||
const title = el.text.trim().split('\n')[0]; | ||
if (country && title) { | ||
@@ -77,7 +88,20 @@ return { | ||
const getPoster = (el) => { | ||
return el.querySelector('#poster img').attributes.src; | ||
var _a; | ||
const poster = el.querySelector('.film-posters img'); | ||
// Resolve empty image | ||
if ((_a = poster.classNames) === null || _a === void 0 ? void 0 : _a.includes('empty-image')) { | ||
return null; | ||
} | ||
else { | ||
// Full sized image (not thumb) | ||
return poster.attributes.src.split('?')[0]; | ||
} | ||
}; | ||
exports.getPoster = getPoster; | ||
const getDescriptions = (el) => { | ||
return el.querySelectorAll('#plots ul li').map((desc) => desc.text.trim()); | ||
var _a; | ||
// TODO more plots | ||
const plot = (_a = el | ||
.querySelector('.body--plots .plot-preview p')) === null || _a === void 0 ? void 0 : _a.text.trim().replace(/(\r\n|\n|\r|\t)/gm, ''); | ||
return plot ? [plot] : []; | ||
}; | ||
@@ -93,3 +117,6 @@ exports.getDescriptions = getDescriptions; | ||
const people = el.querySelectorAll('a'); | ||
return people.map((person) => { | ||
return (people | ||
// Filter out "more" links | ||
.filter((x) => x.classNames.length === 0) | ||
.map((person) => { | ||
return { | ||
@@ -100,3 +127,3 @@ id: global_helper_1.parseIdFromUrl(person.attributes.href), | ||
}; | ||
}); | ||
})); | ||
}; | ||
@@ -121,3 +148,9 @@ exports.parsePeople = parsePeople; | ||
exports.getType = getType; | ||
const getBoxContent = (el, box) => { | ||
const headers = el.querySelectorAll('section.box .box-header h3'); | ||
return headers.find((header) => header.text.trim().includes(box)); | ||
}; | ||
exports.getBoxContent = getBoxContent; | ||
const getTags = (el) => { | ||
// const tagsRaw = getBoxContent(el, 'Tagy'); | ||
const tagsRaw = el.querySelectorAll('.tags .content a'); | ||
@@ -124,0 +157,0 @@ return tagsRaw.map((elem) => elem.text.trim()); |
@@ -0,1 +1,2 @@ | ||
import { Colors } from 'interfaces/user-ratings.interface'; | ||
import { HTMLElement } from 'node-html-parser'; | ||
@@ -11,2 +12,2 @@ import { CSFDColorRating, CSFDFilmTypes, CSFDStars } from '../interfaces/global'; | ||
export declare const getUrl: (el: HTMLElement) => string; | ||
export declare const parseColor: (quality: number) => CSFDColorRating; | ||
export declare const parseColor: (quality: Colors) => CSFDColorRating; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const getId = (el) => { | ||
const url = el.querySelector('td a.film').rawAttributes.href; | ||
const url = el.querySelector('td.name .film-title-name').attributes.href; | ||
return global_helper_1.parseIdFromUrl(url); | ||
@@ -12,4 +12,4 @@ }; | ||
const getUserRating = (el) => { | ||
const ratingText = el.querySelector('td .rating').attributes.alt; | ||
const rating = ratingText ? ratingText.length : 0; | ||
const ratingText = el.querySelector('td.star-rating-only .stars').classNames.pop(); | ||
const rating = ratingText.includes('stars-') ? +ratingText.split('-').pop() : 0; | ||
return rating; | ||
@@ -19,24 +19,25 @@ }; | ||
const getType = (el) => { | ||
const typeText = el.querySelector('td .film-type'); | ||
return (typeText ? typeText.innerText.slice(1, -1) : 'film'); | ||
const typeText = el.querySelectorAll('td.name .film-title-info .info'); | ||
return (typeText.length > 1 ? typeText[1].text.slice(1, -1) : 'film'); | ||
}; | ||
exports.getType = getType; | ||
const getTitle = (el) => { | ||
return el.querySelector('td .film').text; | ||
return el.querySelector('td.name .film-title-name').text; | ||
}; | ||
exports.getTitle = getTitle; | ||
const getYear = (el) => { | ||
return +el.querySelector('td .film-year').innerText.slice(1, -1); | ||
return +el.querySelectorAll('td.name .film-title-info .info')[0].text.slice(1, -1); | ||
}; | ||
exports.getYear = getYear; | ||
const getColorRating = (el) => { | ||
return exports.parseColor(+el.querySelector('td a.film').classNames[1].slice(1, 2)); | ||
const color = exports.parseColor(el.querySelector('td.name .icon').classNames.pop()); | ||
return color; | ||
}; | ||
exports.getColorRating = getColorRating; | ||
const getDate = (el) => { | ||
return el.querySelectorAll('td')[2].rawText; | ||
return el.querySelector('td.date-only').text.trim(); | ||
}; | ||
exports.getDate = getDate; | ||
const getUrl = (el) => { | ||
const url = el.querySelector('td a.film').rawAttributes.href; | ||
const url = el.querySelector('td.name .film-title-name').attributes.href; | ||
return `https://www.csfd.cz${url}`; | ||
@@ -47,9 +48,9 @@ }; | ||
switch (quality) { | ||
case 0: | ||
case 'lightgrey': | ||
return 'unknown'; | ||
case 1: | ||
case 'red': | ||
return 'good'; | ||
case 2: | ||
case 'blue': | ||
return 'average'; | ||
case 3: | ||
case 'grey': | ||
return 'bad'; | ||
@@ -56,0 +57,0 @@ default: |
@@ -14,4 +14,4 @@ import { CSFDMovie } from 'interfaces/movie.interface'; | ||
}): Promise<CSFDUserRatings[]>; | ||
movie(movie: string | number): Promise<CSFDMovie>; | ||
movie(movie: number): Promise<CSFDMovie>; | ||
} | ||
export declare const csfd: Csfd; |
@@ -15,3 +15,3 @@ "use strict"; | ||
async movie(movie) { | ||
return this.movieService.movie(movie); | ||
return this.movieService.movie(+movie); | ||
} | ||
@@ -18,0 +18,0 @@ } |
@@ -5,2 +5,3 @@ import { CSFDScreening } from './global'; | ||
poster: string; | ||
duration: number | string; | ||
otherTitles: CSFDOtherTitles[]; | ||
@@ -42,2 +43,2 @@ origins: string[]; | ||
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ý'; | ||
export declare type CSFDCreatorGroups = 'Režie' | 'Scénář' | 'Kamera' | 'Hudba' | 'Hrají' | 'Producenti' | 'Střih' | 'Předloha' | 'Scénografie' | 'Kostýmy'; | ||
export declare type CSFDCreatorGroups = 'Režie' | 'Scénář' | 'Kamera' | 'Hudba' | 'Hrají' | 'Produkce' | 'Střih' | 'Předloha' | 'Scénografie' | 'Kostýmy'; |
@@ -6,1 +6,2 @@ import { CSFDScreening, CSFDStars } from './global'; | ||
} | ||
export declare type Colors = 'lightgrey' | 'blue' | 'red' | 'grey'; |
{ | ||
"name": "node-csfd-api", | ||
"version": "0.6.2", | ||
"version": "1.0.0-beta.0", | ||
"description": "Simple NPM library for scraping CSFD", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
import { CSFDMovie } from 'interfaces/movie.interface'; | ||
export declare class MovieScraper { | ||
private film; | ||
movie(movie: string | number): Promise<CSFDMovie>; | ||
movie(movieId: number): Promise<CSFDMovie>; | ||
private buildMovie; | ||
} |
@@ -9,21 +9,23 @@ "use strict"; | ||
class MovieScraper { | ||
async movie(movie) { | ||
const response = await fetchers_1.fetchMovie(movie); | ||
async movie(movieId) { | ||
const response = await fetchers_1.fetchMovie(+movieId); | ||
const movieHtml = node_html_parser_1.parse(response); | ||
const movieNode = movieHtml.querySelector('#pg-web-film'); | ||
const bodyClasses = movieHtml.querySelector('body').classNames; | ||
this.buildMovie(movieNode, movie, bodyClasses); | ||
const pageClasses = movieHtml.querySelector('.page-content').classNames; | ||
const asideNode = movieHtml.querySelector('.box-rating-container'); | ||
const movieNode = movieHtml.querySelector('.main-movie-profile'); | ||
this.buildMovie(+movieId, movieNode, asideNode, pageClasses); | ||
return this.film; | ||
} | ||
buildMovie(el, movie, bodyClasses) { | ||
buildMovie(movieId, el, elAside, pageClasses) { | ||
this.film = { | ||
id: movie_helper_1.getId(el), | ||
id: movieId, | ||
title: movie_helper_1.getTitle(el), | ||
year: movie_helper_1.getYear(el), | ||
duration: movie_helper_1.getDuration(el), | ||
descriptions: movie_helper_1.getDescriptions(el), | ||
genres: movie_helper_1.getGenres(el), | ||
type: movie_helper_1.getType(el), | ||
url: vars_1.movieUrl(movie), | ||
url: vars_1.movieUrl(movieId), | ||
origins: movie_helper_1.getOrigins(el), | ||
colorRating: movie_helper_1.getColorRating(bodyClasses), | ||
colorRating: movie_helper_1.getColorRating(pageClasses), | ||
rating: movie_helper_1.getRating(el), | ||
@@ -39,3 +41,3 @@ otherTitles: movie_helper_1.getOtherTitles(el), | ||
basedOn: movie_helper_1.getGroup(el, 'Předloha'), | ||
producers: movie_helper_1.getGroup(el, 'Producenti'), | ||
producers: movie_helper_1.getGroup(el, 'Produkce'), | ||
filmEditing: movie_helper_1.getGroup(el, 'Střih'), | ||
@@ -45,3 +47,3 @@ costumeDesign: movie_helper_1.getGroup(el, 'Kostýmy'), | ||
}, | ||
tags: movie_helper_1.getTags(el) | ||
tags: movie_helper_1.getTags(elAside) | ||
}; | ||
@@ -48,0 +50,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
const items = node_html_parser_1.parse(response); | ||
const movies = items.querySelectorAll('.ui-table-list tbody tr'); | ||
const movies = items.querySelectorAll('.box-user-rating .table-container tbody tr'); | ||
if (config) { | ||
@@ -18,0 +18,0 @@ if (((_a = config.includesOnly) === null || _a === void 0 ? void 0 : _a.length) && ((_b = config.excludes) === null || _b === void 0 ? void 0 : _b.length)) { |
export declare const userRatingsUrl: (user: string | number) => string; | ||
export declare const movieUrl: (movie: string | number) => string; | ||
export declare const movieUrl: (movie: number) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.movieUrl = exports.userRatingsUrl = void 0; | ||
const userRatingsUrl = (user) => `https://www.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/`; | ||
const userRatingsUrl = (user) => `https://new.csfd.cz/uzivatel/${encodeURIComponent(user)}/hodnoceni/`; | ||
exports.userRatingsUrl = userRatingsUrl; | ||
const movieUrl = (movie) => `https://www.csfd.cz/film/${encodeURIComponent(movie)}`; | ||
const movieUrl = (movie) => `https://new.csfd.cz/film/${encodeURIComponent(movie)}`; | ||
exports.movieUrl = movieUrl; |
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
27272
519