node-csfd-api 5.4.0 → 5.5.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{export-ratings.mjs → export-ratings.js} +1 -1
- package/bin/{mcp-server.mjs → mcp-server.js} +2 -2
- package/bin/{server.mjs → server.js} +2 -2
- package/{cli.mjs → cli.js} +3 -3
- package/dto/{cinema.d.mts → cinema.d.cts} +2 -2
- package/dto/{creator.d.mts → creator.d.cts} +2 -2
- package/dto/{global.d.mts → global.d.cts} +1 -1
- package/dto/{movie.d.mts → movie.d.cts} +2 -2
- package/dto/{options.d.mts → options.d.cts} +1 -1
- package/dto/{search.d.mts → search.d.cts} +3 -3
- package/dto/{user-ratings.d.mts → user-ratings.d.cts} +2 -2
- package/dto/{user-reviews.d.mts → user-reviews.d.cts} +2 -2
- package/fetchers/{fetch.polyfill.mjs → fetch.polyfill.cjs} +3 -4
- package/fetchers/fetch.polyfill.cjs.map +1 -0
- package/fetchers/fetch.polyfill.js +2 -3
- package/fetchers/fetch.polyfill.js.map +1 -1
- package/fetchers/{index.mjs → index.cjs} +4 -4
- package/fetchers/index.cjs.map +1 -0
- package/fetchers/index.js +3 -3
- package/fetchers/index.js.map +1 -1
- package/helpers/{cinema.helper.mjs → cinema.helper.cjs} +9 -5
- package/helpers/cinema.helper.cjs.map +1 -0
- package/helpers/cinema.helper.js +4 -8
- package/helpers/cinema.helper.js.map +1 -1
- package/helpers/{creator.helper.mjs → creator.helper.cjs} +11 -7
- package/helpers/creator.helper.cjs.map +1 -0
- package/helpers/creator.helper.js +6 -10
- package/helpers/creator.helper.js.map +1 -1
- package/helpers/{global.helper.mjs → global.helper.cjs} +10 -2
- package/helpers/{global.helper.mjs.map → global.helper.cjs.map} +1 -1
- package/helpers/global.helper.js +1 -9
- package/helpers/{movie.helper.mjs → movie.helper.cjs} +36 -13
- package/helpers/movie.helper.cjs.map +1 -0
- package/helpers/movie.helper.js +12 -35
- package/helpers/movie.helper.js.map +1 -1
- package/helpers/{search-creator.helper.mjs → search-creator.helper.cjs} +6 -4
- package/helpers/search-creator.helper.cjs.map +1 -0
- package/helpers/search-creator.helper.js +3 -5
- package/helpers/search-creator.helper.js.map +1 -1
- package/helpers/{search-user.helper.mjs → search-user.helper.cjs} +9 -6
- package/helpers/search-user.helper.cjs.map +1 -0
- package/helpers/search-user.helper.js +5 -8
- package/helpers/search-user.helper.js.map +1 -1
- package/helpers/{search.helper.mjs → search.helper.cjs} +14 -7
- package/helpers/search.helper.cjs.map +1 -0
- package/helpers/search.helper.js +6 -13
- package/helpers/search.helper.js.map +1 -1
- package/helpers/{user-ratings.helper.mjs → user-ratings.helper.cjs} +14 -7
- package/helpers/user-ratings.helper.cjs.map +1 -0
- package/helpers/user-ratings.helper.js +6 -13
- package/helpers/user-ratings.helper.js.map +1 -1
- package/helpers/{user-reviews.helper.mjs → user-reviews.helper.cjs} +16 -7
- package/helpers/user-reviews.helper.cjs.map +1 -0
- package/helpers/user-reviews.helper.js +6 -15
- package/helpers/user-reviews.helper.js.map +1 -1
- package/{index.mjs → index.cjs} +16 -13
- package/index.cjs.map +1 -0
- package/{index.d.mts → index.d.cts} +15 -15
- package/index.js +13 -14
- package/index.js.map +1 -1
- package/{package.mjs → package.js} +1 -1
- package/package.json +13 -7
- package/services/cinema.service.cjs +31 -0
- package/services/cinema.service.cjs.map +1 -0
- package/services/{cinema.service.d.mts → cinema.service.d.cts} +3 -3
- package/services/cinema.service.js +11 -11
- package/services/cinema.service.js.map +1 -1
- package/services/creator.service.cjs +32 -0
- package/services/creator.service.cjs.map +1 -0
- package/services/{creator.service.d.mts → creator.service.d.cts} +3 -3
- package/services/creator.service.js +11 -11
- package/services/creator.service.js.map +1 -1
- package/services/movie.service.cjs +61 -0
- package/services/movie.service.cjs.map +1 -0
- package/services/{movie.service.d.mts → movie.service.d.cts} +3 -3
- package/services/movie.service.js +33 -33
- package/services/movie.service.js.map +1 -1
- package/services/search.service.cjs +75 -0
- package/services/search.service.cjs.map +1 -0
- package/services/{search.service.d.mts → search.service.d.cts} +3 -3
- package/services/search.service.js +29 -29
- package/services/search.service.js.map +1 -1
- package/services/{user-ratings.service.mjs → user-ratings.service.cjs} +19 -19
- package/services/user-ratings.service.cjs.map +1 -0
- package/services/{user-ratings.service.d.mts → user-ratings.service.d.cts} +3 -3
- package/services/user-ratings.service.js +18 -18
- package/services/user-ratings.service.js.map +1 -1
- package/services/{user-reviews.service.mjs → user-reviews.service.cjs} +21 -21
- package/services/user-reviews.service.cjs.map +1 -0
- package/services/{user-reviews.service.d.mts → user-reviews.service.d.cts} +3 -3
- package/services/user-reviews.service.js +20 -20
- package/services/user-reviews.service.js.map +1 -1
- package/src/fetchers/{fetch.polyfill.mjs → fetch.polyfill.js} +1 -3
- package/src/fetchers/{index.mjs → index.js} +1 -1
- package/src/helpers/{cinema.helper.mjs → cinema.helper.js} +1 -1
- package/src/helpers/{creator.helper.mjs → creator.helper.js} +1 -1
- package/src/helpers/{movie.helper.mjs → movie.helper.js} +1 -1
- package/src/helpers/{search-creator.helper.mjs → search-creator.helper.js} +1 -1
- package/src/helpers/{search-user.helper.mjs → search-user.helper.js} +1 -1
- package/src/helpers/{search.helper.mjs → search.helper.js} +1 -1
- package/src/helpers/{user-ratings.helper.mjs → user-ratings.helper.js} +1 -1
- package/src/helpers/{user-reviews.helper.mjs → user-reviews.helper.js} +1 -1
- package/src/{index.mjs → index.js} +7 -6
- package/src/services/{cinema.service.mjs → cinema.service.js} +3 -3
- package/src/services/{creator.service.mjs → creator.service.js} +3 -3
- package/src/services/{movie.service.mjs → movie.service.js} +3 -3
- package/src/services/{search.service.mjs → search.service.js} +6 -6
- package/src/services/{user-ratings.service.mjs → user-ratings.service.js} +4 -4
- package/src/services/{user-reviews.service.mjs → user-reviews.service.js} +4 -4
- package/{vars.mjs → vars.cjs} +8 -2
- package/{vars.mjs.map → vars.cjs.map} +1 -1
- package/vars.js +1 -7
- package/fetchers/fetch.polyfill.mjs.map +0 -1
- package/fetchers/index.mjs.map +0 -1
- package/helpers/cinema.helper.mjs.map +0 -1
- package/helpers/creator.helper.mjs.map +0 -1
- package/helpers/movie.helper.mjs.map +0 -1
- package/helpers/search-creator.helper.mjs.map +0 -1
- package/helpers/search-user.helper.mjs.map +0 -1
- package/helpers/search.helper.mjs.map +0 -1
- package/helpers/user-ratings.helper.mjs.map +0 -1
- package/helpers/user-reviews.helper.mjs.map +0 -1
- package/index.mjs.map +0 -1
- package/services/cinema.service.mjs +0 -31
- package/services/cinema.service.mjs.map +0 -1
- package/services/creator.service.mjs +0 -32
- package/services/creator.service.mjs.map +0 -1
- package/services/movie.service.mjs +0 -61
- package/services/movie.service.mjs.map +0 -1
- package/services/search.service.mjs +0 -75
- package/services/search.service.mjs.map +0 -1
- package/services/user-ratings.service.mjs.map +0 -1
- package/services/user-reviews.service.mjs.map +0 -1
- /package/src/helpers/{global.helper.mjs → global.helper.js} +0 -0
- /package/src/{vars.mjs → vars.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const require_global_helper = require("./global.helper.cjs");
|
|
2
2
|
//#region src/helpers/movie.helper.ts
|
|
3
3
|
const CREATOR_LABELS = {
|
|
4
4
|
en: {
|
|
@@ -85,7 +85,7 @@ const getMovieOrigins = (el) => {
|
|
|
85
85
|
return el.querySelector(".origin").textContent.split(",")[0].split(" / ");
|
|
86
86
|
};
|
|
87
87
|
const getMovieColorRating = (bodyClasses) => {
|
|
88
|
-
return getColor(bodyClasses[1]);
|
|
88
|
+
return require_global_helper.getColor(bodyClasses[1]);
|
|
89
89
|
};
|
|
90
90
|
const getMovieRating = (el) => {
|
|
91
91
|
const rating = el.querySelector(".film-rating-average").textContent?.replace(/%/g, "").trim();
|
|
@@ -104,7 +104,7 @@ const getMovieYear = (jsonLd) => {
|
|
|
104
104
|
};
|
|
105
105
|
const getMovieDuration = (jsonLd, el) => {
|
|
106
106
|
if (jsonLd && jsonLd.duration) try {
|
|
107
|
-
return parseISO8601Duration(jsonLd.duration);
|
|
107
|
+
return require_global_helper.parseISO8601Duration(jsonLd.duration);
|
|
108
108
|
} catch (e) {}
|
|
109
109
|
try {
|
|
110
110
|
const timeString = el.querySelector(".origin").innerText.split(",");
|
|
@@ -132,7 +132,7 @@ const getMovieTitlesOther = (el) => {
|
|
|
132
132
|
const getMoviePoster = (el) => {
|
|
133
133
|
const poster = el.querySelector(".film-posters img");
|
|
134
134
|
if (poster) if (poster.classNames?.includes("empty-image")) return null;
|
|
135
|
-
else return addProtocol(poster.attributes.src.split("?")[0].replace(/\/w140\//, "/w1080/"));
|
|
135
|
+
else return require_global_helper.addProtocol(poster.attributes.src.split("?")[0].replace(/\/w140\//, "/w1080/"));
|
|
136
136
|
else return null;
|
|
137
137
|
};
|
|
138
138
|
const getMovieRandomPhoto = (el) => {
|
|
@@ -151,7 +151,7 @@ const getMovieDescriptions = (el) => {
|
|
|
151
151
|
const parseMoviePeople = (el) => {
|
|
152
152
|
return el.querySelectorAll("a").filter((x) => x.classNames.length === 0).map((person) => {
|
|
153
153
|
return {
|
|
154
|
-
id: parseIdFromUrl(person.attributes.href),
|
|
154
|
+
id: require_global_helper.parseIdFromUrl(person.attributes.href),
|
|
155
155
|
name: person.innerText.trim(),
|
|
156
156
|
url: `https://www.csfd.cz${person.attributes.href}`
|
|
157
157
|
};
|
|
@@ -206,7 +206,7 @@ const getSeasonsOrEpisodes = (el) => {
|
|
|
206
206
|
const href = nameContainer?.getAttribute("href");
|
|
207
207
|
const url = href ? href.startsWith("/") ? `https://www.csfd.cz${href}` : href : null;
|
|
208
208
|
return {
|
|
209
|
-
id: parseLastIdFromUrl(href || ""),
|
|
209
|
+
id: require_global_helper.parseLastIdFromUrl(href || ""),
|
|
210
210
|
title: nameContainer?.textContent?.trim() || null,
|
|
211
211
|
url,
|
|
212
212
|
info: infoContainer?.textContent?.replace(/[{()}]/g, "").trim() || null
|
|
@@ -230,8 +230,8 @@ const getSeasonOrEpisodeParent = (el) => {
|
|
|
230
230
|
if (parents.length === 0) parents = el.querySelectorAll(".film-header h1 a");
|
|
231
231
|
if (parents.length === 0) return null;
|
|
232
232
|
const [parentSeries, parentSeason] = parents;
|
|
233
|
-
const seriesId = parseIdFromUrl(parentSeries?.getAttribute("href"));
|
|
234
|
-
const seasonId = parseLastIdFromUrl(parentSeason?.getAttribute("href") || "");
|
|
233
|
+
const seriesId = require_global_helper.parseIdFromUrl(parentSeries?.getAttribute("href"));
|
|
234
|
+
const seasonId = require_global_helper.parseLastIdFromUrl(parentSeason?.getAttribute("href") || "");
|
|
235
235
|
const seriesTitle = parentSeries?.textContent?.trim() || null;
|
|
236
236
|
const seasonTitle = parentSeason?.textContent?.trim() || null;
|
|
237
237
|
const series = seriesId && seriesTitle ? {
|
|
@@ -249,7 +249,7 @@ const getSeasonOrEpisodeParent = (el) => {
|
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
251
|
const getMovieType = (el) => {
|
|
252
|
-
return parseFilmType(el.querySelector(".film-header-name .type")?.innerText?.replace(/[{()}]/g, "") || "film");
|
|
252
|
+
return require_global_helper.parseFilmType(el.querySelector(".film-header-name .type")?.innerText?.replace(/[{()}]/g, "") || "film");
|
|
253
253
|
};
|
|
254
254
|
const getMovieVods = (el) => {
|
|
255
255
|
let vods = [];
|
|
@@ -268,7 +268,7 @@ const getMovieBoxMovies = (el, boxName) => {
|
|
|
268
268
|
const movieListItem = [];
|
|
269
269
|
const movieTitleNodes = getBoxContent(el, boxName)?.querySelectorAll(".article-header .film-title-name");
|
|
270
270
|
if (movieTitleNodes?.length) for (const item of movieTitleNodes) movieListItem.push({
|
|
271
|
-
id: parseIdFromUrl(item.attributes.href),
|
|
271
|
+
id: require_global_helper.parseIdFromUrl(item.attributes.href),
|
|
272
272
|
title: item.textContent.trim(),
|
|
273
273
|
url: `https://www.csfd.cz${item.attributes.href}`
|
|
274
274
|
});
|
|
@@ -281,7 +281,7 @@ const getMoviePremieres = (el) => {
|
|
|
281
281
|
const title = premiereNode.querySelector("p + span").attributes.title;
|
|
282
282
|
if (title) {
|
|
283
283
|
const [dateRaw, ...company] = title?.split(" ");
|
|
284
|
-
const date = parseDate(dateRaw);
|
|
284
|
+
const date = require_global_helper.parseDate(dateRaw);
|
|
285
285
|
if (date) premiere.push({
|
|
286
286
|
country: premiereNode.querySelector(".flag")?.attributes.title || null,
|
|
287
287
|
format: premiereNode.querySelector("p").textContent.trim()?.split(" od")[0],
|
|
@@ -296,6 +296,29 @@ const getMovieTags = (el) => {
|
|
|
296
296
|
return el.querySelectorAll(".box-content a[href*=\"/tag/\"]").map((tag) => tag.textContent);
|
|
297
297
|
};
|
|
298
298
|
//#endregion
|
|
299
|
-
|
|
299
|
+
exports.detectSeasonOrEpisodeListType = detectSeasonOrEpisodeListType;
|
|
300
|
+
exports.getEpisodeCode = getEpisodeCode;
|
|
301
|
+
exports.getMovieBoxMovies = getMovieBoxMovies;
|
|
302
|
+
exports.getMovieColorRating = getMovieColorRating;
|
|
303
|
+
exports.getMovieCreators = getMovieCreators;
|
|
304
|
+
exports.getMovieDescriptions = getMovieDescriptions;
|
|
305
|
+
exports.getMovieDuration = getMovieDuration;
|
|
306
|
+
exports.getMovieGenres = getMovieGenres;
|
|
307
|
+
exports.getMovieOrigins = getMovieOrigins;
|
|
308
|
+
exports.getMoviePoster = getMoviePoster;
|
|
309
|
+
exports.getMoviePremieres = getMoviePremieres;
|
|
310
|
+
exports.getMovieRandomPhoto = getMovieRandomPhoto;
|
|
311
|
+
exports.getMovieRating = getMovieRating;
|
|
312
|
+
exports.getMovieRatingCount = getMovieRatingCount;
|
|
313
|
+
exports.getMovieTags = getMovieTags;
|
|
314
|
+
exports.getMovieTitle = getMovieTitle;
|
|
315
|
+
exports.getMovieTitlesOther = getMovieTitlesOther;
|
|
316
|
+
exports.getMovieTrivia = getMovieTrivia;
|
|
317
|
+
exports.getMovieType = getMovieType;
|
|
318
|
+
exports.getMovieVods = getMovieVods;
|
|
319
|
+
exports.getMovieYear = getMovieYear;
|
|
320
|
+
exports.getSeasonOrEpisodeParent = getSeasonOrEpisodeParent;
|
|
321
|
+
exports.getSeasonsOrEpisodes = getSeasonsOrEpisodes;
|
|
322
|
+
exports.getSeriesAndSeasonTitle = getSeriesAndSeasonTitle;
|
|
300
323
|
|
|
301
|
-
//# sourceMappingURL=movie.helper.
|
|
324
|
+
//# sourceMappingURL=movie.helper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"movie.helper.cjs","names":["getColor","parseISO8601Duration","addProtocol","parseIdFromUrl","parseLastIdFromUrl","parseFilmType","parseDate"],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport type { CSFDColorRating, CSFDFilmTypes } from '../dto/global';\nimport type {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDCreatorGroupsEnglish,\n CSFDCreatorGroupsSlovak,\n CSFDCreators,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDParent,\n CSFDPremiere,\n CSFDSeriesChild,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService,\n MovieJsonLd\n} from '../dto/movie';\nimport type { CSFDOptions } from '../types';\nimport {\n addProtocol,\n getColor,\n parseDate,\n parseFilmType,\n parseISO8601Duration,\n parseIdFromUrl,\n parseLastIdFromUrl\n} from './global.helper';\n\nconst CREATOR_LABELS: Record<\n string,\n Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak>\n> = {\n en: {\n directors: 'Directed by',\n writers: 'Screenplay',\n cinematography: 'Cinematography',\n music: 'Composer',\n actors: 'Cast',\n basedOn: 'Based on',\n producers: 'Produced by',\n filmEditing: 'Editing',\n costumeDesign: 'Costumes',\n productionDesign: 'Production design',\n casting: 'Casting',\n sound: 'Sound',\n makeup: 'Make-up'\n },\n cs: {\n directors: 'Režie',\n writers: 'Scénář',\n cinematography: 'Kamera',\n music: 'Hudba',\n actors: 'Hrají',\n basedOn: 'Předloha',\n producers: 'Produkce',\n filmEditing: 'Střih',\n costumeDesign: 'Kostýmy',\n productionDesign: 'Scénografie',\n casting: 'Casting',\n sound: 'Zvuk',\n makeup: 'Masky'\n },\n sk: {\n directors: 'Réžia',\n writers: 'Scenár',\n cinematography: 'Kamera',\n music: 'Hudba',\n actors: 'Hrajú',\n basedOn: 'Predloha',\n producers: 'Produkcia',\n filmEditing: 'Strih',\n costumeDesign: 'Kostýmy',\n productionDesign: 'Scénografia',\n casting: 'Casting',\n sound: 'Zvuk',\n makeup: 'Masky'\n }\n};\n\n/**\n * Maps language-specific movie creator group labels.\n * @param language - The language code (e.g., 'en', 'cs')\n * @param key - The key of the creator group (e.g., 'directors', 'writers')\n * @returns The localized label for the creator group\n */\nexport const getLocalizedCreatorLabel = (\n language: string | undefined,\n key:\n | 'directors'\n | 'writers'\n | 'cinematography'\n | 'music'\n | 'actors'\n | 'basedOn'\n | 'producers'\n | 'filmEditing'\n | 'costumeDesign'\n | 'productionDesign'\n | 'casting'\n | 'sound'\n | 'makeup'\n): CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak => {\n const lang = language || 'cs'; // Default to Czech\n return (CREATOR_LABELS[lang] || CREATOR_LABELS['cs'])[key];\n};\n\nexport const getMovieId = (el: HTMLElement): number => {\n const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;\n return parseIdFromUrl(url);\n};\n\nexport const getSeriesAndSeasonTitle = (\n el: HTMLElement\n): { seriesName: string | null; seasonName: string | null } => {\n const titleElement = el.querySelector('h1');\n if (!titleElement) {\n return { seriesName: null, seasonName: null };\n }\n\n const fullText = titleElement.innerText.trim();\n\n // Check if there's a series part indicated by ' - '\n if (fullText.includes(' - ')) {\n const [seriesName, seasonName] = fullText.split(' - ').map((part) => part.trim());\n return { seriesName, seasonName };\n }\n\n // If no series part found, return just the name\n return { seriesName: fullText, seasonName: null };\n};\n\nexport const getMovieTitle = (el: HTMLElement): string => {\n return el.querySelector('h1').innerText.split(`(`)[0].trim();\n};\n\nexport const getMovieGenres = (el: HTMLElement): CSFDGenres[] => {\n const genresRaw = el.querySelector('.genres').textContent;\n return genresRaw.split(' / ') as CSFDGenres[];\n};\n\nexport const getMovieOrigins = (el: HTMLElement): string[] => {\n const originsRaw = el.querySelector('.origin').textContent;\n const origins = originsRaw.split(',')[0];\n return origins.split(' / ');\n};\n\nexport const getMovieColorRating = (bodyClasses: string[]): CSFDColorRating => {\n return getColor(bodyClasses[1]);\n};\n\nexport const getMovieRating = (el: HTMLElement): number => {\n const ratingRaw = el.querySelector('.film-rating-average').textContent;\n const rating = ratingRaw?.replace(/%/g, '').trim();\n const ratingInt = parseInt(rating);\n\n if (Number.isInteger(ratingInt)) {\n return ratingInt;\n } else {\n return null;\n }\n};\n\nexport const getMovieRatingCount = (el: HTMLElement): number => {\n const ratingCountRaw = el.querySelector('.box-rating-container .counter')?.textContent;\n const ratingCount = +ratingCountRaw?.replace(/[(\\s)]/g, '');\n if (Number.isInteger(ratingCount)) {\n return ratingCount;\n } else {\n return null;\n }\n};\n\nexport const getMovieYear = (jsonLd: MovieJsonLd | null): number => {\n if (jsonLd && jsonLd.dateCreated) {\n return +jsonLd.dateCreated;\n }\n return null;\n};\n\nexport const getMovieDuration = (jsonLd: MovieJsonLd | null, el: HTMLElement): number => {\n if (jsonLd && jsonLd.duration) {\n try {\n return parseISO8601Duration(jsonLd.duration);\n } catch (e) {\n // ignore\n }\n }\n\n try {\n const origin = el.querySelector('.origin').innerText;\n const timeString = origin.split(',');\n if (timeString.length > 2) {\n // Get last time elelment\n const timeString2 = timeString.pop().trim();\n // Clean it\n const timeRaw = timeString2.split('(')[0].trim();\n // Split by minutes and hours\n const hoursMinsRaw = timeRaw.split('min')[0];\n const hoursMins = hoursMinsRaw.split('h');\n // Resolve hours + minutes format\n const duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\n } catch (error) {\n return null;\n }\n};\n\nexport const getMovieTitlesOther = (el: HTMLElement): CSFDTitlesOther[] => {\n const namesNode = el.querySelectorAll('.film-names li');\n\n if (!namesNode.length) {\n return [];\n }\n\n const titlesOther = namesNode.map((el) => {\n const country = el.querySelector('img.flag').attributes.alt;\n const title = el.textContent.trim().split('\\n')[0];\n\n if (country && title) {\n return {\n country,\n title\n };\n } else {\n return null;\n }\n });\n\n return titlesOther.filter((x) => x);\n};\n\nexport const getMoviePoster = (el: HTMLElement | null): string => {\n const poster = el.querySelector('.film-posters img');\n // Resolve empty image\n if (poster) {\n if (poster.classNames?.includes('empty-image')) {\n return null;\n } else {\n // Full sized image (not thumb)\n const imageThumb = poster.attributes.src.split('?')[0];\n const image = imageThumb.replace(/\\/w140\\//, '/w1080/');\n return addProtocol(image);\n }\n } else {\n return null;\n }\n};\n\nexport const getMovieRandomPhoto = (el: HTMLElement | null): string => {\n const imageNode = el.querySelector('.gallery-item picture img');\n const image = imageNode?.attributes?.src;\n if (image) {\n return image.replace(/\\/w663\\//, '/w1326/');\n } else {\n return null;\n }\n};\n\nexport const getMovieTrivia = (el: HTMLElement | null): string[] => {\n const triviaNodes = el.querySelectorAll('.article-trivia ul li');\n if (triviaNodes?.length) {\n return triviaNodes.map((node) => node.textContent.trim().replace(/(\\r\\n|\\n|\\r|\\t)/gm, ''));\n } else {\n return null;\n }\n};\n\nexport const getMovieDescriptions = (el: HTMLElement): string[] => {\n return el\n .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')\n .map((movie) => movie.textContent?.trim().replace(/(\\r\\n|\\n|\\r|\\t)/gm, ''));\n};\n\nconst parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {\n const people = el.querySelectorAll('a');\n return (\n people\n // Filter out \"more\" links\n .filter((x) => x.classNames.length === 0)\n .map((person) => {\n return {\n id: parseIdFromUrl(person.attributes.href),\n name: person.innerText.trim(),\n url: `https://www.csfd.cz${person.attributes.href}`\n };\n })\n );\n};\n\n// export const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak): CSFDMovieCreator[] => {\n// const creators = el.querySelectorAll('.creators h4');\n// const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];\n// if (element?.parentNode) {\n// return parseMoviePeople(element.parentNode as HTMLElement);\n// } else {\n// return [];\n// }\n// };\n\nexport const getMovieCreators = (el: HTMLElement, options?: CSFDOptions): CSFDCreators => {\n const creators: CSFDCreators = {\n directors: [],\n writers: [],\n cinematography: [],\n music: [],\n actors: [],\n basedOn: [],\n producers: [],\n filmEditing: [],\n costumeDesign: [],\n productionDesign: []\n };\n\n const groups = el.querySelectorAll('.creators h4');\n\n const keys = [\n 'directors',\n 'writers',\n 'cinematography',\n 'music',\n 'actors',\n 'basedOn',\n 'producers',\n 'filmEditing',\n 'costumeDesign',\n 'productionDesign'\n ] as const;\n\n const localizedLabels = keys.map((key) => ({\n key,\n label: getLocalizedCreatorLabel(options?.language, key) as string\n }));\n\n for (const group of groups) {\n const text = group.textContent.trim();\n for (const { key, label } of localizedLabels) {\n if (text.includes(label)) {\n if (group.parentNode) {\n creators[key] = parseMoviePeople(group.parentNode as HTMLElement);\n }\n break;\n }\n }\n }\n\n return creators;\n};\n\nexport const getSeasonsOrEpisodes = (el: HTMLElement): CSFDSeriesChild[] | null => {\n const childrenList = el.querySelector('.film-episodes-list');\n if (!childrenList) return null;\n\n const childrenNodes = childrenList.querySelectorAll('.film-title');\n if (!childrenNodes?.length) return [];\n\n return childrenNodes.map((season) => {\n const nameContainer = season.querySelector('.film-title-name');\n const infoContainer = season.querySelector('.info');\n\n const href = nameContainer?.getAttribute('href');\n const url = href ? (href.startsWith('/') ? `https://www.csfd.cz${href}` : href) : null;\n\n return {\n id: parseLastIdFromUrl(href || ''),\n title: nameContainer?.textContent?.trim() || null,\n url,\n info: infoContainer?.textContent?.replace(/[{()}]/g, '').trim() || null\n };\n });\n};\n\nexport const getEpisodeCode = (el: HTMLElement): string | null => {\n const filmHeaderName = el.querySelector('.film-header-name h1');\n if (!filmHeaderName) return null;\n\n const text = filmHeaderName.textContent?.trim() || '';\n const match = text.match(/\\(([^)]+)\\)/);\n const code = match ? match[1] : null;\n\n return code;\n};\n\nexport const detectSeasonOrEpisodeListType = (el: HTMLElement) => {\n const headerText = el.querySelector('.box-header h3')?.innerText.trim() ?? '';\n\n if (headerText.includes('Série')) return 'seasons';\n if (headerText.startsWith('Epizody')) return 'episodes';\n return null;\n};\n\nexport const getSeasonOrEpisodeParent = (el: HTMLElement): CSFDParent | null => {\n // Try h2 first (for episodes), then h1 (for seasons)\n let parents = el.querySelectorAll('.film-header h2 a');\n if (parents.length === 0) {\n parents = el.querySelectorAll('.film-header h1 a');\n }\n\n if (parents.length === 0) return null;\n\n const [parentSeries, parentSeason] = parents;\n\n const seriesId = parseIdFromUrl(parentSeries?.getAttribute('href'));\n const seasonId = parseLastIdFromUrl(parentSeason?.getAttribute('href') || '');\n const seriesTitle = parentSeries?.textContent?.trim() || null;\n const seasonTitle = parentSeason?.textContent?.trim() || null;\n\n const series = seriesId && seriesTitle ? { id: seriesId, title: seriesTitle } : null;\n const season = seasonId && seasonTitle ? { id: seasonId, title: seasonTitle } : null;\n\n if (!series && !season) return null;\n\n return { series, season };\n};\n\nexport const getMovieGroup = (\n el: HTMLElement,\n group: CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak\n): CSFDMovieCreator[] => {\n const creators = el.querySelectorAll('.creators h4');\n const element = creators.find((elem) => elem.textContent.trim().includes(group as string));\n if (element?.parentNode) {\n return parseMoviePeople(element.parentNode as HTMLElement);\n } else {\n return [];\n }\n};\n\nexport const getMovieType = (el: HTMLElement): CSFDFilmTypes => {\n const type = el.querySelector('.film-header-name .type');\n return parseFilmType(type?.innerText?.replace(/[{()}]/g, '') || 'film');\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttonsVod = el.querySelectorAll('.box-buttons-vod .vod-badge a');\n vods = buttonsVod.map((btn) => {\n return {\n title: btn.textContent.trim() as CSFDVodService,\n url: btn.attributes.href\n };\n });\n }\n return vods.length ? vods : [];\n};\n\n// Get box content\nconst getBoxContent = (el: HTMLElement, box: string): HTMLElement => {\n const headers = el.querySelectorAll('section.box .box-header');\n return headers.find((header) => header.querySelector('h3')?.textContent.trim().includes(box))\n ?.parentNode;\n};\n\nexport const getMovieBoxMovies = (\n el: HTMLElement,\n boxName: CSFDBoxContent\n): CSFDMovieListItem[] => {\n const movieListItem: CSFDMovieListItem[] = [];\n const box = getBoxContent(el, boxName);\n const movieTitleNodes = box?.querySelectorAll('.article-header .film-title-name');\n if (movieTitleNodes?.length) {\n for (const item of movieTitleNodes) {\n movieListItem.push({\n id: parseIdFromUrl(item.attributes.href),\n title: item.textContent.trim(),\n url: `https://www.csfd.cz${item.attributes.href}`\n });\n }\n }\n return movieListItem;\n};\n\nexport const getMoviePremieres = (el: HTMLElement): CSFDPremiere[] => {\n const premiereNodes = el.querySelectorAll('.box-premieres li');\n const premiere: CSFDPremiere[] = [];\n for (const premiereNode of premiereNodes) {\n const title = premiereNode.querySelector('p + span').attributes.title;\n\n if (title) {\n const [dateRaw, ...company] = title?.split(' ');\n const date = parseDate(dateRaw);\n\n if (date) {\n premiere.push({\n country: premiereNode.querySelector('.flag')?.attributes.title || null,\n format: premiereNode.querySelector('p').textContent.trim()?.split(' od')[0],\n date,\n company: company.join(' ')\n });\n }\n }\n }\n return premiere;\n};\n\nexport const getMovieTags = (el: HTMLElement): string[] => {\n const tagsRaw = el.querySelectorAll('.box-content a[href*=\"/tag/\"]');\n return tagsRaw.map((tag) => tag.textContent);\n};\n"],"mappings":";;AA8BA,MAAM,iBAGF;CACF,IAAI;EACF,WAAW;EACX,SAAS;EACT,gBAAgB;EAChB,OAAO;EACP,QAAQ;EACR,SAAS;EACT,WAAW;EACX,aAAa;EACb,eAAe;EACf,kBAAkB;EAClB,SAAS;EACT,OAAO;E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,MAAM,gBAAqC,EAAE;CAE7C,MAAM,kBADM,cAAc,IAAI,QAAQ,EACT,iBAAiB,mCAAmC;AACjF,KAAI,iBAAiB,OACnB,MAAK,MAAM,QAAQ,gBACjB,eAAc,KAAK;EACjB,IAAIF,sBAAAA,eAAe,KAAK,WAAW,KAAK;EACxC,OAAO,KAAK,YAAY,MAAM;EAC9B,KAAK,sBAAsB,KAAK,WAAW;EAC5C,CAAC;AAGN,QAAO;;AAGT,MAAa,qBAAqB,OAAoC;CACpE,MAAM,gBAAgB,GAAG,iBAAiB,oBAAoB;CAC9D,MAAM,WAA2B,EAAE;AACnC,MAAK,MAAM,gBAAgB,eAAe;EACxC,MAAM,QAAQ,aAAa,cAAc,WAAW,CAAC,WAAW;AAEhE,MAAI,OAAO;GACT,MAAM,CAAC,SAAS,GAAG,WAAW,OAAO,MAAM,IAAI;GAC/C,MAAM,OAAOG,sBAAAA,UAAU,QAAQ;AAE/B,OAAI,KACF,UAAS,KAAK;IACZ,SAAS,aAAa,cAAc,QAAQ,EAAE,WAAW,SAAS;IAClE,QAAQ,aAAa,cAAc,IAAI,CAAC,YAAY,MAAM,EAAE,MAAM,MAAM,CAAC;IACzE;IACA,SAAS,QAAQ,KAAK,IAAI;IAC3B,CAAC;;;AAIR,QAAO;;AAGT,MAAa,gBAAgB,OAA8B;AAEzD,QADgB,GAAG,iBAAiB,kCAAgC,CACrD,KAAK,QAAQ,IAAI,YAAY"}
|
package/helpers/movie.helper.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { addProtocol, getColor, parseDate, parseFilmType, parseISO8601Duration, parseIdFromUrl, parseLastIdFromUrl } from "./global.helper.js";
|
|
2
2
|
//#region src/helpers/movie.helper.ts
|
|
3
3
|
const CREATOR_LABELS = {
|
|
4
4
|
en: {
|
|
@@ -85,7 +85,7 @@ const getMovieOrigins = (el) => {
|
|
|
85
85
|
return el.querySelector(".origin").textContent.split(",")[0].split(" / ");
|
|
86
86
|
};
|
|
87
87
|
const getMovieColorRating = (bodyClasses) => {
|
|
88
|
-
return
|
|
88
|
+
return getColor(bodyClasses[1]);
|
|
89
89
|
};
|
|
90
90
|
const getMovieRating = (el) => {
|
|
91
91
|
const rating = el.querySelector(".film-rating-average").textContent?.replace(/%/g, "").trim();
|
|
@@ -104,7 +104,7 @@ const getMovieYear = (jsonLd) => {
|
|
|
104
104
|
};
|
|
105
105
|
const getMovieDuration = (jsonLd, el) => {
|
|
106
106
|
if (jsonLd && jsonLd.duration) try {
|
|
107
|
-
return
|
|
107
|
+
return parseISO8601Duration(jsonLd.duration);
|
|
108
108
|
} catch (e) {}
|
|
109
109
|
try {
|
|
110
110
|
const timeString = el.querySelector(".origin").innerText.split(",");
|
|
@@ -132,7 +132,7 @@ const getMovieTitlesOther = (el) => {
|
|
|
132
132
|
const getMoviePoster = (el) => {
|
|
133
133
|
const poster = el.querySelector(".film-posters img");
|
|
134
134
|
if (poster) if (poster.classNames?.includes("empty-image")) return null;
|
|
135
|
-
else return
|
|
135
|
+
else return addProtocol(poster.attributes.src.split("?")[0].replace(/\/w140\//, "/w1080/"));
|
|
136
136
|
else return null;
|
|
137
137
|
};
|
|
138
138
|
const getMovieRandomPhoto = (el) => {
|
|
@@ -151,7 +151,7 @@ const getMovieDescriptions = (el) => {
|
|
|
151
151
|
const parseMoviePeople = (el) => {
|
|
152
152
|
return el.querySelectorAll("a").filter((x) => x.classNames.length === 0).map((person) => {
|
|
153
153
|
return {
|
|
154
|
-
id:
|
|
154
|
+
id: parseIdFromUrl(person.attributes.href),
|
|
155
155
|
name: person.innerText.trim(),
|
|
156
156
|
url: `https://www.csfd.cz${person.attributes.href}`
|
|
157
157
|
};
|
|
@@ -206,7 +206,7 @@ const getSeasonsOrEpisodes = (el) => {
|
|
|
206
206
|
const href = nameContainer?.getAttribute("href");
|
|
207
207
|
const url = href ? href.startsWith("/") ? `https://www.csfd.cz${href}` : href : null;
|
|
208
208
|
return {
|
|
209
|
-
id:
|
|
209
|
+
id: parseLastIdFromUrl(href || ""),
|
|
210
210
|
title: nameContainer?.textContent?.trim() || null,
|
|
211
211
|
url,
|
|
212
212
|
info: infoContainer?.textContent?.replace(/[{()}]/g, "").trim() || null
|
|
@@ -230,8 +230,8 @@ const getSeasonOrEpisodeParent = (el) => {
|
|
|
230
230
|
if (parents.length === 0) parents = el.querySelectorAll(".film-header h1 a");
|
|
231
231
|
if (parents.length === 0) return null;
|
|
232
232
|
const [parentSeries, parentSeason] = parents;
|
|
233
|
-
const seriesId =
|
|
234
|
-
const seasonId =
|
|
233
|
+
const seriesId = parseIdFromUrl(parentSeries?.getAttribute("href"));
|
|
234
|
+
const seasonId = parseLastIdFromUrl(parentSeason?.getAttribute("href") || "");
|
|
235
235
|
const seriesTitle = parentSeries?.textContent?.trim() || null;
|
|
236
236
|
const seasonTitle = parentSeason?.textContent?.trim() || null;
|
|
237
237
|
const series = seriesId && seriesTitle ? {
|
|
@@ -249,7 +249,7 @@ const getSeasonOrEpisodeParent = (el) => {
|
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
251
|
const getMovieType = (el) => {
|
|
252
|
-
return
|
|
252
|
+
return parseFilmType(el.querySelector(".film-header-name .type")?.innerText?.replace(/[{()}]/g, "") || "film");
|
|
253
253
|
};
|
|
254
254
|
const getMovieVods = (el) => {
|
|
255
255
|
let vods = [];
|
|
@@ -268,7 +268,7 @@ const getMovieBoxMovies = (el, boxName) => {
|
|
|
268
268
|
const movieListItem = [];
|
|
269
269
|
const movieTitleNodes = getBoxContent(el, boxName)?.querySelectorAll(".article-header .film-title-name");
|
|
270
270
|
if (movieTitleNodes?.length) for (const item of movieTitleNodes) movieListItem.push({
|
|
271
|
-
id:
|
|
271
|
+
id: parseIdFromUrl(item.attributes.href),
|
|
272
272
|
title: item.textContent.trim(),
|
|
273
273
|
url: `https://www.csfd.cz${item.attributes.href}`
|
|
274
274
|
});
|
|
@@ -281,7 +281,7 @@ const getMoviePremieres = (el) => {
|
|
|
281
281
|
const title = premiereNode.querySelector("p + span").attributes.title;
|
|
282
282
|
if (title) {
|
|
283
283
|
const [dateRaw, ...company] = title?.split(" ");
|
|
284
|
-
const date =
|
|
284
|
+
const date = parseDate(dateRaw);
|
|
285
285
|
if (date) premiere.push({
|
|
286
286
|
country: premiereNode.querySelector(".flag")?.attributes.title || null,
|
|
287
287
|
format: premiereNode.querySelector("p").textContent.trim()?.split(" od")[0],
|
|
@@ -296,29 +296,6 @@ const getMovieTags = (el) => {
|
|
|
296
296
|
return el.querySelectorAll(".box-content a[href*=\"/tag/\"]").map((tag) => tag.textContent);
|
|
297
297
|
};
|
|
298
298
|
//#endregion
|
|
299
|
-
|
|
300
|
-
exports.getEpisodeCode = getEpisodeCode;
|
|
301
|
-
exports.getMovieBoxMovies = getMovieBoxMovies;
|
|
302
|
-
exports.getMovieColorRating = getMovieColorRating;
|
|
303
|
-
exports.getMovieCreators = getMovieCreators;
|
|
304
|
-
exports.getMovieDescriptions = getMovieDescriptions;
|
|
305
|
-
exports.getMovieDuration = getMovieDuration;
|
|
306
|
-
exports.getMovieGenres = getMovieGenres;
|
|
307
|
-
exports.getMovieOrigins = getMovieOrigins;
|
|
308
|
-
exports.getMoviePoster = getMoviePoster;
|
|
309
|
-
exports.getMoviePremieres = getMoviePremieres;
|
|
310
|
-
exports.getMovieRandomPhoto = getMovieRandomPhoto;
|
|
311
|
-
exports.getMovieRating = getMovieRating;
|
|
312
|
-
exports.getMovieRatingCount = getMovieRatingCount;
|
|
313
|
-
exports.getMovieTags = getMovieTags;
|
|
314
|
-
exports.getMovieTitle = getMovieTitle;
|
|
315
|
-
exports.getMovieTitlesOther = getMovieTitlesOther;
|
|
316
|
-
exports.getMovieTrivia = getMovieTrivia;
|
|
317
|
-
exports.getMovieType = getMovieType;
|
|
318
|
-
exports.getMovieVods = getMovieVods;
|
|
319
|
-
exports.getMovieYear = getMovieYear;
|
|
320
|
-
exports.getSeasonOrEpisodeParent = getSeasonOrEpisodeParent;
|
|
321
|
-
exports.getSeasonsOrEpisodes = getSeasonsOrEpisodes;
|
|
322
|
-
exports.getSeriesAndSeasonTitle = getSeriesAndSeasonTitle;
|
|
299
|
+
export { detectSeasonOrEpisodeListType, getEpisodeCode, getMovieBoxMovies, getMovieColorRating, getMovieCreators, getMovieDescriptions, getMovieDuration, getMovieGenres, getMovieOrigins, getMoviePoster, getMoviePremieres, getMovieRandomPhoto, getMovieRating, getMovieRatingCount, getMovieTags, getMovieTitle, getMovieTitlesOther, getMovieTrivia, getMovieType, getMovieVods, getMovieYear, getSeasonOrEpisodeParent, getSeasonsOrEpisodes, getSeriesAndSeasonTitle };
|
|
323
300
|
|
|
324
301
|
//# sourceMappingURL=movie.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movie.helper.js","names":["getColor","parseISO8601Duration","addProtocol","parseIdFromUrl","parseLastIdFromUrl","parseFilmType","parseDate"],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport type { CSFDColorRating, CSFDFilmTypes } from '../dto/global';\nimport type {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDCreatorGroupsEnglish,\n CSFDCreatorGroupsSlovak,\n CSFDCreators,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDParent,\n CSFDPremiere,\n CSFDSeriesChild,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService,\n MovieJsonLd\n} from '../dto/movie';\nimport type { CSFDOptions } from '../types';\nimport {\n addProtocol,\n getColor,\n parseDate,\n parseFilmType,\n parseISO8601Duration,\n parseIdFromUrl,\n parseLastIdFromUrl\n} from './global.helper';\n\nconst CREATOR_LABELS: Record<\n string,\n Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak>\n> = {\n en: {\n directors: 'Directed by',\n writers: 'Screenplay',\n cinematography: 'Cinematography',\n music: 'Composer',\n actors: 'Cast',\n basedOn: 'Based on',\n producers: 'Produced by',\n filmEditing: 'Editing',\n costumeDesign: 'Costumes',\n productionDesign: 'Production design',\n casting: 'Casting',\n sound: 'Sound',\n makeup: 'Make-up'\n },\n cs: {\n directors: 'Režie',\n writers: 'Scénář',\n cinematography: 'Kamera',\n music: 'Hudba',\n actors: 'Hrají',\n basedOn: 'Předloha',\n producers: 'Produkce',\n filmEditing: 'Střih',\n costumeDesign: 'Kostýmy',\n productionDesign: 'Scénografie',\n casting: 'Casting',\n sound: 'Zvuk',\n makeup: 'Masky'\n },\n sk: {\n directors: 'Réžia',\n writers: 'Scenár',\n cinematography: 'Kamera',\n music: 'Hudba',\n actors: 'Hrajú',\n basedOn: 'Predloha',\n producers: 'Produkcia',\n filmEditing: 'Strih',\n costumeDesign: 'Kostýmy',\n productionDesign: 'Scénografia',\n casting: 'Casting',\n sound: 'Zvuk',\n makeup: 'Masky'\n }\n};\n\n/**\n * Maps language-specific movie creator group labels.\n * @param language - The language code (e.g., 'en', 'cs')\n * @param key - The key of the creator group (e.g., 'directors', 'writers')\n * @returns The localized label for the creator group\n */\nexport const getLocalizedCreatorLabel = (\n language: string | undefined,\n key:\n | 'directors'\n | 'writers'\n | 'cinematography'\n | 'music'\n | 'actors'\n | 'basedOn'\n | 'producers'\n | 'filmEditing'\n | 'costumeDesign'\n | 'productionDesign'\n | 'casting'\n | 'sound'\n | 'makeup'\n): CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak => {\n const lang = language || 'cs'; // Default to Czech\n return (CREATOR_LABELS[lang] || CREATOR_LABELS['cs'])[key];\n};\n\nexport const getMovieId = (el: HTMLElement): number => {\n const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;\n return parseIdFromUrl(url);\n};\n\nexport const getSeriesAndSeasonTitle = (\n el: HTMLElement\n): { seriesName: string | null; seasonName: string | null } => {\n const titleElement = el.querySelector('h1');\n if (!titleElement) {\n return { seriesName: null, seasonName: null };\n }\n\n const fullText = titleElement.innerText.trim();\n\n // Check if there's a series part indicated by ' - '\n if (fullText.includes(' - ')) {\n const [seriesName, seasonName] = fullText.split(' - ').map((part) => part.trim());\n return { seriesName, seasonName };\n }\n\n // If no series part found, return just the name\n return { seriesName: fullText, seasonName: null };\n};\n\nexport const getMovieTitle = (el: HTMLElement): string => {\n return el.querySelector('h1').innerText.split(`(`)[0].trim();\n};\n\nexport const getMovieGenres = (el: HTMLElement): CSFDGenres[] => {\n const genresRaw = el.querySelector('.genres').textContent;\n return genresRaw.split(' / ') as CSFDGenres[];\n};\n\nexport const getMovieOrigins = (el: HTMLElement): string[] => {\n const originsRaw = el.querySelector('.origin').textContent;\n const origins = originsRaw.split(',')[0];\n return origins.split(' / ');\n};\n\nexport const getMovieColorRating = (bodyClasses: string[]): CSFDColorRating => {\n return getColor(bodyClasses[1]);\n};\n\nexport const getMovieRating = (el: HTMLElement): number => {\n const ratingRaw = el.querySelector('.film-rating-average').textContent;\n const rating = ratingRaw?.replace(/%/g, '').trim();\n const ratingInt = parseInt(rating);\n\n if (Number.isInteger(ratingInt)) {\n return ratingInt;\n } else {\n return null;\n }\n};\n\nexport const getMovieRatingCount = (el: HTMLElement): number => {\n const ratingCountRaw = el.querySelector('.box-rating-container .counter')?.textContent;\n const ratingCount = +ratingCountRaw?.replace(/[(\\s)]/g, '');\n if (Number.isInteger(ratingCount)) {\n return ratingCount;\n } else {\n return null;\n }\n};\n\nexport const getMovieYear = (jsonLd: MovieJsonLd | null): number => {\n if (jsonLd && jsonLd.dateCreated) {\n return +jsonLd.dateCreated;\n }\n return null;\n};\n\nexport const getMovieDuration = (jsonLd: MovieJsonLd | null, el: HTMLElement): number => {\n if (jsonLd && jsonLd.duration) {\n try {\n return parseISO8601Duration(jsonLd.duration);\n } catch (e) {\n // ignore\n }\n }\n\n try {\n const origin = el.querySelector('.origin').innerText;\n const timeString = origin.split(',');\n if (timeString.length > 2) {\n // Get last time elelment\n const timeString2 = timeString.pop().trim();\n // Clean it\n const timeRaw = timeString2.split('(')[0].trim();\n // Split by minutes and hours\n const hoursMinsRaw = timeRaw.split('min')[0];\n const hoursMins = hoursMinsRaw.split('h');\n // Resolve hours + minutes format\n const duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\n } catch (error) {\n return null;\n }\n};\n\nexport const getMovieTitlesOther = (el: HTMLElement): CSFDTitlesOther[] => {\n const namesNode = el.querySelectorAll('.film-names li');\n\n if (!namesNode.length) {\n return [];\n }\n\n const titlesOther = namesNode.map((el) => {\n const country = el.querySelector('img.flag').attributes.alt;\n const title = el.textContent.trim().split('\\n')[0];\n\n if (country && title) {\n return {\n country,\n title\n };\n } else {\n return null;\n }\n });\n\n return titlesOther.filter((x) => x);\n};\n\nexport const getMoviePoster = (el: HTMLElement | null): string => {\n const poster = el.querySelector('.film-posters img');\n // Resolve empty image\n if (poster) {\n if (poster.classNames?.includes('empty-image')) {\n return null;\n } else {\n // Full sized image (not thumb)\n const imageThumb = poster.attributes.src.split('?')[0];\n const image = imageThumb.replace(/\\/w140\\//, '/w1080/');\n return addProtocol(image);\n }\n } else {\n return null;\n }\n};\n\nexport const getMovieRandomPhoto = (el: HTMLElement | null): string => {\n const imageNode = el.querySelector('.gallery-item picture img');\n const image = imageNode?.attributes?.src;\n if (image) {\n return image.replace(/\\/w663\\//, '/w1326/');\n } else {\n return null;\n }\n};\n\nexport const getMovieTrivia = (el: HTMLElement | null): string[] => {\n const triviaNodes = el.querySelectorAll('.article-trivia ul li');\n if (triviaNodes?.length) {\n return triviaNodes.map((node) => node.textContent.trim().replace(/(\\r\\n|\\n|\\r|\\t)/gm, ''));\n } else {\n return null;\n }\n};\n\nexport const getMovieDescriptions = (el: HTMLElement): string[] => {\n return el\n .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')\n .map((movie) => movie.textContent?.trim().replace(/(\\r\\n|\\n|\\r|\\t)/gm, ''));\n};\n\nconst parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {\n const people = el.querySelectorAll('a');\n return (\n people\n // Filter out \"more\" links\n .filter((x) => x.classNames.length === 0)\n .map((person) => {\n return {\n id: parseIdFromUrl(person.attributes.href),\n name: person.innerText.trim(),\n url: `https://www.csfd.cz${person.attributes.href}`\n };\n })\n );\n};\n\n// export const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak): CSFDMovieCreator[] => {\n// const creators = el.querySelectorAll('.creators h4');\n// const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];\n// if (element?.parentNode) {\n// return parseMoviePeople(element.parentNode as HTMLElement);\n// } else {\n// return [];\n// }\n// };\n\nexport const getMovieCreators = (el: HTMLElement, options?: CSFDOptions): CSFDCreators => {\n const creators: CSFDCreators = {\n directors: [],\n writers: [],\n cinematography: [],\n music: [],\n actors: [],\n basedOn: [],\n producers: [],\n filmEditing: [],\n costumeDesign: [],\n productionDesign: []\n };\n\n const groups = el.querySelectorAll('.creators h4');\n\n const keys = [\n 'directors',\n 'writers',\n 'cinematography',\n 'music',\n 'actors',\n 'basedOn',\n 'producers',\n 'filmEditing',\n 'costumeDesign',\n 'productionDesign'\n ] as const;\n\n const localizedLabels = keys.map((key) => ({\n key,\n label: getLocalizedCreatorLabel(options?.language, key) as string\n }));\n\n for (const group of groups) {\n const text = group.textContent.trim();\n for (const { key, label } of localizedLabels) {\n if (text.includes(label)) {\n if (group.parentNode) {\n creators[key] = parseMoviePeople(group.parentNode as HTMLElement);\n }\n break;\n }\n }\n }\n\n return creators;\n};\n\nexport const getSeasonsOrEpisodes = (el: HTMLElement): CSFDSeriesChild[] | null => {\n const childrenList = el.querySelector('.film-episodes-list');\n if (!childrenList) return null;\n\n const childrenNodes = childrenList.querySelectorAll('.film-title');\n if (!childrenNodes?.length) return [];\n\n return childrenNodes.map((season) => {\n const nameContainer = season.querySelector('.film-title-name');\n const infoContainer = season.querySelector('.info');\n\n const href = nameContainer?.getAttribute('href');\n const url = href ? (href.startsWith('/') ? `https://www.csfd.cz${href}` : href) : null;\n\n return {\n id: parseLastIdFromUrl(href || ''),\n title: nameContainer?.textContent?.trim() || null,\n url,\n info: infoContainer?.textContent?.replace(/[{()}]/g, '').trim() || null\n };\n });\n};\n\nexport const getEpisodeCode = (el: HTMLElement): string | null => {\n const filmHeaderName = el.querySelector('.film-header-name h1');\n if (!filmHeaderName) return null;\n\n const text = filmHeaderName.textContent?.trim() || '';\n const match = text.match(/\\(([^)]+)\\)/);\n const code = match ? match[1] : null;\n\n return code;\n};\n\nexport const detectSeasonOrEpisodeListType = (el: HTMLElement) => {\n const headerText = el.querySelector('.box-header h3')?.innerText.trim() ?? '';\n\n if (headerText.includes('Série')) return 'seasons';\n if (headerText.startsWith('Epizody')) return 'episodes';\n return null;\n};\n\nexport const getSeasonOrEpisodeParent = (el: HTMLElement): CSFDParent | null => {\n // Try h2 first (for episodes), then h1 (for seasons)\n let parents = el.querySelectorAll('.film-header h2 a');\n if (parents.length === 0) {\n parents = el.querySelectorAll('.film-header h1 a');\n }\n\n if (parents.length === 0) return null;\n\n const [parentSeries, parentSeason] = parents;\n\n const seriesId = parseIdFromUrl(parentSeries?.getAttribute('href'));\n const seasonId = parseLastIdFromUrl(parentSeason?.getAttribute('href') || '');\n const seriesTitle = parentSeries?.textContent?.trim() || null;\n const seasonTitle = parentSeason?.textContent?.trim() || null;\n\n const series = seriesId && seriesTitle ? { id: seriesId, title: seriesTitle } : null;\n const season = seasonId && seasonTitle ? { id: seasonId, title: seasonTitle } : null;\n\n if (!series && !season) return null;\n\n return { series, season };\n};\n\nexport const getMovieGroup = (\n el: HTMLElement,\n group: CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak\n): CSFDMovieCreator[] => {\n const creators = el.querySelectorAll('.creators h4');\n const element = creators.find((elem) => elem.textContent.trim().includes(group as string));\n if (element?.parentNode) {\n return parseMoviePeople(element.parentNode as HTMLElement);\n } else {\n return [];\n }\n};\n\nexport const getMovieType = (el: HTMLElement): CSFDFilmTypes => {\n const type = el.querySelector('.film-header-name .type');\n return parseFilmType(type?.innerText?.replace(/[{()}]/g, '') || 'film');\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttonsVod = el.querySelectorAll('.box-buttons-vod .vod-badge a');\n vods = buttonsVod.map((btn) => {\n return {\n title: btn.textContent.trim() as CSFDVodService,\n url: btn.attributes.href\n };\n });\n }\n return vods.length ? vods : [];\n};\n\n// Get box content\nconst getBoxContent = (el: HTMLElement, box: string): HTMLElement => {\n const headers = el.querySelectorAll('section.box .box-header');\n return headers.find((header) => header.querySelector('h3')?.textContent.trim().includes(box))\n ?.parentNode;\n};\n\nexport const getMovieBoxMovies = (\n el: HTMLElement,\n boxName: CSFDBoxContent\n): CSFDMovieListItem[] => {\n const movieListItem: CSFDMovieListItem[] = [];\n const box = getBoxContent(el, boxName);\n const movieTitleNodes = box?.querySelectorAll('.article-header .film-title-name');\n if (movieTitleNodes?.length) {\n for (const item of movieTitleNodes) {\n movieListItem.push({\n id: parseIdFromUrl(item.attributes.href),\n title: item.textContent.trim(),\n url: `https://www.csfd.cz${item.attributes.href}`\n });\n }\n }\n return movieListItem;\n};\n\nexport const getMoviePremieres = (el: HTMLElement): CSFDPremiere[] => {\n const premiereNodes = el.querySelectorAll('.box-premieres li');\n const premiere: CSFDPremiere[] = [];\n for (const premiereNode of premiereNodes) {\n const title = premiereNode.querySelector('p + span').attributes.title;\n\n if (title) {\n const [dateRaw, ...company] = title?.split(' ');\n const date = parseDate(dateRaw);\n\n if (date) {\n premiere.push({\n country: premiereNode.querySelector('.flag')?.attributes.title || null,\n format: premiereNode.querySelector('p').textContent.trim()?.split(' od')[0],\n date,\n company: company.join(' ')\n });\n }\n }\n }\n return premiere;\n};\n\nexport const getMovieTags = (el: HTMLElement): string[] => {\n const tagsRaw = el.querySelectorAll('.box-content a[href*=\"/tag/\"]');\n return tagsRaw.map((tag) => tag.textContent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hC,MAAM,iBAAiB,IAAiB,QAA6B;AAEnE,QADgB,GAAG,iBAAiB,0BAA0B,CAC/C,MAAM,WAAW,OAAO,cAAc,KAAK,EAAE,YAAY,MAAM,CAAC,SAAS,IAAI,CAAC,EACzF;;AAGN,MAAa,qBACX,IACA,YACwB;CACxB,MAAM,gBAAqC,EAAE;CAE7C,MAAM,kBADM,cAAc,IAAI,QAAQ,EACT,iBAAiB,mCAAmC;AACjF,KAAI,iBAAiB,OACnB,MAAK,MAAM,QAAQ,gBACjB,eAAc,KAAK;EACjB,IAAIF,sBAAAA,eAAe,KAAK,WAAW,KAAK;EACxC,OAAO,KAAK,YAAY,MAAM;EAC9B,KAAK,sBAAsB,KAAK,WAAW;EAC5C,CAAC;AAGN,QAAO;;AAGT,MAAa,qBAAqB,OAAoC;CACpE,MAAM,gBAAgB,GAAG,iBAAiB,oBAAoB;CAC9D,MAAM,WAA2B,EAAE;AACnC,MAAK,MAAM,gBAAgB,eAAe;EACxC,MAAM,QAAQ,aAAa,cAAc,WAAW,CAAC,WAAW;AAEhE,MAAI,OAAO;GACT,MAAM,CAAC,SAAS,GAAG,WAAW,OAAO,MAAM,IAAI;GAC/C,MAAM,OAAOG,sBAAAA,UAAU,QAAQ;AAE/B,OAAI,KACF,UAAS,KAAK;IACZ,SAAS,aAAa,cAAc,QAAQ,EAAE,WAAW,SAAS;IAClE,QAAQ,aAAa,cAAc,IAAI,CAAC,YAAY,MAAM,EAAE,MAAM,MAAM,CAAC;IACzE;IACA,SAAS,QAAQ,KAAK,IAAI;IAC3B,CAAC;;;AAIR,QAAO;;AAGT,MAAa,gBAAgB,OAA8B;AAEzD,QADgB,GAAG,iBAAiB,kCAAgC,CACrD,KAAK,QAAQ,IAAI,YAAY"}
|
|
1
|
+
{"version":3,"file":"movie.helper.js","names":[],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport type { CSFDColorRating, CSFDFilmTypes } from '../dto/global';\nimport type {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDCreatorGroupsEnglish,\n CSFDCreatorGroupsSlovak,\n CSFDCreators,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDParent,\n CSFDPremiere,\n CSFDSeriesChild,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService,\n MovieJsonLd\n} from '../dto/movie';\nimport type { CSFDOptions } from '../types';\nimport {\n addProtocol,\n getColor,\n parseDate,\n parseFilmType,\n parseISO8601Duration,\n parseIdFromUrl,\n parseLastIdFromUrl\n} from './global.helper';\n\nconst CREATOR_LABELS: Record<\n string,\n Record<string, CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak>\n> = {\n en: {\n directors: 'Directed by',\n writers: 'Screenplay',\n cinematography: 'Cinematography',\n music: 'Composer',\n actors: 'Cast',\n basedOn: 'Based on',\n producers: 'Produced by',\n filmEditing: 'Editing',\n costumeDesign: 'Costumes',\n productionDesign: 'Production design',\n casting: 'Casting',\n sound: 'Sound',\n makeup: 'Make-up'\n },\n cs: {\n directors: 'Režie',\n writers: 'Scénář',\n cinematography: 'Kamera',\n music: 'Hudba',\n actors: 'Hrají',\n basedOn: 'Předloha',\n producers: 'Produkce',\n filmEditing: 'Střih',\n costumeDesign: 'Kostýmy',\n productionDesign: 'Scénografie',\n casting: 'Casting',\n sound: 'Zvuk',\n makeup: 'Masky'\n },\n sk: {\n directors: 'Réžia',\n writers: 'Scenár',\n cinematography: 'Kamera',\n music: 'Hudba',\n actors: 'Hrajú',\n basedOn: 'Predloha',\n producers: 'Produkcia',\n filmEditing: 'Strih',\n costumeDesign: 'Kostýmy',\n productionDesign: 'Scénografia',\n casting: 'Casting',\n sound: 'Zvuk',\n makeup: 'Masky'\n }\n};\n\n/**\n * Maps language-specific movie creator group labels.\n * @param language - The language code (e.g., 'en', 'cs')\n * @param key - The key of the creator group (e.g., 'directors', 'writers')\n * @returns The localized label for the creator group\n */\nexport const getLocalizedCreatorLabel = (\n language: string | undefined,\n key:\n | 'directors'\n | 'writers'\n | 'cinematography'\n | 'music'\n | 'actors'\n | 'basedOn'\n | 'producers'\n | 'filmEditing'\n | 'costumeDesign'\n | 'productionDesign'\n | 'casting'\n | 'sound'\n | 'makeup'\n): CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak => {\n const lang = language || 'cs'; // Default to Czech\n return (CREATOR_LABELS[lang] || CREATOR_LABELS['cs'])[key];\n};\n\nexport const getMovieId = (el: HTMLElement): number => {\n const url = el.querySelector('.tabs .tab-nav-list a').attributes.href;\n return parseIdFromUrl(url);\n};\n\nexport const getSeriesAndSeasonTitle = (\n el: HTMLElement\n): { seriesName: string | null; seasonName: string | null } => {\n const titleElement = el.querySelector('h1');\n if (!titleElement) {\n return { seriesName: null, seasonName: null };\n }\n\n const fullText = titleElement.innerText.trim();\n\n // Check if there's a series part indicated by ' - '\n if (fullText.includes(' - ')) {\n const [seriesName, seasonName] = fullText.split(' - ').map((part) => part.trim());\n return { seriesName, seasonName };\n }\n\n // If no series part found, return just the name\n return { seriesName: fullText, seasonName: null };\n};\n\nexport const getMovieTitle = (el: HTMLElement): string => {\n return el.querySelector('h1').innerText.split(`(`)[0].trim();\n};\n\nexport const getMovieGenres = (el: HTMLElement): CSFDGenres[] => {\n const genresRaw = el.querySelector('.genres').textContent;\n return genresRaw.split(' / ') as CSFDGenres[];\n};\n\nexport const getMovieOrigins = (el: HTMLElement): string[] => {\n const originsRaw = el.querySelector('.origin').textContent;\n const origins = originsRaw.split(',')[0];\n return origins.split(' / ');\n};\n\nexport const getMovieColorRating = (bodyClasses: string[]): CSFDColorRating => {\n return getColor(bodyClasses[1]);\n};\n\nexport const getMovieRating = (el: HTMLElement): number => {\n const ratingRaw = el.querySelector('.film-rating-average').textContent;\n const rating = ratingRaw?.replace(/%/g, '').trim();\n const ratingInt = parseInt(rating);\n\n if (Number.isInteger(ratingInt)) {\n return ratingInt;\n } else {\n return null;\n }\n};\n\nexport const getMovieRatingCount = (el: HTMLElement): number => {\n const ratingCountRaw = el.querySelector('.box-rating-container .counter')?.textContent;\n const ratingCount = +ratingCountRaw?.replace(/[(\\s)]/g, '');\n if (Number.isInteger(ratingCount)) {\n return ratingCount;\n } else {\n return null;\n }\n};\n\nexport const getMovieYear = (jsonLd: MovieJsonLd | null): number => {\n if (jsonLd && jsonLd.dateCreated) {\n return +jsonLd.dateCreated;\n }\n return null;\n};\n\nexport const getMovieDuration = (jsonLd: MovieJsonLd | null, el: HTMLElement): number => {\n if (jsonLd && jsonLd.duration) {\n try {\n return parseISO8601Duration(jsonLd.duration);\n } catch (e) {\n // ignore\n }\n }\n\n try {\n const origin = el.querySelector('.origin').innerText;\n const timeString = origin.split(',');\n if (timeString.length > 2) {\n // Get last time elelment\n const timeString2 = timeString.pop().trim();\n // Clean it\n const timeRaw = timeString2.split('(')[0].trim();\n // Split by minutes and hours\n const hoursMinsRaw = timeRaw.split('min')[0];\n const hoursMins = hoursMinsRaw.split('h');\n // Resolve hours + minutes format\n const duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\n } catch (error) {\n return null;\n }\n};\n\nexport const getMovieTitlesOther = (el: HTMLElement): CSFDTitlesOther[] => {\n const namesNode = el.querySelectorAll('.film-names li');\n\n if (!namesNode.length) {\n return [];\n }\n\n const titlesOther = namesNode.map((el) => {\n const country = el.querySelector('img.flag').attributes.alt;\n const title = el.textContent.trim().split('\\n')[0];\n\n if (country && title) {\n return {\n country,\n title\n };\n } else {\n return null;\n }\n });\n\n return titlesOther.filter((x) => x);\n};\n\nexport const getMoviePoster = (el: HTMLElement | null): string => {\n const poster = el.querySelector('.film-posters img');\n // Resolve empty image\n if (poster) {\n if (poster.classNames?.includes('empty-image')) {\n return null;\n } else {\n // Full sized image (not thumb)\n const imageThumb = poster.attributes.src.split('?')[0];\n const image = imageThumb.replace(/\\/w140\\//, '/w1080/');\n return addProtocol(image);\n }\n } else {\n return null;\n }\n};\n\nexport const getMovieRandomPhoto = (el: HTMLElement | null): string => {\n const imageNode = el.querySelector('.gallery-item picture img');\n const image = imageNode?.attributes?.src;\n if (image) {\n return image.replace(/\\/w663\\//, '/w1326/');\n } else {\n return null;\n }\n};\n\nexport const getMovieTrivia = (el: HTMLElement | null): string[] => {\n const triviaNodes = el.querySelectorAll('.article-trivia ul li');\n if (triviaNodes?.length) {\n return triviaNodes.map((node) => node.textContent.trim().replace(/(\\r\\n|\\n|\\r|\\t)/gm, ''));\n } else {\n return null;\n }\n};\n\nexport const getMovieDescriptions = (el: HTMLElement): string[] => {\n return el\n .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p')\n .map((movie) => movie.textContent?.trim().replace(/(\\r\\n|\\n|\\r|\\t)/gm, ''));\n};\n\nconst parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => {\n const people = el.querySelectorAll('a');\n return (\n people\n // Filter out \"more\" links\n .filter((x) => x.classNames.length === 0)\n .map((person) => {\n return {\n id: parseIdFromUrl(person.attributes.href),\n name: person.innerText.trim(),\n url: `https://www.csfd.cz${person.attributes.href}`\n };\n })\n );\n};\n\n// export const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak): CSFDMovieCreator[] => {\n// const creators = el.querySelectorAll('.creators h4');\n// const element = creators.filter((elem) => elem.textContent.trim().includes(group))[0];\n// if (element?.parentNode) {\n// return parseMoviePeople(element.parentNode as HTMLElement);\n// } else {\n// return [];\n// }\n// };\n\nexport const getMovieCreators = (el: HTMLElement, options?: CSFDOptions): CSFDCreators => {\n const creators: CSFDCreators = {\n directors: [],\n writers: [],\n cinematography: [],\n music: [],\n actors: [],\n basedOn: [],\n producers: [],\n filmEditing: [],\n costumeDesign: [],\n productionDesign: []\n };\n\n const groups = el.querySelectorAll('.creators h4');\n\n const keys = [\n 'directors',\n 'writers',\n 'cinematography',\n 'music',\n 'actors',\n 'basedOn',\n 'producers',\n 'filmEditing',\n 'costumeDesign',\n 'productionDesign'\n ] as const;\n\n const localizedLabels = keys.map((key) => ({\n key,\n label: getLocalizedCreatorLabel(options?.language, key) as string\n }));\n\n for (const group of groups) {\n const text = group.textContent.trim();\n for (const { key, label } of localizedLabels) {\n if (text.includes(label)) {\n if (group.parentNode) {\n creators[key] = parseMoviePeople(group.parentNode as HTMLElement);\n }\n break;\n }\n }\n }\n\n return creators;\n};\n\nexport const getSeasonsOrEpisodes = (el: HTMLElement): CSFDSeriesChild[] | null => {\n const childrenList = el.querySelector('.film-episodes-list');\n if (!childrenList) return null;\n\n const childrenNodes = childrenList.querySelectorAll('.film-title');\n if (!childrenNodes?.length) return [];\n\n return childrenNodes.map((season) => {\n const nameContainer = season.querySelector('.film-title-name');\n const infoContainer = season.querySelector('.info');\n\n const href = nameContainer?.getAttribute('href');\n const url = href ? (href.startsWith('/') ? `https://www.csfd.cz${href}` : href) : null;\n\n return {\n id: parseLastIdFromUrl(href || ''),\n title: nameContainer?.textContent?.trim() || null,\n url,\n info: infoContainer?.textContent?.replace(/[{()}]/g, '').trim() || null\n };\n });\n};\n\nexport const getEpisodeCode = (el: HTMLElement): string | null => {\n const filmHeaderName = el.querySelector('.film-header-name h1');\n if (!filmHeaderName) return null;\n\n const text = filmHeaderName.textContent?.trim() || '';\n const match = text.match(/\\(([^)]+)\\)/);\n const code = match ? match[1] : null;\n\n return code;\n};\n\nexport const detectSeasonOrEpisodeListType = (el: HTMLElement) => {\n const headerText = el.querySelector('.box-header h3')?.innerText.trim() ?? '';\n\n if (headerText.includes('Série')) return 'seasons';\n if (headerText.startsWith('Epizody')) return 'episodes';\n return null;\n};\n\nexport const getSeasonOrEpisodeParent = (el: HTMLElement): CSFDParent | null => {\n // Try h2 first (for episodes), then h1 (for seasons)\n let parents = el.querySelectorAll('.film-header h2 a');\n if (parents.length === 0) {\n parents = el.querySelectorAll('.film-header h1 a');\n }\n\n if (parents.length === 0) return null;\n\n const [parentSeries, parentSeason] = parents;\n\n const seriesId = parseIdFromUrl(parentSeries?.getAttribute('href'));\n const seasonId = parseLastIdFromUrl(parentSeason?.getAttribute('href') || '');\n const seriesTitle = parentSeries?.textContent?.trim() || null;\n const seasonTitle = parentSeason?.textContent?.trim() || null;\n\n const series = seriesId && seriesTitle ? { id: seriesId, title: seriesTitle } : null;\n const season = seasonId && seasonTitle ? { id: seasonId, title: seasonTitle } : null;\n\n if (!series && !season) return null;\n\n return { series, season };\n};\n\nexport const getMovieGroup = (\n el: HTMLElement,\n group: CSFDCreatorGroups | CSFDCreatorGroupsEnglish | CSFDCreatorGroupsSlovak\n): CSFDMovieCreator[] => {\n const creators = el.querySelectorAll('.creators h4');\n const element = creators.find((elem) => elem.textContent.trim().includes(group as string));\n if (element?.parentNode) {\n return parseMoviePeople(element.parentNode as HTMLElement);\n } else {\n return [];\n }\n};\n\nexport const getMovieType = (el: HTMLElement): CSFDFilmTypes => {\n const type = el.querySelector('.film-header-name .type');\n return parseFilmType(type?.innerText?.replace(/[{()}]/g, '') || 'film');\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttonsVod = el.querySelectorAll('.box-buttons-vod .vod-badge a');\n vods = buttonsVod.map((btn) => {\n return {\n title: btn.textContent.trim() as CSFDVodService,\n url: btn.attributes.href\n };\n });\n }\n return vods.length ? vods : [];\n};\n\n// Get box content\nconst getBoxContent = (el: HTMLElement, box: string): HTMLElement => {\n const headers = el.querySelectorAll('section.box .box-header');\n return headers.find((header) => header.querySelector('h3')?.textContent.trim().includes(box))\n ?.parentNode;\n};\n\nexport const getMovieBoxMovies = (\n el: HTMLElement,\n boxName: CSFDBoxContent\n): CSFDMovieListItem[] => {\n const movieListItem: CSFDMovieListItem[] = [];\n const box = getBoxContent(el, boxName);\n const movieTitleNodes = box?.querySelectorAll('.article-header .film-title-name');\n if (movieTitleNodes?.length) {\n for (const item of movieTitleNodes) {\n movieListItem.push({\n id: parseIdFromUrl(item.attributes.href),\n title: item.textContent.trim(),\n url: `https://www.csfd.cz${item.attributes.href}`\n });\n }\n }\n return movieListItem;\n};\n\nexport const getMoviePremieres = (el: HTMLElement): CSFDPremiere[] => {\n const premiereNodes = el.querySelectorAll('.box-premieres li');\n const premiere: CSFDPremiere[] = [];\n for (const premiereNode of premiereNodes) {\n const title = premiereNode.querySelector('p + span').attributes.title;\n\n if (title) {\n const [dateRaw, ...company] = title?.split(' ');\n const date = parseDate(dateRaw);\n\n if (date) {\n premiere.push({\n country: premiereNode.querySelector('.flag')?.attributes.title || null,\n format: premiereNode.querySelector('p').textContent.trim()?.split(' od')[0],\n date,\n company: company.join(' ')\n });\n }\n }\n }\n return premiere;\n};\n\nexport const getMovieTags = (el: HTMLElement): string[] => {\n const tagsRaw = el.querySelectorAll('.box-content a[href*=\"/tag/\"]');\n return tagsRaw.map((tag) => tag.textContent);\n};\n"],"mappings":";;AA8BA,MAAM,iBAGF;CACF,IAAI;EACF,WAAW;EACX,SAAS;EACT,gBAAgB;EAChB,OAAO;EACP,QAAQ;EACR,SAAS;EACT,WAAW;EACX,aAAa;EACb,eAAe;EACf,kBAAkB;EAClB,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,IAAI;EACF,WAAW;EACX,SAAS;EACT,gBAAgB;EAChB,OAAO;EACP,QAAQ;EACR,SAAS;EACT,WAAW;EACX,aAAa;EACb,eAAe;EACf,kBAAkB;EAClB,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,IAAI;EACF,WAAW;EACX,SAAS;EACT,gBAAgB;EAChB,OAAO;EACP,QAAQ;EACR,SAAS;EACT,WAAW;EACX,aAAa;EACb,eAAe;EACf,kBAAkB;EAClB,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACF;;;;;;;AAQD,MAAa,4BACX,UACA,QAc2E;AAE3E,SAAQ,eADK,YAAY,SACO,eAAe,OAAO;;AAQxD,MAAa,2BACX,OAC6D;CAC7D,MAAM,eAAe,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;AAE/B,OAAI,KACF,UAAS,KAAK;IACZ,SAAS,aAAa,cAAc,QAAQ,EAAE,WAAW,SAAS;IAClE,QAAQ,aAAa,cAAc,IAAI,CAAC,YAAY,MAAM,EAAE,MAAM,MAAM,CAAC;IACzE;IACA,SAAS,QAAQ,KAAK,IAAI;IAC3B,CAAC;;;AAIR,QAAO;;AAGT,MAAa,gBAAgB,OAA8B;AAEzD,QADgB,GAAG,iBAAiB,kCAAgC,CACrD,KAAK,QAAQ,IAAI,YAAY"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
const require_global_helper = require("./global.helper.cjs");
|
|
2
2
|
//#region src/helpers/search-creator.helper.ts
|
|
3
3
|
const getCreatorName = (el) => {
|
|
4
4
|
return el.querySelector(".user-title").text.trim();
|
|
5
5
|
};
|
|
6
6
|
const getCreatorImage = (el) => {
|
|
7
7
|
const image = el.querySelector("img").attributes.src;
|
|
8
|
-
return addProtocol(image);
|
|
8
|
+
return require_global_helper.addProtocol(image);
|
|
9
9
|
};
|
|
10
10
|
const getCreatorUrl = (el) => {
|
|
11
11
|
return el.querySelector(".user-title a").attributes.href;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
|
-
|
|
14
|
+
exports.getCreatorImage = getCreatorImage;
|
|
15
|
+
exports.getCreatorName = getCreatorName;
|
|
16
|
+
exports.getCreatorUrl = getCreatorUrl;
|
|
15
17
|
|
|
16
|
-
//# sourceMappingURL=search-creator.helper.
|
|
18
|
+
//# sourceMappingURL=search-creator.helper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-creator.helper.cjs","names":["addProtocol"],"sources":["../../src/helpers/search-creator.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { addProtocol } from './global.helper';\n\nexport const getCreatorName = (el: HTMLElement): string => {\n return el.querySelector('.user-title').text.trim();\n};\n\nexport const getCreatorImage = (el: HTMLElement): string => {\n const image = el.querySelector('img').attributes.src;\n return addProtocol(image);\n};\n\nexport const getCreatorUrl = (el: HTMLElement): string => {\n return el.querySelector('.user-title a').attributes.href;\n};\n"],"mappings":";;AAGA,MAAa,kBAAkB,OAA4B;AACzD,QAAO,GAAG,cAAc,cAAc,CAAC,KAAK,MAAM;;AAGpD,MAAa,mBAAmB,OAA4B;CAC1D,MAAM,QAAQ,GAAG,cAAc,MAAM,CAAC,WAAW;AACjD,QAAOA,sBAAAA,YAAY,MAAM;;AAG3B,MAAa,iBAAiB,OAA4B;AACxD,QAAO,GAAG,cAAc,gBAAgB,CAAC,WAAW"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { addProtocol } from "./global.helper.js";
|
|
2
2
|
//#region src/helpers/search-creator.helper.ts
|
|
3
3
|
const getCreatorName = (el) => {
|
|
4
4
|
return el.querySelector(".user-title").text.trim();
|
|
5
5
|
};
|
|
6
6
|
const getCreatorImage = (el) => {
|
|
7
7
|
const image = el.querySelector("img").attributes.src;
|
|
8
|
-
return
|
|
8
|
+
return addProtocol(image);
|
|
9
9
|
};
|
|
10
10
|
const getCreatorUrl = (el) => {
|
|
11
11
|
return el.querySelector(".user-title a").attributes.href;
|
|
12
12
|
};
|
|
13
13
|
//#endregion
|
|
14
|
-
|
|
15
|
-
exports.getCreatorName = getCreatorName;
|
|
16
|
-
exports.getCreatorUrl = getCreatorUrl;
|
|
14
|
+
export { getCreatorImage, getCreatorName, getCreatorUrl };
|
|
17
15
|
|
|
18
16
|
//# sourceMappingURL=search-creator.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-creator.helper.js","names":[
|
|
1
|
+
{"version":3,"file":"search-creator.helper.js","names":[],"sources":["../../src/helpers/search-creator.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { addProtocol } from './global.helper';\n\nexport const getCreatorName = (el: HTMLElement): string => {\n return el.querySelector('.user-title').text.trim();\n};\n\nexport const getCreatorImage = (el: HTMLElement): string => {\n const image = el.querySelector('img').attributes.src;\n return addProtocol(image);\n};\n\nexport const getCreatorUrl = (el: HTMLElement): string => {\n return el.querySelector('.user-title a').attributes.href;\n};\n"],"mappings":";;AAGA,MAAa,kBAAkB,OAA4B;AACzD,QAAO,GAAG,cAAc,cAAc,CAAC,KAAK,MAAM;;AAGpD,MAAa,mBAAmB,OAA4B;CAC1D,MAAM,QAAQ,GAAG,cAAc,MAAM,CAAC,WAAW;AACjD,QAAO,YAAY,MAAM;;AAG3B,MAAa,iBAAiB,OAA4B;AACxD,QAAO,GAAG,cAAc,gBAAgB,CAAC,WAAW"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const require_global_helper = require("./global.helper.cjs");
|
|
2
|
+
let node_html_parser = require("node-html-parser");
|
|
3
3
|
//#region src/helpers/search-user.helper.ts
|
|
4
4
|
const getUser = (el) => {
|
|
5
5
|
return el.querySelector(".user-title-name").text;
|
|
@@ -7,17 +7,20 @@ const getUser = (el) => {
|
|
|
7
7
|
const getUserRealName = (el) => {
|
|
8
8
|
const p = el.querySelector(".article-content p");
|
|
9
9
|
if (!p) return null;
|
|
10
|
-
const textNodes = p.childNodes.filter((n) => n.nodeType === NodeType.TEXT_NODE && n.rawText.trim() !== "");
|
|
10
|
+
const textNodes = p.childNodes.filter((n) => n.nodeType === node_html_parser.NodeType.TEXT_NODE && n.rawText.trim() !== "");
|
|
11
11
|
return textNodes.length ? textNodes[0].rawText.trim() : null;
|
|
12
12
|
};
|
|
13
13
|
const getAvatar = (el) => {
|
|
14
14
|
const image = el.querySelector(".article-img img").attributes.src;
|
|
15
|
-
return addProtocol(image);
|
|
15
|
+
return require_global_helper.addProtocol(image);
|
|
16
16
|
};
|
|
17
17
|
const getUserUrl = (el) => {
|
|
18
18
|
return el.querySelector(".user-title-name").attributes.href;
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
|
|
21
|
+
exports.getAvatar = getAvatar;
|
|
22
|
+
exports.getUser = getUser;
|
|
23
|
+
exports.getUserRealName = getUserRealName;
|
|
24
|
+
exports.getUserUrl = getUserUrl;
|
|
22
25
|
|
|
23
|
-
//# sourceMappingURL=search-user.helper.
|
|
26
|
+
//# sourceMappingURL=search-user.helper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-user.helper.cjs","names":["NodeType","addProtocol"],"sources":["../../src/helpers/search-user.helper.ts"],"sourcesContent":["import { HTMLElement, NodeType } from 'node-html-parser';\nimport { addProtocol } from './global.helper';\n\nexport const getUser = (el: HTMLElement): string => {\n return el.querySelector('.user-title-name').text;\n};\n\nexport const getUserRealName = (el: HTMLElement): string => {\n const p = el.querySelector('.article-content p');\n if (!p) return null;\n\n const textNodes = p.childNodes.filter(n => n.nodeType === NodeType.TEXT_NODE && n.rawText.trim() !== '');\n const name = textNodes.length ? textNodes[0].rawText.trim() : null;\n\n return name;\n};\n\nexport const getAvatar = (el: HTMLElement): string => {\n const image = el.querySelector('.article-img img').attributes.src;\n return addProtocol(image);\n};\n\nexport const getUserUrl = (el: HTMLElement): string => {\n return el.querySelector('.user-title-name').attributes.href;\n};\n"],"mappings":";;;AAGA,MAAa,WAAW,OAA4B;AAClD,QAAO,GAAG,cAAc,mBAAmB,CAAC;;AAG9C,MAAa,mBAAmB,OAA4B;CAC1D,MAAM,IAAI,GAAG,cAAc,qBAAqB;AAChD,KAAI,CAAC,EAAG,QAAO;CAEf,MAAM,YAAY,EAAE,WAAW,QAAO,MAAK,EAAE,aAAaA,iBAAAA,SAAS,aAAa,EAAE,QAAQ,MAAM,KAAK,GAAG;AAGxG,QAFa,UAAU,SAAS,UAAU,GAAG,QAAQ,MAAM,GAAG;;AAKhE,MAAa,aAAa,OAA4B;CACpD,MAAM,QAAQ,GAAG,cAAc,mBAAmB,CAAC,WAAW;AAC9D,QAAOC,sBAAAA,YAAY,MAAM;;AAG3B,MAAa,cAAc,OAA4B;AACrD,QAAO,GAAG,cAAc,mBAAmB,CAAC,WAAW"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { addProtocol } from "./global.helper.js";
|
|
2
|
+
import { NodeType } from "node-html-parser";
|
|
3
3
|
//#region src/helpers/search-user.helper.ts
|
|
4
4
|
const getUser = (el) => {
|
|
5
5
|
return el.querySelector(".user-title-name").text;
|
|
@@ -7,20 +7,17 @@ const getUser = (el) => {
|
|
|
7
7
|
const getUserRealName = (el) => {
|
|
8
8
|
const p = el.querySelector(".article-content p");
|
|
9
9
|
if (!p) return null;
|
|
10
|
-
const textNodes = p.childNodes.filter((n) => n.nodeType ===
|
|
10
|
+
const textNodes = p.childNodes.filter((n) => n.nodeType === NodeType.TEXT_NODE && n.rawText.trim() !== "");
|
|
11
11
|
return textNodes.length ? textNodes[0].rawText.trim() : null;
|
|
12
12
|
};
|
|
13
13
|
const getAvatar = (el) => {
|
|
14
14
|
const image = el.querySelector(".article-img img").attributes.src;
|
|
15
|
-
return
|
|
15
|
+
return addProtocol(image);
|
|
16
16
|
};
|
|
17
17
|
const getUserUrl = (el) => {
|
|
18
18
|
return el.querySelector(".user-title-name").attributes.href;
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
|
|
22
|
-
exports.getUser = getUser;
|
|
23
|
-
exports.getUserRealName = getUserRealName;
|
|
24
|
-
exports.getUserUrl = getUserUrl;
|
|
21
|
+
export { getAvatar, getUser, getUserRealName, getUserUrl };
|
|
25
22
|
|
|
26
23
|
//# sourceMappingURL=search-user.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-user.helper.js","names":[
|
|
1
|
+
{"version":3,"file":"search-user.helper.js","names":[],"sources":["../../src/helpers/search-user.helper.ts"],"sourcesContent":["import { HTMLElement, NodeType } from 'node-html-parser';\nimport { addProtocol } from './global.helper';\n\nexport const getUser = (el: HTMLElement): string => {\n return el.querySelector('.user-title-name').text;\n};\n\nexport const getUserRealName = (el: HTMLElement): string => {\n const p = el.querySelector('.article-content p');\n if (!p) return null;\n\n const textNodes = p.childNodes.filter(n => n.nodeType === NodeType.TEXT_NODE && n.rawText.trim() !== '');\n const name = textNodes.length ? textNodes[0].rawText.trim() : null;\n\n return name;\n};\n\nexport const getAvatar = (el: HTMLElement): string => {\n const image = el.querySelector('.article-img img').attributes.src;\n return addProtocol(image);\n};\n\nexport const getUserUrl = (el: HTMLElement): string => {\n return el.querySelector('.user-title-name').attributes.href;\n};\n"],"mappings":";;;AAGA,MAAa,WAAW,OAA4B;AAClD,QAAO,GAAG,cAAc,mBAAmB,CAAC;;AAG9C,MAAa,mBAAmB,OAA4B;CAC1D,MAAM,IAAI,GAAG,cAAc,qBAAqB;AAChD,KAAI,CAAC,EAAG,QAAO;CAEf,MAAM,YAAY,EAAE,WAAW,QAAO,MAAK,EAAE,aAAa,SAAS,aAAa,EAAE,QAAQ,MAAM,KAAK,GAAG;AAGxG,QAFa,UAAU,SAAS,UAAU,GAAG,QAAQ,MAAM,GAAG;;AAKhE,MAAa,aAAa,OAA4B;CACpD,MAAM,QAAQ,GAAG,cAAc,mBAAmB,CAAC,WAAW;AAC9D,QAAO,YAAY,MAAM;;AAG3B,MAAa,cAAc,OAA4B;AACrD,QAAO,GAAG,cAAc,mBAAmB,CAAC,WAAW"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
const require_global_helper = require("./global.helper.cjs");
|
|
2
2
|
//#region src/helpers/search.helper.ts
|
|
3
3
|
const getSearchType = (el) => {
|
|
4
4
|
const type = el.querySelectorAll(".film-title-info .info")[1];
|
|
5
|
-
return parseFilmType(type?.innerText?.replace(/[{()}]/g, "")?.trim() || "film");
|
|
5
|
+
return require_global_helper.parseFilmType(type?.innerText?.replace(/[{()}]/g, "")?.trim() || "film");
|
|
6
6
|
};
|
|
7
7
|
const getSearchTitle = (el) => {
|
|
8
8
|
return el.querySelector(".film-title-name").text;
|
|
@@ -14,11 +14,11 @@ const getSearchUrl = (el) => {
|
|
|
14
14
|
return el.querySelector(".film-title-name").attributes.href;
|
|
15
15
|
};
|
|
16
16
|
const getSearchColorRating = (el) => {
|
|
17
|
-
return parseColor(el.querySelector(".article-header i.icon").classNames.split(" ").pop());
|
|
17
|
+
return require_global_helper.parseColor(el.querySelector(".article-header i.icon").classNames.split(" ").pop());
|
|
18
18
|
};
|
|
19
19
|
const getSearchPoster = (el) => {
|
|
20
20
|
const image = el.querySelector("img").attributes.src;
|
|
21
|
-
return addProtocol(image);
|
|
21
|
+
return require_global_helper.addProtocol(image);
|
|
22
22
|
};
|
|
23
23
|
const getSearchOrigins = (el) => {
|
|
24
24
|
const originsRaw = el.querySelector(".article-content p .info")?.text;
|
|
@@ -32,7 +32,7 @@ const parseSearchPeople = (el, type) => {
|
|
|
32
32
|
const peopleNode = Array.from(el && el.querySelectorAll(".article-content p")).find((el) => el.textContent.includes(who));
|
|
33
33
|
if (peopleNode) return Array.from(peopleNode.querySelectorAll("a")).map((person) => {
|
|
34
34
|
return {
|
|
35
|
-
id: parseIdFromUrl(person.attributes.href),
|
|
35
|
+
id: require_global_helper.parseIdFromUrl(person.attributes.href),
|
|
36
36
|
name: person.innerText.trim(),
|
|
37
37
|
url: `https://www.csfd.cz${person.attributes.href}`
|
|
38
38
|
};
|
|
@@ -40,6 +40,13 @@ const parseSearchPeople = (el, type) => {
|
|
|
40
40
|
else return [];
|
|
41
41
|
};
|
|
42
42
|
//#endregion
|
|
43
|
-
|
|
43
|
+
exports.getSearchColorRating = getSearchColorRating;
|
|
44
|
+
exports.getSearchOrigins = getSearchOrigins;
|
|
45
|
+
exports.getSearchPoster = getSearchPoster;
|
|
46
|
+
exports.getSearchTitle = getSearchTitle;
|
|
47
|
+
exports.getSearchType = getSearchType;
|
|
48
|
+
exports.getSearchUrl = getSearchUrl;
|
|
49
|
+
exports.getSearchYear = getSearchYear;
|
|
50
|
+
exports.parseSearchPeople = parseSearchPeople;
|
|
44
51
|
|
|
45
|
-
//# sourceMappingURL=search.helper.
|
|
52
|
+
//# sourceMappingURL=search.helper.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.helper.cjs","names":["parseFilmType","parseColor","addProtocol","parseIdFromUrl"],"sources":["../../src/helpers/search.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { CSFDColorRating, CSFDFilmTypes } from '../dto/global';\nimport { CSFDMovieCreator } from '../dto/movie';\nimport { CSFDColors } from '../dto/user-ratings';\nimport { addProtocol, parseColor, parseFilmType, parseIdFromUrl } from './global.helper';\n\ntype Creator = 'Režie:' | 'Hrají:';\n\nexport const getSearchType = (el: HTMLElement): CSFDFilmTypes => {\n const type = el.querySelectorAll('.film-title-info .info')[1];\n return parseFilmType(type?.innerText?.replace(/[{()}]/g, '')?.trim() || 'film');\n};\n\nexport const getSearchTitle = (el: HTMLElement): string => {\n return el.querySelector('.film-title-name').text;\n};\n\nexport const getSearchYear = (el: HTMLElement): number => {\n return +el.querySelectorAll('.film-title-info .info')[0]?.innerText.replace(/[{()}]/g, '');\n};\n\nexport const getSearchUrl = (el: HTMLElement): string => {\n return el.querySelector('.film-title-name').attributes.href;\n};\n\nexport const getSearchColorRating = (el: HTMLElement): CSFDColorRating => {\n return parseColor(\n el.querySelector('.article-header i.icon').classNames.split(' ').pop() as CSFDColors\n );\n};\n\nexport const getSearchPoster = (el: HTMLElement): string => {\n const image = el.querySelector('img').attributes.src;\n return addProtocol(image);\n};\n\nexport const getSearchOrigins = (el: HTMLElement): string[] => {\n const originsRaw = el.querySelector('.article-content p .info')?.text;\n if (!originsRaw) return [];\n const originsAll = originsRaw?.split(', ')?.[0];\n return originsAll?.split('/').map((country) => country.trim());\n};\n\nexport const parseSearchPeople = (\n el: HTMLElement,\n type: 'directors' | 'actors'\n): CSFDMovieCreator[] => {\n let who: Creator;\n if (type === 'directors') who = 'Režie:';\n if (type === 'actors') who = 'Hrají:';\n\n const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) =>\n el.textContent.includes(who)\n );\n\n if (peopleNode) {\n const people = Array.from(peopleNode.querySelectorAll('a')) as unknown as HTMLElement[];\n\n return people.map((person) => {\n return {\n id: parseIdFromUrl(person.attributes.href),\n name: person.innerText.trim(),\n url: `https://www.csfd.cz${person.attributes.href}`\n };\n });\n } else {\n return [];\n }\n};\n"],"mappings":";;AAQA,MAAa,iBAAiB,OAAmC;CAC/D,MAAM,OAAO,GAAG,iBAAiB,yBAAyB,CAAC;AAC3D,QAAOA,sBAAAA,cAAc,MAAM,WAAW,QAAQ,WAAW,GAAG,EAAE,MAAM,IAAI,OAAO;;AAGjF,MAAa,kBAAkB,OAA4B;AACzD,QAAO,GAAG,cAAc,mBAAmB,CAAC;;AAG9C,MAAa,iBAAiB,OAA4B;AACxD,QAAO,CAAC,GAAG,iBAAiB,yBAAyB,CAAC,IAAI,UAAU,QAAQ,WAAW,GAAG;;AAG5F,MAAa,gBAAgB,OAA4B;AACvD,QAAO,GAAG,cAAc,mBAAmB,CAAC,WAAW;;AAGzD,MAAa,wBAAwB,OAAqC;AACxE,QAAOC,sBAAAA,WACL,GAAG,cAAc,yBAAyB,CAAC,WAAW,MAAM,IAAI,CAAC,KAAK,CACvE;;AAGH,MAAa,mBAAmB,OAA4B;CAC1D,MAAM,QAAQ,GAAG,cAAc,MAAM,CAAC,WAAW;AACjD,QAAOC,sBAAAA,YAAY,MAAM;;AAG3B,MAAa,oBAAoB,OAA8B;CAC7D,MAAM,aAAa,GAAG,cAAc,2BAA2B,EAAE;AACjE,KAAI,CAAC,WAAY,QAAO,EAAE;AAE1B,SADmB,YAAY,MAAM,KAAK,GAAG,KAC1B,MAAM,IAAI,CAAC,KAAK,YAAY,QAAQ,MAAM,CAAC;;AAGhE,MAAa,qBACX,IACA,SACuB;CACvB,IAAI;AACJ,KAAI,SAAS,YAAa,OAAM;AAChC,KAAI,SAAS,SAAU,OAAM;CAE7B,MAAM,aAAa,MAAM,KAAK,MAAM,GAAG,iBAAiB,qBAAqB,CA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