node-csfd-api 5.3.0 → 5.4.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 +1 -1
- package/bin/mcp-server.mjs +1 -1
- package/bin/server.mjs +1 -1
- package/fetchers/index.js +53 -9
- package/fetchers/index.js.map +1 -1
- package/fetchers/index.mjs +53 -9
- package/fetchers/index.mjs.map +1 -1
- package/package.json +1 -1
- package/package.mjs +1 -1
- package/src/fetchers/fetch.polyfill.mjs +8 -0
- package/src/fetchers/index.mjs +76 -0
- package/src/helpers/cinema.helper.mjs +80 -0
- package/src/helpers/creator.helper.mjs +69 -0
- package/src/helpers/global.helper.mjs +101 -0
- package/src/helpers/movie.helper.mjs +302 -0
- package/src/helpers/search-creator.helper.mjs +17 -0
- package/src/helpers/search-user.helper.mjs +24 -0
- package/src/helpers/search.helper.mjs +46 -0
- package/src/helpers/user-ratings.helper.mjs +35 -0
- package/src/helpers/user-reviews.helper.mjs +48 -0
- package/src/index.mjs +64 -0
- package/src/services/cinema.service.mjs +32 -0
- package/src/services/creator.service.mjs +33 -0
- package/src/services/movie.service.mjs +62 -0
- package/src/services/search.service.mjs +76 -0
- package/src/services/user-ratings.service.mjs +66 -0
- package/src/services/user-reviews.service.mjs +68 -0
- package/src/vars.mjs +22 -0
package/bin/export-ratings.mjs
CHANGED
package/bin/mcp-server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { csfd } from "../index.mjs";
|
|
2
|
+
import { csfd } from "../src/index.mjs";
|
|
3
3
|
import { name, version } from "../package.mjs";
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
package/bin/server.mjs
CHANGED
package/fetchers/index.js
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
1
|
const require_fetch_polyfill = require("./fetch.polyfill.js");
|
|
2
2
|
//#region src/fetchers/index.ts
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const browserProfiles = [
|
|
4
|
+
{
|
|
5
|
+
"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",
|
|
6
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
|
|
7
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"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",
|
|
11
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
|
|
12
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"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",
|
|
16
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
|
|
17
|
+
"Sec-Ch-Ua-Platform": "\"macOS\""
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"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",
|
|
21
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
|
|
22
|
+
"Sec-Ch-Ua-Platform": "\"macOS\""
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"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",
|
|
26
|
+
"Sec-Ch-Ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
|
|
27
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"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",
|
|
31
|
+
"Sec-Ch-Ua": "\"Microsoft Edge\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
|
|
32
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
33
|
+
}
|
|
8
34
|
];
|
|
9
|
-
const
|
|
35
|
+
const randomProfile = () => browserProfiles[Math.floor(Math.random() * browserProfiles.length)];
|
|
36
|
+
const baseHeaders = {
|
|
37
|
+
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",
|
|
38
|
+
"Accept-Language": "cs-CZ,cs;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
39
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
40
|
+
"Cache-Control": "max-age=0",
|
|
41
|
+
Connection: "keep-alive",
|
|
42
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
43
|
+
"Sec-Fetch-Dest": "document",
|
|
44
|
+
"Sec-Fetch-Mode": "navigate",
|
|
45
|
+
"Sec-Fetch-Site": "none",
|
|
46
|
+
"Sec-Fetch-User": "?1",
|
|
47
|
+
"Upgrade-Insecure-Requests": "1"
|
|
48
|
+
};
|
|
10
49
|
const fetchPage = async (url, optionsRequest) => {
|
|
11
50
|
try {
|
|
12
|
-
const mergedHeaders = new Headers(
|
|
51
|
+
const mergedHeaders = new Headers({
|
|
52
|
+
...baseHeaders,
|
|
53
|
+
...randomProfile()
|
|
54
|
+
});
|
|
13
55
|
if (optionsRequest?.headers) new Headers(optionsRequest.headers).forEach((value, key) => mergedHeaders.set(key, value));
|
|
14
56
|
const { headers: _, ...restOptions } = optionsRequest || {};
|
|
15
57
|
const response = await require_fetch_polyfill.fetchSafe(url, {
|
|
@@ -17,8 +59,10 @@ const fetchPage = async (url, optionsRequest) => {
|
|
|
17
59
|
...restOptions,
|
|
18
60
|
headers: mergedHeaders
|
|
19
61
|
});
|
|
20
|
-
if (response.
|
|
21
|
-
|
|
62
|
+
if (!response.ok) throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
63
|
+
const html = await response.text();
|
|
64
|
+
if (html.includes("Making sure you're not a bot!")) console.warn("node-csfd-api: Trap detected.");
|
|
65
|
+
return html;
|
|
22
66
|
} catch (e) {
|
|
23
67
|
if (e instanceof Error) console.error(e.message);
|
|
24
68
|
else console.error(String(e));
|
package/fetchers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fetchSafe"],"sources":["../../src/fetchers/index.ts"],"sourcesContent":["import { fetchSafe } from './fetch.polyfill';\n\nconst
|
|
1
|
+
{"version":3,"file":"index.js","names":["fetchSafe"],"sources":["../../src/fetchers/index.ts"],"sourcesContent":["import { fetchSafe } from './fetch.polyfill';\n\ninterface BrowserProfile {\n 'User-Agent': string;\n 'Sec-Ch-Ua': string;\n 'Sec-Ch-Ua-Platform': string;\n}\n\nconst browserProfiles: BrowserProfile[] = [\n // Chrome 131 / Windows\n {\n 'User-Agent':\n 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n },\n // Chrome 130 / Windows\n {\n 'User-Agent':\n 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n },\n // Chrome 131 / macOS\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"macOS\"'\n },\n // Chrome 130 / macOS\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"macOS\"'\n },\n // Edge 131 / Windows\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n },\n // Edge 130 / Windows\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Microsoft Edge\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n }\n];\n\nconst randomProfile = (): BrowserProfile =>\n browserProfiles[Math.floor(Math.random() * browserProfiles.length)];\n\nconst baseHeaders = {\n Accept:\n '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',\n 'Accept-Language': 'cs-CZ,cs;q=0.9,en-US;q=0.8,en;q=0.7',\n 'Accept-Encoding': 'gzip, deflate, br',\n 'Cache-Control': 'max-age=0',\n Connection: 'keep-alive',\n 'Sec-Ch-Ua-Mobile': '?0',\n 'Sec-Fetch-Dest': 'document',\n 'Sec-Fetch-Mode': 'navigate',\n 'Sec-Fetch-Site': 'none',\n 'Sec-Fetch-User': '?1',\n 'Upgrade-Insecure-Requests': '1'\n};\n\nexport const fetchPage = async (url: string, optionsRequest?: RequestInit): Promise<string> => {\n try {\n const mergedHeaders = new Headers({ ...baseHeaders, ...randomProfile() });\n\n // Merge any custom headers provided in the function arguments\n if (optionsRequest?.headers) {\n const reqHeaders = new Headers(optionsRequest.headers);\n reqHeaders.forEach((value, key) => mergedHeaders.set(key, value));\n }\n\n const { headers: _, ...restOptions } = optionsRequest || {};\n\n const response = await fetchSafe(url, {\n credentials: 'omit',\n ...restOptions,\n headers: mergedHeaders\n });\n\n if (!response.ok) {\n throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);\n }\n\n const html = await response.text();\n\n // Quickly check if we hit the trap\n if (html.includes(\"Making sure you're not a bot!\")) {\n console.warn('node-csfd-api: Trap detected.');\n }\n\n return html;\n } catch (e: unknown) {\n if (e instanceof Error) {\n console.error(e.message);\n } else {\n console.error(String(e));\n }\n return 'Error';\n }\n};\n"],"mappings":";;AAQA,MAAM,kBAAoC;CAExC;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CACF;AAED,MAAM,sBACJ,gBAAgB,KAAK,MAAM,KAAK,QAAQ,GAAG,gBAAgB,OAAO;AAEpE,MAAM,cAAc;CAClB,QACE;CACF,mBAAmB;CACnB,mBAAmB;CACnB,iBAAiB;CACjB,YAAY;CACZ,oBAAoB;CACpB,kBAAkB;CAClB,kBAAkB;CAClB,kBAAkB;CAClB,kBAAkB;CAClB,6BAA6B;CAC9B;AAED,MAAa,YAAY,OAAO,KAAa,mBAAkD;AAC7F,KAAI;EACF,MAAM,gBAAgB,IAAI,QAAQ;GAAE,GAAG;GAAa,GAAG,eAAe;GAAE,CAAC;AAGzE,MAAI,gBAAgB,QACC,KAAI,QAAQ,eAAe,QAAQ,CAC3C,SAAS,OAAO,QAAQ,cAAc,IAAI,KAAK,MAAM,CAAC;EAGnE,MAAM,EAAE,SAAS,GAAG,GAAG,gBAAgB,kBAAkB,EAAE;EAE3D,MAAM,WAAW,MAAMA,uBAAAA,UAAU,KAAK;GACpC,aAAa;GACb,GAAG;GACH,SAAS;GACV,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,+BAA+B,SAAS,OAAO,YAAY,MAAM;EAGnF,MAAM,OAAO,MAAM,SAAS,MAAM;AAGlC,MAAI,KAAK,SAAS,gCAAgC,CAChD,SAAQ,KAAK,gCAAgC;AAG/C,SAAO;UACA,GAAY;AACnB,MAAI,aAAa,MACf,SAAQ,MAAM,EAAE,QAAQ;MAExB,SAAQ,MAAM,OAAO,EAAE,CAAC;AAE1B,SAAO"}
|
package/fetchers/index.mjs
CHANGED
|
@@ -1,15 +1,57 @@
|
|
|
1
1
|
import { fetchSafe } from "./fetch.polyfill.mjs";
|
|
2
2
|
//#region src/fetchers/index.ts
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const browserProfiles = [
|
|
4
|
+
{
|
|
5
|
+
"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",
|
|
6
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
|
|
7
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"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",
|
|
11
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
|
|
12
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"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",
|
|
16
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
|
|
17
|
+
"Sec-Ch-Ua-Platform": "\"macOS\""
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"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",
|
|
21
|
+
"Sec-Ch-Ua": "\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
|
|
22
|
+
"Sec-Ch-Ua-Platform": "\"macOS\""
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"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",
|
|
26
|
+
"Sec-Ch-Ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
|
|
27
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"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",
|
|
31
|
+
"Sec-Ch-Ua": "\"Microsoft Edge\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"",
|
|
32
|
+
"Sec-Ch-Ua-Platform": "\"Windows\""
|
|
33
|
+
}
|
|
8
34
|
];
|
|
9
|
-
const
|
|
35
|
+
const randomProfile = () => browserProfiles[Math.floor(Math.random() * browserProfiles.length)];
|
|
36
|
+
const baseHeaders = {
|
|
37
|
+
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",
|
|
38
|
+
"Accept-Language": "cs-CZ,cs;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
39
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
40
|
+
"Cache-Control": "max-age=0",
|
|
41
|
+
Connection: "keep-alive",
|
|
42
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
43
|
+
"Sec-Fetch-Dest": "document",
|
|
44
|
+
"Sec-Fetch-Mode": "navigate",
|
|
45
|
+
"Sec-Fetch-Site": "none",
|
|
46
|
+
"Sec-Fetch-User": "?1",
|
|
47
|
+
"Upgrade-Insecure-Requests": "1"
|
|
48
|
+
};
|
|
10
49
|
const fetchPage = async (url, optionsRequest) => {
|
|
11
50
|
try {
|
|
12
|
-
const mergedHeaders = new Headers(
|
|
51
|
+
const mergedHeaders = new Headers({
|
|
52
|
+
...baseHeaders,
|
|
53
|
+
...randomProfile()
|
|
54
|
+
});
|
|
13
55
|
if (optionsRequest?.headers) new Headers(optionsRequest.headers).forEach((value, key) => mergedHeaders.set(key, value));
|
|
14
56
|
const { headers: _, ...restOptions } = optionsRequest || {};
|
|
15
57
|
const response = await fetchSafe(url, {
|
|
@@ -17,8 +59,10 @@ const fetchPage = async (url, optionsRequest) => {
|
|
|
17
59
|
...restOptions,
|
|
18
60
|
headers: mergedHeaders
|
|
19
61
|
});
|
|
20
|
-
if (response.
|
|
21
|
-
|
|
62
|
+
if (!response.ok) throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);
|
|
63
|
+
const html = await response.text();
|
|
64
|
+
if (html.includes("Making sure you're not a bot!")) console.warn("node-csfd-api: Trap detected.");
|
|
65
|
+
return html;
|
|
22
66
|
} catch (e) {
|
|
23
67
|
if (e instanceof Error) console.error(e.message);
|
|
24
68
|
else console.error(String(e));
|
package/fetchers/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/fetchers/index.ts"],"sourcesContent":["import { fetchSafe } from './fetch.polyfill';\n\nconst
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/fetchers/index.ts"],"sourcesContent":["import { fetchSafe } from './fetch.polyfill';\n\ninterface BrowserProfile {\n 'User-Agent': string;\n 'Sec-Ch-Ua': string;\n 'Sec-Ch-Ua-Platform': string;\n}\n\nconst browserProfiles: BrowserProfile[] = [\n // Chrome 131 / Windows\n {\n 'User-Agent':\n 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n },\n // Chrome 130 / Windows\n {\n 'User-Agent':\n 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n },\n // Chrome 131 / macOS\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"macOS\"'\n },\n // Chrome 130 / macOS\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Google Chrome\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"macOS\"'\n },\n // Edge 131 / Windows\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n },\n // Edge 130 / Windows\n {\n 'User-Agent':\n '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',\n 'Sec-Ch-Ua': '\"Microsoft Edge\";v=\"130\", \"Chromium\";v=\"130\", \"Not_A Brand\";v=\"24\"',\n 'Sec-Ch-Ua-Platform': '\"Windows\"'\n }\n];\n\nconst randomProfile = (): BrowserProfile =>\n browserProfiles[Math.floor(Math.random() * browserProfiles.length)];\n\nconst baseHeaders = {\n Accept:\n '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',\n 'Accept-Language': 'cs-CZ,cs;q=0.9,en-US;q=0.8,en;q=0.7',\n 'Accept-Encoding': 'gzip, deflate, br',\n 'Cache-Control': 'max-age=0',\n Connection: 'keep-alive',\n 'Sec-Ch-Ua-Mobile': '?0',\n 'Sec-Fetch-Dest': 'document',\n 'Sec-Fetch-Mode': 'navigate',\n 'Sec-Fetch-Site': 'none',\n 'Sec-Fetch-User': '?1',\n 'Upgrade-Insecure-Requests': '1'\n};\n\nexport const fetchPage = async (url: string, optionsRequest?: RequestInit): Promise<string> => {\n try {\n const mergedHeaders = new Headers({ ...baseHeaders, ...randomProfile() });\n\n // Merge any custom headers provided in the function arguments\n if (optionsRequest?.headers) {\n const reqHeaders = new Headers(optionsRequest.headers);\n reqHeaders.forEach((value, key) => mergedHeaders.set(key, value));\n }\n\n const { headers: _, ...restOptions } = optionsRequest || {};\n\n const response = await fetchSafe(url, {\n credentials: 'omit',\n ...restOptions,\n headers: mergedHeaders\n });\n\n if (!response.ok) {\n throw new Error(`node-csfd-api: Bad response ${response.status} for url: ${url}`);\n }\n\n const html = await response.text();\n\n // Quickly check if we hit the trap\n if (html.includes(\"Making sure you're not a bot!\")) {\n console.warn('node-csfd-api: Trap detected.');\n }\n\n return html;\n } catch (e: unknown) {\n if (e instanceof Error) {\n console.error(e.message);\n } else {\n console.error(String(e));\n }\n return 'Error';\n }\n};\n"],"mappings":";;AAQA,MAAM,kBAAoC;CAExC;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CAED;EACE,cACE;EACF,aAAa;EACb,sBAAsB;EACvB;CACF;AAED,MAAM,sBACJ,gBAAgB,KAAK,MAAM,KAAK,QAAQ,GAAG,gBAAgB,OAAO;AAEpE,MAAM,cAAc;CAClB,QACE;CACF,mBAAmB;CACnB,mBAAmB;CACnB,iBAAiB;CACjB,YAAY;CACZ,oBAAoB;CACpB,kBAAkB;CAClB,kBAAkB;CAClB,kBAAkB;CAClB,kBAAkB;CAClB,6BAA6B;CAC9B;AAED,MAAa,YAAY,OAAO,KAAa,mBAAkD;AAC7F,KAAI;EACF,MAAM,gBAAgB,IAAI,QAAQ;GAAE,GAAG;GAAa,GAAG,eAAe;GAAE,CAAC;AAGzE,MAAI,gBAAgB,QACC,KAAI,QAAQ,eAAe,QAAQ,CAC3C,SAAS,OAAO,QAAQ,cAAc,IAAI,KAAK,MAAM,CAAC;EAGnE,MAAM,EAAE,SAAS,GAAG,GAAG,gBAAgB,kBAAkB,EAAE;EAE3D,MAAM,WAAW,MAAM,UAAU,KAAK;GACpC,aAAa;GACb,GAAG;GACH,SAAS;GACV,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,+BAA+B,SAAS,OAAO,YAAY,MAAM;EAGnF,MAAM,OAAO,MAAM,SAAS,MAAM;AAGlC,MAAI,KAAK,SAAS,gCAAgC,CAChD,SAAQ,KAAK,gCAAgC;AAG/C,SAAO;UACA,GAAY;AACnB,MAAI,aAAa,MACf,SAAQ,MAAM,EAAE,QAAQ;MAExB,SAAQ,MAAM,OAAO,EAAE,CAAC;AAE1B,SAAO"}
|
package/package.json
CHANGED
package/package.mjs
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fetch as fetch$1 } from "cross-fetch";
|
|
3
|
+
|
|
4
|
+
//#region src/fetchers/fetch.polyfill.ts
|
|
5
|
+
const fetchSafe = typeof fetch === "function" && fetch || typeof global === "object" && global.fetch || typeof window !== "undefined" && window.fetch || fetch$1;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { fetchSafe };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fetchSafe } from "./fetch.polyfill.mjs";
|
|
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 };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseColor, parseIdFromUrl } from "./global.helper.mjs";
|
|
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 };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { addProtocol, parseColor, parseDate, parseIdFromUrl } from "./global.helper.mjs";
|
|
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?.querySelectorAll(".updated-box")?.[0]?.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 };
|
|
@@ -0,0 +1,101 @@
|
|
|
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 };
|