node-csfd-api
Version:
ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)
45 lines (43 loc) • 1.79 kB
JavaScript
import { addProtocol, parseColor, parseIdFromUrl } from "./global.helper.mjs";
//#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 parseColor(el.querySelector(".article-header i.icon").classNames.split(" ").pop());
};
const getSearchPoster = (el) => {
const image = el.querySelector("img").attributes.src;
return 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: parseIdFromUrl(person.attributes.href),
name: person.innerText.trim(),
url: `https://www.csfd.cz${person.attributes.href}`
};
});
else return [];
};
//#endregion
export { getSearchColorRating, getSearchOrigins, getSearchPoster, getSearchTitle, getSearchType, getSearchUrl, getSearchYear, parseSearchPeople };
//# sourceMappingURL=search.helper.mjs.map