UNPKG

node-csfd-api

Version:

ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)

52 lines (50 loc) 2.03 kB
const require_global_helper = require('./global.helper.js'); //#region src/helpers/search.helper.ts const getSearchType = (el) => { return el.querySelectorAll(".film-title-info .info")[1]?.innerText?.replace(/[{()}]/g, "")?.trim() || "film"; }; const getSearchTitle = (el) => { return el.querySelector(".film-title-name").text; }; const getSearchYear = (el) => { return +el.querySelectorAll(".film-title-info .info")[0]?.innerText.replace(/[{()}]/g, ""); }; const getSearchUrl = (el) => { return el.querySelector(".film-title-name").attributes.href; }; const getSearchColorRating = (el) => { return require_global_helper.parseColor(el.querySelector(".article-header i.icon").classNames.split(" ").pop()); }; const getSearchPoster = (el) => { const image = el.querySelector("img").attributes.src; return require_global_helper.addProtocol(image); }; const getSearchOrigins = (el) => { const originsRaw = el.querySelector(".article-content p .info")?.text; if (!originsRaw) return []; return (originsRaw?.split(", ")?.[0])?.split("/").map((country) => country.trim()); }; const parseSearchPeople = (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$1) => el$1.textContent.includes(who)); if (peopleNode) return Array.from(peopleNode.querySelectorAll("a")).map((person) => { return { id: require_global_helper.parseIdFromUrl(person.attributes.href), name: person.innerText.trim(), url: `https://www.csfd.cz${person.attributes.href}` }; }); else return []; }; //#endregion exports.getSearchColorRating = getSearchColorRating; exports.getSearchOrigins = getSearchOrigins; exports.getSearchPoster = getSearchPoster; exports.getSearchTitle = getSearchTitle; exports.getSearchType = getSearchType; exports.getSearchUrl = getSearchUrl; exports.getSearchYear = getSearchYear; exports.parseSearchPeople = parseSearchPeople; //# sourceMappingURL=search.helper.js.map