node-csfd-api
Version:
ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)
63 lines (62 loc) • 2.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.parsePeople = exports.getOrigins = exports.getPoster = exports.getColorRating = exports.getUrl = exports.getYear = exports.getTitle = exports.getType = void 0;
const global_helper_1 = require("./global.helper");
const getType = (el) => {
const type = el.querySelectorAll('.film-title-info .info')[1];
return ((type === null || type === void 0 ? void 0 : type.innerText.replace(/[{()}]/g, '')) || 'film');
};
exports.getType = getType;
const getTitle = (el) => {
return el.querySelector('.film-title-name').text;
};
exports.getTitle = getTitle;
const getYear = (el) => {
var _a;
return +((_a = el.querySelectorAll('.film-title-info .info')[0]) === null || _a === void 0 ? void 0 : _a.innerText.replace(/[{()}]/g, ''));
};
exports.getYear = getYear;
const getUrl = (el) => {
return el.querySelector('.film-title-name').attributes.href;
};
exports.getUrl = getUrl;
const getColorRating = (el) => {
return (0, global_helper_1.parseColor)(el.querySelector('.article-header i.icon').classNames.split(' ').pop());
};
exports.getColorRating = getColorRating;
const getPoster = (el) => {
const image = el.querySelector('img').attributes.src;
return (0, global_helper_1.addProtocol)(image);
};
exports.getPoster = getPoster;
const getOrigins = (el) => {
var _a, _b;
const originsRaw = (_a = el.querySelector('.article-content p .info')) === null || _a === void 0 ? void 0 : _a.text;
if (!originsRaw)
return [];
const originsAll = (_b = originsRaw === null || originsRaw === void 0 ? void 0 : originsRaw.split(', ')) === null || _b === void 0 ? void 0 : _b[0];
return originsAll === null || originsAll === void 0 ? void 0 : originsAll.split('/').map((country) => country.trim());
};
exports.getOrigins = getOrigins;
const parsePeople = (el, type) => {
let who;
if (type === 'directors')
who = 'Režie:';
if (type === 'actors')
who = 'Hrají:';
const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) => el.textContent.includes(who));
if (peopleNode) {
const people = Array.from(peopleNode.querySelectorAll('a'));
return people.map((person) => {
return {
id: (0, global_helper_1.parseIdFromUrl)(person.attributes.href),
name: person.innerText.trim(),
url: `https://www.csfd.cz${person.attributes.href}`
};
});
}
else {
return [];
}
};
exports.parsePeople = parsePeople;
;