node-csfd-api-racintom
Version:
ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)
44 lines (43 loc) • 1.81 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeasonScraper = void 0;
const fetchers_1 = require("../fetchers");
const node_html_parser_1 = require("node-html-parser");
const vars_1 = require("../vars");
class SeasonScraper {
async season(url) {
const response = await (0, fetchers_1.fetchPage)((0, vars_1.seasonUrl)(url));
const seasonHtml = (0, node_html_parser_1.parse)(response);
const movieNode = seasonHtml.querySelector('.main-movie-profile');
return this.buildSeason(movieNode);
}
buildSeason(movieNode) {
return {
origin: this.getOriginFromHtml(movieNode),
description: this.getDescriptionFromHtml(movieNode),
thumbnail: this.getThumbnailFromHtml(movieNode),
episodeList: this.getEpisodeListFromHtml(movieNode),
};
}
getOriginFromHtml(movieNode) {
return movieNode.querySelector('.film-info-content .origin').textContent;
}
getDescriptionFromHtml(movieNode) {
var _a;
return (_a = movieNode.querySelector('.plot-full')) === null || _a === void 0 ? void 0 : _a.textContent;
}
getThumbnailFromHtml(movieNode) {
return movieNode.querySelector('.film-posters img').getAttribute('src');
}
getEpisodeListFromHtml(movieNode) {
return movieNode.querySelectorAll('.film-episodes-list li').map(container => {
const nameContainer = container.querySelector('.film-title-name');
return {
name: nameContainer.textContent,
seasonEpisodeIdentifier: container.querySelector('.film-title-info').textContent,
linkToDetail: nameContainer.getAttribute('href'),
};
});
}
}
exports.SeasonScraper = SeasonScraper;
;