node-csfd-api 5.5.0 → 5.6.0-next.2

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { csfd } from "../src/index.js";
2
+ import { csfd } from "../index.js";
3
3
  import { writeFile } from "node:fs/promises";
4
4
 
5
5
  //#region src/bin/export-ratings.ts
package/bin/mcp-server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { csfd } from "../src/index.js";
2
+ import { csfd } from "../index.js";
3
3
  import { name, version } from "../package.js";
4
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
package/bin/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { csfd } from "../src/index.js";
2
+ import { csfd } from "../index.js";
3
3
  import { homepage, name, version } from "../package.js";
4
4
  import "dotenv/config";
5
5
  import express from "express";
package/cli.js CHANGED
@@ -1,8 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  //#region src/cli.ts
3
- /**
4
- * Main CLI entry point for node-csfd-api.
5
- */
3
+ function getCommandName() {
4
+ const scriptPath = process.argv[1] ?? "";
5
+ const basename = scriptPath.split("/").pop() ?? "";
6
+ if (basename === "csfd" || basename === "node-csfd-api") return basename;
7
+ if (scriptPath.includes("node-csfd-api")) return "npx node-csfd-api";
8
+ return "csfd";
9
+ }
6
10
  async function main() {
7
11
  const args = process.argv.slice(2);
8
12
  switch (args[0]) {
@@ -29,7 +33,7 @@ async function main() {
29
33
  const userId = Number(userIdRaw);
30
34
  if (!userIdRaw || isNaN(userId)) {
31
35
  console.error("Error: Please provide a valid numeric User ID.");
32
- console.log("Usage: npx node-csfd-api export ratings <userId> [options]");
36
+ console.log(`Usage: ${getCommandName()} export ratings <userId> [options]`);
33
37
  process.exit(1);
34
38
  }
35
39
  const isLetterboxd = args.includes("--letterboxd");
@@ -55,7 +59,7 @@ async function main() {
55
59
  }
56
60
  } else if (args[1] === "letterboxd") {
57
61
  console.warn("Deprecation Warning: \"export letterboxd\" is deprecated. Please use \"export ratings <id> --letterboxd\" instead.");
58
- console.log("Usage: npx node-csfd-api export ratings <userId> --letterboxd");
62
+ console.log(`Usage: ${getCommandName()} export ratings <userId> --letterboxd`);
59
63
  process.exit(1);
60
64
  } else {
61
65
  console.error(`Unknown export target: ${args[1]}`);
@@ -63,14 +67,19 @@ async function main() {
63
67
  process.exit(1);
64
68
  }
65
69
  break;
70
+ case "--version":
71
+ case "-v":
72
+ console.log("5.6.0-next.2");
73
+ break;
66
74
  default:
67
75
  printUsage();
68
76
  break;
69
77
  }
70
78
  }
71
79
  function printUsage() {
80
+ const cmd = getCommandName();
72
81
  console.log(`
73
- Usage: npx node-csfd-api <command> [options]
82
+ Usage: ${cmd} <command> [options]
74
83
 
75
84
  Commands:
76
85
  server, api Start the REST API server
@@ -81,6 +90,10 @@ Commands:
81
90
  --json Export to JSON format
82
91
  --letterboxd Export to Letterboxd-compatible CSV format
83
92
  help Show this help message
93
+
94
+ Flags:
95
+ --version, -v Show version
96
+ --help, -h Show this help message
84
97
  `);
85
98
  }
86
99
  main().catch((error) => {
package/package.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  //#region package.json
3
3
  var name = "node-csfd-api";
4
- var version = "5.5.0";
4
+ var version = "5.6.0-next.2";
5
5
  var homepage = "https://github.com/bartholomej/node-csfd-api#readme";
6
6
 
7
7
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-csfd-api",
3
- "version": "5.5.0",
3
+ "version": "5.6.0-next.2",
4
4
  "description": "ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)",
5
5
  "author": "BART! <bart@bartweb.cz>",
6
6
  "publishConfig": {
@@ -63,6 +63,9 @@
63
63
  },
64
64
  "./package.json": "./package.json"
65
65
  },
66
- "bin": "cli.js",
66
+ "bin": {
67
+ "csfd": "cli.js",
68
+ "node-csfd-api": "cli.js"
69
+ },
67
70
  "sideEffects": false
68
71
  }
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- //#region src/fetchers/fetch.polyfill.ts
3
- const fetchSafe = typeof fetch === "function" && fetch || typeof global === "object" && global.fetch || typeof window !== "undefined" && window.fetch;
4
-
5
- //#endregion
6
- export { fetchSafe };
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env node
2
- import { fetchSafe } from "./fetch.polyfill.js";
3
-
4
- //#region src/fetchers/index.ts
5
- const browserProfiles = [
6
- {
7
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
8
- "Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
9
- "Sec-Ch-Ua-Platform": "\"Windows\""
10
- },
11
- {
12
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
13
- "Sec-Ch-Ua": "\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
14
- "Sec-Ch-Ua-Platform": "\"Windows\""
15
- },
16
- {
17
- "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
18
- "Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
19
- "Sec-Ch-Ua-Platform": "\"macOS\""
20
- },
21
- {
22
- "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
23
- "Sec-Ch-Ua": "\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
24
- "Sec-Ch-Ua-Platform": "\"macOS\""
25
- },
26
- {
27
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
28
- "Sec-Ch-Ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
29
- "Sec-Ch-Ua-Platform": "\"Windows\""
30
- },
31
- {
32
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
33
- "Sec-Ch-Ua": "\"Microsoft Edge\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
34
- "Sec-Ch-Ua-Platform": "\"Windows\""
35
- }
36
- ];
37
- const randomProfile = () => browserProfiles[Math.floor(Math.random() * browserProfiles.length)];
38
- const baseHeaders = {
39
- Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
40
- "Accept-Language": "cs-CZ,cs;q=0.9,en-US;q=0.8,en;q=0.7",
41
- "Accept-Encoding": "gzip, deflate, br",
42
- "Cache-Control": "max-age=0",
43
- Connection: "keep-alive",
44
- "Sec-Ch-Ua-Mobile": "?0",
45
- "Sec-Fetch-Dest": "document",
46
- "Sec-Fetch-Mode": "navigate",
47
- "Sec-Fetch-Site": "none",
48
- "Sec-Fetch-User": "?1",
49
- "Upgrade-Insecure-Requests": "1"
50
- };
51
- const fetchPage = async (url, optionsRequest) => {
52
- try {
53
- const mergedHeaders = new Headers({
54
- ...baseHeaders,
55
- ...randomProfile()
56
- });
57
- if (optionsRequest?.headers) new Headers(optionsRequest.headers).forEach((value, key) => mergedHeaders.set(key, value));
58
- const { headers: _, ...restOptions } = optionsRequest || {};
59
- const response = await fetchSafe(url, {
60
- credentials: "omit",
61
- ...restOptions,
62
- headers: mergedHeaders
63
- });
64
- if (!response.ok) throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
65
- const html = await response.text();
66
- if (html.includes("Making sure you're not a bot!")) console.warn("node-csfd-api: Trap detected.");
67
- return html;
68
- } catch (e) {
69
- if (e instanceof Error) console.error(e.message);
70
- else console.error(String(e));
71
- return "Error";
72
- }
73
- };
74
-
75
- //#endregion
76
- export { fetchPage };
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env node
2
- import { parseColor, parseIdFromUrl } from "./global.helper.js";
3
-
4
- //#region src/helpers/cinema.helper.ts
5
- const getCinemaColorRating = (el) => {
6
- const classes = el?.classNames.split(" ") ?? [];
7
- const last = classes.length ? classes[classes.length - 1] : void 0;
8
- return last ? parseColor(last) : "unknown";
9
- };
10
- const getCinemaId = (el) => {
11
- return +el?.id?.split("-")[1];
12
- };
13
- const getCinemaUrlId = (url) => {
14
- if (!url) return null;
15
- return parseIdFromUrl(url);
16
- };
17
- const getCinemaCoords = (el) => {
18
- if (!el) return null;
19
- const linkMapsEl = el.querySelector("a[href*=\"q=\"]");
20
- if (!linkMapsEl) return null;
21
- const [_, latLng] = linkMapsEl.getAttribute("href").split("q=");
22
- const coords = latLng.split(",");
23
- if (coords.length !== 2) return null;
24
- const lat = Number(coords[0]);
25
- const lng = Number(coords[1]);
26
- if (Number.isFinite(lat) && Number.isFinite(lng)) return {
27
- lat,
28
- lng
29
- };
30
- return null;
31
- };
32
- const getCinemaUrl = (el) => {
33
- if (!el) return "";
34
- return el.querySelector(".cinema-logo a")?.attributes.href ?? "";
35
- };
36
- const parseCinema = (el) => {
37
- const [city, name] = el.querySelector("header h2").innerText.trim().split(" - ");
38
- return {
39
- city,
40
- name
41
- };
42
- };
43
- const getGroupedFilmsByDate = (el) => {
44
- const divs = el.querySelectorAll(":scope > div");
45
- return divs.map((_, index) => index).filter((index) => index % 2 === 0).map((index) => {
46
- const [date, films] = divs.slice(index, index + 2);
47
- return {
48
- date: date?.firstChild?.textContent?.trim() ?? null,
49
- films: getCinemaFilms("", films)
50
- };
51
- });
52
- };
53
- const getCinemaFilms = (date, el) => {
54
- return el.querySelectorAll(".cinema-table tr").map((filmNode) => {
55
- const url = filmNode.querySelector("td.name h3 a")?.attributes.href;
56
- const id = url ? getCinemaUrlId(url) : null;
57
- const title = filmNode.querySelector(".name h3")?.text.trim();
58
- const colorRating = getCinemaColorRating(filmNode.querySelector(".name .icon"));
59
- const showTimes = filmNode.querySelectorAll(".td-time")?.map((x) => x.textContent.trim());
60
- const meta = filmNode.querySelectorAll(".td-title span")?.map((x) => x.text.trim());
61
- return {
62
- id,
63
- title,
64
- url,
65
- colorRating,
66
- showTimes,
67
- meta: parseMeta(meta)
68
- };
69
- });
70
- };
71
- const parseMeta = (meta) => {
72
- const metaConvert = [];
73
- for (const element of meta) if (element === "T") metaConvert.push("subtitles");
74
- else if (element === "D") metaConvert.push("dubbing");
75
- else metaConvert.push(element);
76
- return metaConvert;
77
- };
78
-
79
- //#endregion
80
- export { getCinemaCoords, getCinemaId, getCinemaUrl, getGroupedFilmsByDate, parseCinema };
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env node
2
- import { addProtocol, parseColor, parseDate, parseIdFromUrl } from "./global.helper.js";
3
-
4
- //#region src/helpers/creator.helper.ts
5
- const getCreatorColorRating = (el) => {
6
- const classes = el?.classNames.split(" ") ?? [];
7
- const last = classes[classes.length - 1];
8
- return parseColor(last);
9
- };
10
- const getCreatorId = (url) => {
11
- return url ? parseIdFromUrl(url) : null;
12
- };
13
- const getCreatorName = (el) => {
14
- return (el?.querySelector("h1"))?.innerText?.trim() ?? null;
15
- };
16
- const getCreatorBirthdayInfo = (el) => {
17
- const infoBlock = el?.querySelector(".creator-profile-details p");
18
- const text = infoBlock?.innerHTML.trim();
19
- const birthPlaceRow = infoBlock?.querySelector(".info-place")?.innerText.trim();
20
- const ageRow = infoBlock?.querySelector(".info")?.innerText.trim();
21
- let birthday = null;
22
- if (text) {
23
- const birthdayRow = text.split("\n").find((x) => x.includes("nar."));
24
- birthday = birthdayRow ? parseDate(parseBirthday(birthdayRow)) : null;
25
- }
26
- const age = ageRow ? +parseAge(ageRow) : null;
27
- const birthPlace = birthPlaceRow ? parseBirthPlace(birthPlaceRow) : "";
28
- return {
29
- birthday,
30
- age,
31
- birthPlace
32
- };
33
- };
34
- const getCreatorBio = (el) => {
35
- return (el?.querySelector(".article-content p"))?.text?.trim().split("\n")[0]?.trim() || null;
36
- };
37
- const getCreatorPhoto = (el) => {
38
- const src = el?.querySelector("img")?.getAttribute("src");
39
- return src ? addProtocol(src) : null;
40
- };
41
- const parseBirthday = (text) => text.replace(/nar\./g, "").trim();
42
- const parseAge = (text) => {
43
- const digits = text.replace(/[^\d]/g, "");
44
- return digits ? Number(digits) : null;
45
- };
46
- const parseBirthPlace = (text) => text.trim().replace(/<br>/g, "").trim();
47
- const getCreatorFilms = (el) => {
48
- const filmNodes = el?.querySelector(".updated-box")?.querySelectorAll("table tr") ?? [];
49
- let yearCache = null;
50
- return filmNodes.map((filmNode) => {
51
- const id = getCreatorId(filmNode.querySelector("td.name .film-title-name")?.attributes?.href);
52
- const title = filmNode.querySelector(".name")?.text?.trim();
53
- const yearText = filmNode.querySelector(".year")?.text?.trim();
54
- const year = yearText ? +yearText : null;
55
- const colorRating = getCreatorColorRating(filmNode.querySelector(".name .icon"));
56
- if (typeof year === "number" && !isNaN(year)) yearCache = +year;
57
- const finalYear = year ?? yearCache;
58
- if (id != null && title && finalYear != null) return {
59
- id,
60
- title,
61
- year: finalYear,
62
- colorRating
63
- };
64
- return null;
65
- }).filter(Boolean);
66
- };
67
-
68
- //#endregion
69
- export { getCreatorBio, getCreatorBirthdayInfo, getCreatorFilms, getCreatorName, getCreatorPhoto };
@@ -1,101 +0,0 @@
1
- #!/usr/bin/env node
2
- //#region src/helpers/global.helper.ts
3
- const LANG_PREFIX_REGEX = /^[a-z]{2,3}$/;
4
- const ISO8601_DURATION_REGEX = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;
5
- const parseIdFromUrl = (url) => {
6
- if (!url) return null;
7
- const parts = url.split("/");
8
- const idParts = parts.filter((p) => /^\d+-/.test(p));
9
- if (idParts.length > 0) return +idParts[idParts.length - 1].split("-")[0] || null;
10
- return +parts[LANG_PREFIX_REGEX.test(parts[1]) ? 3 : 2]?.split("-")[0] || null;
11
- };
12
- const parseLastIdFromUrl = (url) => {
13
- if (url) return +(url?.split("/")[3])?.split("-")[0] || null;
14
- else return null;
15
- };
16
- const PAGE_COLORS = {
17
- "page-lightgrey": "unknown",
18
- "page-red": "good",
19
- "page-blue": "average",
20
- "page-grey": "bad"
21
- };
22
- const getColor = (cls) => {
23
- return PAGE_COLORS[cls] || "unknown";
24
- };
25
- const RATING_COLORS = {
26
- lightgrey: "unknown",
27
- red: "good",
28
- blue: "average",
29
- grey: "bad"
30
- };
31
- const parseColor = (quality) => {
32
- return RATING_COLORS[quality] || "unknown";
33
- };
34
- const FILM_TYPES = {
35
- "TV film": "tv-film",
36
- pořad: "tv-show",
37
- seriál: "series",
38
- "divadelní záznam": "theatrical",
39
- koncert: "concert",
40
- série: "season",
41
- "studentský film": "student-film",
42
- "amatérský film": "amateur-film",
43
- "hudební videoklip": "music-video",
44
- epizoda: "episode",
45
- "video kompilace": "video-compilation",
46
- film: "film"
47
- };
48
- const parseFilmType = (type) => {
49
- return FILM_TYPES[type] || "film";
50
- };
51
- const addProtocol = (url) => {
52
- return url.startsWith("//") ? "https:" + url : url;
53
- };
54
- const getDuration = (matches) => {
55
- return {
56
- sign: matches[1] === void 0 ? "+" : "-",
57
- years: matches[2] === void 0 ? 0 : matches[2],
58
- months: matches[3] === void 0 ? 0 : matches[3],
59
- weeks: matches[4] === void 0 ? 0 : matches[4],
60
- days: matches[5] === void 0 ? 0 : matches[5],
61
- hours: matches[6] === void 0 ? 0 : matches[6],
62
- minutes: matches[7] === void 0 ? 0 : matches[7],
63
- seconds: matches[8] === void 0 ? 0 : matches[8]
64
- };
65
- };
66
- const parseISO8601Duration = (iso) => {
67
- const duration = getDuration(iso.match(ISO8601_DURATION_REGEX));
68
- return +duration.hours * 60 + +duration.minutes;
69
- };
70
- /**
71
- * Parses a date string into a standardized YYYY-MM-DD format.
72
- * Supports:
73
- * - D.M.YYYY
74
- * - DD.MM.YYYY
75
- * - D. M. YYYY
76
- * - MM/DD/YYYY
77
- * - YYYY
78
- */
79
- const parseDate = (date) => {
80
- if (!date) return null;
81
- const cleanDate = date.trim();
82
- const dateMatch = cleanDate.match(/^(\d{1,2})\.\s*(\d{1,2})\.\s*(\d{4})$/);
83
- if (dateMatch) {
84
- const day = dateMatch[1].padStart(2, "0");
85
- const month = dateMatch[2].padStart(2, "0");
86
- return `${dateMatch[3]}-${month}-${day}`;
87
- }
88
- const slashMatch = cleanDate.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
89
- if (slashMatch) {
90
- const month = slashMatch[1].padStart(2, "0");
91
- const day = slashMatch[2].padStart(2, "0");
92
- return `${slashMatch[3]}-${month}-${day}`;
93
- }
94
- const yearMatch = cleanDate.match(/^(\d{4})$/);
95
- if (yearMatch) return `${yearMatch[1]}-01-01`;
96
- return null;
97
- };
98
- const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
99
-
100
- //#endregion
101
- export { addProtocol, getColor, parseColor, parseDate, parseFilmType, parseISO8601Duration, parseIdFromUrl, parseLastIdFromUrl, sleep };