UNPKG

node-csfd-api

Version:

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

48 lines (46 loc) 2.02 kB
import { parseColor, parseIdFromUrl } from "./global.helper.mjs"; //#region src/helpers/user-reviews.helper.ts const getUserReviewId = (el) => { const url = el.querySelector(".film-title-name").attributes.href; return parseIdFromUrl(url); }; const getUserReviewRating = (el) => { const ratingText = el.querySelector(".star-rating .stars").classNames.split(" ").pop(); return ratingText.includes("stars-") ? +ratingText.split("-").pop() : 0; }; const getUserReviewType = (el) => { const typeText = el.querySelectorAll(".film-title-info .info"); return typeText.length > 1 ? typeText[1].text.slice(1, -1) : "film"; }; const getUserReviewTitle = (el) => { return el.querySelector(".film-title-name").text; }; const getUserReviewYear = (el) => { const infoSpan = el.querySelector(".film-title-info .info"); return infoSpan ? +infoSpan.text.replace(/[()]/g, "") : null; }; const getUserReviewColorRating = (el) => { return parseColor(el.querySelector(".film-title-nooverflow .icon")?.classNames.split(" ").pop()); }; const getUserReviewDate = (el) => { return el.querySelector(".header-right-info .info time").text.trim(); }; const getUserReviewUrl = (el) => { return `https://www.csfd.cz${el.querySelector(".film-title-name").attributes.href}`; }; const getUserReviewText = (el) => { return el.querySelector(".user-reviews-text .comment").text.trim(); }; const getUserReviewPoster = (el) => { const img = el.querySelector(".article-img img"); const srcset = img?.attributes.srcset; if (srcset) { const poster3x = srcset.split(",").map((s) => s.trim()).find((s) => s.endsWith("3x")); if (poster3x) return `https:${poster3x.replace(/\s+3x$/, "").trim()}`; } const src = img?.attributes.src; return src ? `https:${src}` : null; }; //#endregion export { getUserReviewColorRating, getUserReviewDate, getUserReviewId, getUserReviewPoster, getUserReviewRating, getUserReviewText, getUserReviewTitle, getUserReviewType, getUserReviewUrl, getUserReviewYear }; //# sourceMappingURL=user-reviews.helper.mjs.map