node-csfd-api 3.0.0 → 3.1.0-next.3
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/dto/movie.d.mts +22 -1
- package/dto/movie.d.ts +22 -1
- package/helpers/global.helper.js +5 -0
- package/helpers/global.helper.js.map +1 -1
- package/helpers/global.helper.mjs +5 -1
- package/helpers/global.helper.mjs.map +1 -1
- package/helpers/movie.helper.js +80 -0
- package/helpers/movie.helper.js.map +1 -1
- package/helpers/movie.helper.mjs +77 -2
- package/helpers/movie.helper.mjs.map +1 -1
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/package.json +1 -1
- package/services/movie.service.js +15 -3
- package/services/movie.service.js.map +1 -1
- package/services/movie.service.mjs +16 -4
- package/services/movie.service.mjs.map +1 -1
package/dto/movie.d.mts
CHANGED
|
@@ -18,6 +18,21 @@ interface CSFDMovie extends CSFDScreening {
|
|
|
18
18
|
premieres: CSFDPremiere[];
|
|
19
19
|
related: CSFDMovieListItem[];
|
|
20
20
|
similar: CSFDMovieListItem[];
|
|
21
|
+
seasons: CSFDSeason[] | null;
|
|
22
|
+
episodes: CSFDSeason[] | null;
|
|
23
|
+
parent: CSFDParent | null;
|
|
24
|
+
episodeCode: string | null;
|
|
25
|
+
seasonName: string | null;
|
|
26
|
+
}
|
|
27
|
+
interface CSFDParent {
|
|
28
|
+
season: {
|
|
29
|
+
id: number;
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
series: {
|
|
33
|
+
id: number;
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
21
36
|
}
|
|
22
37
|
type CSFDVodService = 'Netflix' | 'hbogo' | 'Prime Video' | 'Apple TV+' | 'iTunes' | 'KVIFF.TV' | 'Edisonline' | 'o2tv' | 'SledovaniTV' | 'Starmax' | 'DAFilms' | 'FILMY ČESKY A ZADARMO' | 'Youtube Česká filmová klasika' | 'VAPET' | 'VOREL FILM' | 'ivysilani' | 'Google Play' | 'Voyo' | 'YouTube Movies' | 'prima+' | 'Lepší.TV' | 'Blu-ray' | 'DVD';
|
|
23
38
|
interface CSFDVod {
|
|
@@ -66,6 +81,12 @@ interface CSFDPremiere {
|
|
|
66
81
|
company: string;
|
|
67
82
|
}
|
|
68
83
|
type CSFDBoxContent = 'Související' | 'Podobné';
|
|
84
|
+
interface CSFDSeason {
|
|
85
|
+
id: number;
|
|
86
|
+
name: string;
|
|
87
|
+
url: string;
|
|
88
|
+
info: string | null;
|
|
89
|
+
}
|
|
69
90
|
//#endregion
|
|
70
|
-
export { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDPremiere, CSFDTitlesOther, CSFDVod, CSFDVodService };
|
|
91
|
+
export { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDParent, CSFDPremiere, CSFDSeason, CSFDTitlesOther, CSFDVod, CSFDVodService };
|
|
71
92
|
//# sourceMappingURL=movie.d.mts.map
|
package/dto/movie.d.ts
CHANGED
|
@@ -18,6 +18,21 @@ interface CSFDMovie extends CSFDScreening {
|
|
|
18
18
|
premieres: CSFDPremiere[];
|
|
19
19
|
related: CSFDMovieListItem[];
|
|
20
20
|
similar: CSFDMovieListItem[];
|
|
21
|
+
seasons: CSFDSeason[] | null;
|
|
22
|
+
episodes: CSFDSeason[] | null;
|
|
23
|
+
parent: CSFDParent | null;
|
|
24
|
+
episodeCode: string | null;
|
|
25
|
+
seasonName: string | null;
|
|
26
|
+
}
|
|
27
|
+
interface CSFDParent {
|
|
28
|
+
season: {
|
|
29
|
+
id: number;
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
series: {
|
|
33
|
+
id: number;
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
21
36
|
}
|
|
22
37
|
type CSFDVodService = 'Netflix' | 'hbogo' | 'Prime Video' | 'Apple TV+' | 'iTunes' | 'KVIFF.TV' | 'Edisonline' | 'o2tv' | 'SledovaniTV' | 'Starmax' | 'DAFilms' | 'FILMY ČESKY A ZADARMO' | 'Youtube Česká filmová klasika' | 'VAPET' | 'VOREL FILM' | 'ivysilani' | 'Google Play' | 'Voyo' | 'YouTube Movies' | 'prima+' | 'Lepší.TV' | 'Blu-ray' | 'DVD';
|
|
23
38
|
interface CSFDVod {
|
|
@@ -66,6 +81,12 @@ interface CSFDPremiere {
|
|
|
66
81
|
company: string;
|
|
67
82
|
}
|
|
68
83
|
type CSFDBoxContent = 'Související' | 'Podobné';
|
|
84
|
+
interface CSFDSeason {
|
|
85
|
+
id: number;
|
|
86
|
+
name: string;
|
|
87
|
+
url: string;
|
|
88
|
+
info: string | null;
|
|
89
|
+
}
|
|
69
90
|
//#endregion
|
|
70
|
-
export { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDPremiere, CSFDTitlesOther, CSFDVod, CSFDVodService };
|
|
91
|
+
export { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDParent, CSFDPremiere, CSFDSeason, CSFDTitlesOther, CSFDVod, CSFDVodService };
|
|
71
92
|
//# sourceMappingURL=movie.d.ts.map
|
package/helpers/global.helper.js
CHANGED
|
@@ -4,6 +4,10 @@ const parseIdFromUrl = (url) => {
|
|
|
4
4
|
if (url) return +(url?.split("/")[2])?.split("-")[0] || null;
|
|
5
5
|
else return null;
|
|
6
6
|
};
|
|
7
|
+
const parseLastIdFromUrl = (url) => {
|
|
8
|
+
if (url) return +(url?.split("/")[3])?.split("-")[0] || null;
|
|
9
|
+
else return null;
|
|
10
|
+
};
|
|
7
11
|
const getColor = (cls) => {
|
|
8
12
|
switch (cls) {
|
|
9
13
|
case "page-lightgrey": return "unknown";
|
|
@@ -47,4 +51,5 @@ exports.getColor = getColor;
|
|
|
47
51
|
exports.parseColor = parseColor;
|
|
48
52
|
exports.parseISO8601Duration = parseISO8601Duration;
|
|
49
53
|
exports.parseIdFromUrl = parseIdFromUrl;
|
|
54
|
+
exports.parseLastIdFromUrl = parseLastIdFromUrl;
|
|
50
55
|
//# sourceMappingURL=global.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.helper.js","names":[],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import { CSFDColorRating } from '../dto/global';\nimport { Colors } from '../dto/user-ratings';\n\nexport const parseIdFromUrl = (url: string): number => {\n if (url) {\n const idSlug = url?.split('/')[2];\n const id = idSlug?.split('-')[0];\n return +id || null;\n } else {\n return null;\n }\n};\n\nexport const getColor = (cls: string): CSFDColorRating => {\n switch (cls) {\n case 'page-lightgrey':\n return 'unknown';\n case 'page-red':\n return 'good';\n case 'page-blue':\n return 'average';\n case 'page-grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const parseColor = (quality: Colors): CSFDColorRating => {\n switch (quality) {\n case 'lightgrey':\n return 'unknown';\n case 'red':\n return 'good';\n case 'blue':\n return 'average';\n case 'grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const addProtocol = (url: string): string => {\n return url.startsWith('//') ? 'https:' + url : url;\n};\n\nexport const getDuration = (matches: any[]) => {\n return {\n sign: matches[1] === undefined ? '+' : '-',\n years: matches[2] === undefined ? 0 : matches[2],\n months: matches[3] === undefined ? 0 : matches[3],\n weeks: matches[4] === undefined ? 0 : matches[4],\n days: matches[5] === undefined ? 0 : matches[5],\n hours: matches[6] === undefined ? 0 : matches[6],\n minutes: matches[7] === undefined ? 0 : matches[7],\n seconds: matches[8] === undefined ? 0 : matches[8]\n };\n};\n\nexport const parseISO8601Duration = (iso: string): number => {\n const iso8601DurationRegex =\n /(-)?P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?T(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?/;\n\n const matches = iso.match(iso8601DurationRegex);\n\n const duration = getDuration(matches);\n\n return +duration.minutes;\n};\n"],"mappings":";;AAGA,MAAa,kBAAkB,QAAwB;AACrD,KAAI,IAGF,QAAO,EAFQ,KAAK,MAAM,IAAI,CAAC,KACZ,MAAM,IAAI,CAAC,MAChB;KAEd,QAAO;;AAIX,MAAa,YAAY,QAAiC;AACxD,SAAQ,KAAR;EACE,KAAK,iBACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,cAAc,YAAqC;AAC9D,SAAQ,SAAR;EACE,KAAK,YACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,eAAe,QAAwB;AAClD,QAAO,IAAI,WAAW,KAAK,GAAG,WAAW,MAAM;;AAGjD,MAAa,eAAe,YAAmB;AAC7C,QAAO;EACL,MAAM,QAAQ,OAAO,SAAY,MAAM;EACvC,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,QAAQ,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC/C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,MAAM,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC7C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAChD,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EACjD;;AAGH,MAAa,wBAAwB,QAAwB;AAQ3D,QAAO,CAFU,YAFD,IAAI,MAFlB,kHAE6C,CAEV,CAEpB"}
|
|
1
|
+
{"version":3,"file":"global.helper.js","names":[],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import { CSFDColorRating } from '../dto/global';\nimport { Colors } from '../dto/user-ratings';\n\nexport const parseIdFromUrl = (url: string): number => {\n if (url) {\n const idSlug = url?.split('/')[2];\n const id = idSlug?.split('-')[0];\n return +id || null;\n } else {\n return null;\n }\n};\n\nexport const parseLastIdFromUrl = (url: string): number => {\n if (url) {\n const idSlug = url?.split('/')[3];\n const id = idSlug?.split('-')[0];\n return +id || null;\n } else {\n return null;\n }\n};\n\nexport const getColor = (cls: string): CSFDColorRating => {\n switch (cls) {\n case 'page-lightgrey':\n return 'unknown';\n case 'page-red':\n return 'good';\n case 'page-blue':\n return 'average';\n case 'page-grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const parseColor = (quality: Colors): CSFDColorRating => {\n switch (quality) {\n case 'lightgrey':\n return 'unknown';\n case 'red':\n return 'good';\n case 'blue':\n return 'average';\n case 'grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const addProtocol = (url: string): string => {\n return url.startsWith('//') ? 'https:' + url : url;\n};\n\nexport const getDuration = (matches: any[]) => {\n return {\n sign: matches[1] === undefined ? '+' : '-',\n years: matches[2] === undefined ? 0 : matches[2],\n months: matches[3] === undefined ? 0 : matches[3],\n weeks: matches[4] === undefined ? 0 : matches[4],\n days: matches[5] === undefined ? 0 : matches[5],\n hours: matches[6] === undefined ? 0 : matches[6],\n minutes: matches[7] === undefined ? 0 : matches[7],\n seconds: matches[8] === undefined ? 0 : matches[8]\n };\n};\n\nexport const parseISO8601Duration = (iso: string): number => {\n const iso8601DurationRegex =\n /(-)?P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?T(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?/;\n\n const matches = iso.match(iso8601DurationRegex);\n\n const duration = getDuration(matches);\n\n return +duration.minutes;\n};\n"],"mappings":";;AAGA,MAAa,kBAAkB,QAAwB;AACrD,KAAI,IAGF,QAAO,EAFQ,KAAK,MAAM,IAAI,CAAC,KACZ,MAAM,IAAI,CAAC,MAChB;KAEd,QAAO;;AAIX,MAAa,sBAAsB,QAAwB;AACzD,KAAI,IAGF,QAAO,EAFQ,KAAK,MAAM,IAAI,CAAC,KACZ,MAAM,IAAI,CAAC,MAChB;KAEd,QAAO;;AAIX,MAAa,YAAY,QAAiC;AACxD,SAAQ,KAAR;EACE,KAAK,iBACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,cAAc,YAAqC;AAC9D,SAAQ,SAAR;EACE,KAAK,YACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,eAAe,QAAwB;AAClD,QAAO,IAAI,WAAW,KAAK,GAAG,WAAW,MAAM;;AAGjD,MAAa,eAAe,YAAmB;AAC7C,QAAO;EACL,MAAM,QAAQ,OAAO,SAAY,MAAM;EACvC,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,QAAQ,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC/C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,MAAM,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC7C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAChD,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EACjD;;AAGH,MAAa,wBAAwB,QAAwB;AAQ3D,QAAO,CAFU,YAFD,IAAI,MAFlB,kHAE6C,CAEV,CAEpB"}
|
|
@@ -3,6 +3,10 @@ const parseIdFromUrl = (url) => {
|
|
|
3
3
|
if (url) return +(url?.split("/")[2])?.split("-")[0] || null;
|
|
4
4
|
else return null;
|
|
5
5
|
};
|
|
6
|
+
const parseLastIdFromUrl = (url) => {
|
|
7
|
+
if (url) return +(url?.split("/")[3])?.split("-")[0] || null;
|
|
8
|
+
else return null;
|
|
9
|
+
};
|
|
6
10
|
const getColor = (cls) => {
|
|
7
11
|
switch (cls) {
|
|
8
12
|
case "page-lightgrey": return "unknown";
|
|
@@ -41,5 +45,5 @@ const parseISO8601Duration = (iso) => {
|
|
|
41
45
|
};
|
|
42
46
|
|
|
43
47
|
//#endregion
|
|
44
|
-
export { addProtocol, getColor, parseColor, parseISO8601Duration, parseIdFromUrl };
|
|
48
|
+
export { addProtocol, getColor, parseColor, parseISO8601Duration, parseIdFromUrl, parseLastIdFromUrl };
|
|
45
49
|
//# sourceMappingURL=global.helper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.helper.mjs","names":[],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import { CSFDColorRating } from '../dto/global';\nimport { Colors } from '../dto/user-ratings';\n\nexport const parseIdFromUrl = (url: string): number => {\n if (url) {\n const idSlug = url?.split('/')[2];\n const id = idSlug?.split('-')[0];\n return +id || null;\n } else {\n return null;\n }\n};\n\nexport const getColor = (cls: string): CSFDColorRating => {\n switch (cls) {\n case 'page-lightgrey':\n return 'unknown';\n case 'page-red':\n return 'good';\n case 'page-blue':\n return 'average';\n case 'page-grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const parseColor = (quality: Colors): CSFDColorRating => {\n switch (quality) {\n case 'lightgrey':\n return 'unknown';\n case 'red':\n return 'good';\n case 'blue':\n return 'average';\n case 'grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const addProtocol = (url: string): string => {\n return url.startsWith('//') ? 'https:' + url : url;\n};\n\nexport const getDuration = (matches: any[]) => {\n return {\n sign: matches[1] === undefined ? '+' : '-',\n years: matches[2] === undefined ? 0 : matches[2],\n months: matches[3] === undefined ? 0 : matches[3],\n weeks: matches[4] === undefined ? 0 : matches[4],\n days: matches[5] === undefined ? 0 : matches[5],\n hours: matches[6] === undefined ? 0 : matches[6],\n minutes: matches[7] === undefined ? 0 : matches[7],\n seconds: matches[8] === undefined ? 0 : matches[8]\n };\n};\n\nexport const parseISO8601Duration = (iso: string): number => {\n const iso8601DurationRegex =\n /(-)?P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?T(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?/;\n\n const matches = iso.match(iso8601DurationRegex);\n\n const duration = getDuration(matches);\n\n return +duration.minutes;\n};\n"],"mappings":";AAGA,MAAa,kBAAkB,QAAwB;AACrD,KAAI,IAGF,QAAO,EAFQ,KAAK,MAAM,IAAI,CAAC,KACZ,MAAM,IAAI,CAAC,MAChB;KAEd,QAAO;;AAIX,MAAa,YAAY,QAAiC;AACxD,SAAQ,KAAR;EACE,KAAK,iBACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,cAAc,YAAqC;AAC9D,SAAQ,SAAR;EACE,KAAK,YACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,eAAe,QAAwB;AAClD,QAAO,IAAI,WAAW,KAAK,GAAG,WAAW,MAAM;;AAGjD,MAAa,eAAe,YAAmB;AAC7C,QAAO;EACL,MAAM,QAAQ,OAAO,SAAY,MAAM;EACvC,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,QAAQ,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC/C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,MAAM,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC7C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAChD,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EACjD;;AAGH,MAAa,wBAAwB,QAAwB;AAQ3D,QAAO,CAFU,YAFD,IAAI,MAFlB,kHAE6C,CAEV,CAEpB"}
|
|
1
|
+
{"version":3,"file":"global.helper.mjs","names":[],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import { CSFDColorRating } from '../dto/global';\nimport { Colors } from '../dto/user-ratings';\n\nexport const parseIdFromUrl = (url: string): number => {\n if (url) {\n const idSlug = url?.split('/')[2];\n const id = idSlug?.split('-')[0];\n return +id || null;\n } else {\n return null;\n }\n};\n\nexport const parseLastIdFromUrl = (url: string): number => {\n if (url) {\n const idSlug = url?.split('/')[3];\n const id = idSlug?.split('-')[0];\n return +id || null;\n } else {\n return null;\n }\n};\n\nexport const getColor = (cls: string): CSFDColorRating => {\n switch (cls) {\n case 'page-lightgrey':\n return 'unknown';\n case 'page-red':\n return 'good';\n case 'page-blue':\n return 'average';\n case 'page-grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const parseColor = (quality: Colors): CSFDColorRating => {\n switch (quality) {\n case 'lightgrey':\n return 'unknown';\n case 'red':\n return 'good';\n case 'blue':\n return 'average';\n case 'grey':\n return 'bad';\n default:\n return 'unknown';\n }\n};\n\nexport const addProtocol = (url: string): string => {\n return url.startsWith('//') ? 'https:' + url : url;\n};\n\nexport const getDuration = (matches: any[]) => {\n return {\n sign: matches[1] === undefined ? '+' : '-',\n years: matches[2] === undefined ? 0 : matches[2],\n months: matches[3] === undefined ? 0 : matches[3],\n weeks: matches[4] === undefined ? 0 : matches[4],\n days: matches[5] === undefined ? 0 : matches[5],\n hours: matches[6] === undefined ? 0 : matches[6],\n minutes: matches[7] === undefined ? 0 : matches[7],\n seconds: matches[8] === undefined ? 0 : matches[8]\n };\n};\n\nexport const parseISO8601Duration = (iso: string): number => {\n const iso8601DurationRegex =\n /(-)?P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?T(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?/;\n\n const matches = iso.match(iso8601DurationRegex);\n\n const duration = getDuration(matches);\n\n return +duration.minutes;\n};\n"],"mappings":";AAGA,MAAa,kBAAkB,QAAwB;AACrD,KAAI,IAGF,QAAO,EAFQ,KAAK,MAAM,IAAI,CAAC,KACZ,MAAM,IAAI,CAAC,MAChB;KAEd,QAAO;;AAIX,MAAa,sBAAsB,QAAwB;AACzD,KAAI,IAGF,QAAO,EAFQ,KAAK,MAAM,IAAI,CAAC,KACZ,MAAM,IAAI,CAAC,MAChB;KAEd,QAAO;;AAIX,MAAa,YAAY,QAAiC;AACxD,SAAQ,KAAR;EACE,KAAK,iBACH,QAAO;EACT,KAAK,WACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,cAAc,YAAqC;AAC9D,SAAQ,SAAR;EACE,KAAK,YACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAa,eAAe,QAAwB;AAClD,QAAO,IAAI,WAAW,KAAK,GAAG,WAAW,MAAM;;AAGjD,MAAa,eAAe,YAAmB;AAC7C,QAAO;EACL,MAAM,QAAQ,OAAO,SAAY,MAAM;EACvC,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,QAAQ,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC/C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,MAAM,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC7C,OAAO,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAC9C,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EAChD,SAAS,QAAQ,OAAO,SAAY,IAAI,QAAQ;EACjD;;AAGH,MAAa,wBAAwB,QAAwB;AAQ3D,QAAO,CAFU,YAFD,IAAI,MAFlB,kHAE6C,CAEV,CAEpB"}
|
package/helpers/movie.helper.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
const require_global_helper = require('./global.helper.js');
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/movie.helper.ts
|
|
4
|
+
const getSerieasAndSeasonTitle = (el) => {
|
|
5
|
+
const titleElement = el.querySelector("h1");
|
|
6
|
+
if (!titleElement) return {
|
|
7
|
+
seriesName: null,
|
|
8
|
+
seasonName: null
|
|
9
|
+
};
|
|
10
|
+
const fullText = titleElement.innerText.trim();
|
|
11
|
+
if (fullText.includes(" - ")) {
|
|
12
|
+
const [seriesName, seasonName] = fullText.split(" - ").map((part) => part.trim());
|
|
13
|
+
return {
|
|
14
|
+
seriesName,
|
|
15
|
+
seasonName
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
seriesName: fullText,
|
|
20
|
+
seasonName: null
|
|
21
|
+
};
|
|
22
|
+
};
|
|
4
23
|
const getMovieTitle = (el) => {
|
|
5
24
|
return el.querySelector("h1").innerText.split(`(`)[0].trim();
|
|
6
25
|
};
|
|
@@ -87,6 +106,62 @@ const parseMoviePeople = (el) => {
|
|
|
87
106
|
};
|
|
88
107
|
});
|
|
89
108
|
};
|
|
109
|
+
const getSeasonsOrEpisodes = (el, serie) => {
|
|
110
|
+
const childrenList = el.querySelector(".film-episodes-list");
|
|
111
|
+
if (!childrenList) return null;
|
|
112
|
+
const childrenNodes = childrenList.querySelectorAll(".film-title");
|
|
113
|
+
if (!childrenNodes?.length) return [];
|
|
114
|
+
return childrenNodes.map((season) => {
|
|
115
|
+
const nameContainer = season.querySelector(".film-title-name");
|
|
116
|
+
const infoContainer = season.querySelector(".info");
|
|
117
|
+
return {
|
|
118
|
+
id: require_global_helper.parseLastIdFromUrl(nameContainer?.getAttribute("href") || ""),
|
|
119
|
+
name: nameContainer?.textContent?.trim() || null,
|
|
120
|
+
url: nameContainer?.getAttribute("href") || null,
|
|
121
|
+
info: infoContainer?.textContent?.replace(/[{()}]/g, "").trim() || null
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const getEpisodeCode = (el) => {
|
|
126
|
+
const filmHeaderName = el.querySelector(".film-header-name h1");
|
|
127
|
+
if (!filmHeaderName) return null;
|
|
128
|
+
const match = (filmHeaderName.textContent?.trim() || "").match(/\(([^)]+)\)/);
|
|
129
|
+
return match ? match[1] : null;
|
|
130
|
+
};
|
|
131
|
+
const detectSeasonOrEpisodeListType = (el) => {
|
|
132
|
+
const headerText = el.querySelector(".box-header h3")?.innerText.trim() ?? "";
|
|
133
|
+
if (headerText.includes("Série")) return "seasons";
|
|
134
|
+
if (headerText.startsWith("Epizody")) return "episodes";
|
|
135
|
+
return null;
|
|
136
|
+
};
|
|
137
|
+
const getSeasonorEpisodeParent = (el, serie) => {
|
|
138
|
+
const parents = el.querySelectorAll(".film-header h2 a");
|
|
139
|
+
if (parents.length === 0) {
|
|
140
|
+
if (!serie) return null;
|
|
141
|
+
return {
|
|
142
|
+
series: serie,
|
|
143
|
+
season: null
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const [parentSeries, parentSeason] = parents;
|
|
147
|
+
const seriesId = require_global_helper.parseIdFromUrl(parentSeries?.getAttribute("href"));
|
|
148
|
+
const seasonId = require_global_helper.parseIdFromUrl(parentSeason?.getAttribute("href"));
|
|
149
|
+
const seriesName = parentSeries?.textContent?.trim() || null;
|
|
150
|
+
const seasonName = parentSeason?.textContent?.trim() || null;
|
|
151
|
+
const series = seriesId && seriesName ? {
|
|
152
|
+
id: seriesId,
|
|
153
|
+
name: seriesName
|
|
154
|
+
} : null;
|
|
155
|
+
const season = seasonId && seasonName ? {
|
|
156
|
+
id: seasonId,
|
|
157
|
+
name: seasonName
|
|
158
|
+
} : null;
|
|
159
|
+
if (!series && !season) return null;
|
|
160
|
+
return {
|
|
161
|
+
series,
|
|
162
|
+
season
|
|
163
|
+
};
|
|
164
|
+
};
|
|
90
165
|
const getMovieGroup = (el, group) => {
|
|
91
166
|
const element = el.querySelectorAll(".creators h4").filter((elem) => elem.textContent.trim().includes(group))[0];
|
|
92
167
|
if (element?.parentNode) return parseMoviePeople(element.parentNode);
|
|
@@ -140,6 +215,8 @@ const getMovieTags = (el) => {
|
|
|
140
215
|
};
|
|
141
216
|
|
|
142
217
|
//#endregion
|
|
218
|
+
exports.detectSeasonOrEpisodeListType = detectSeasonOrEpisodeListType;
|
|
219
|
+
exports.getEpisodeCode = getEpisodeCode;
|
|
143
220
|
exports.getMovieBoxMovies = getMovieBoxMovies;
|
|
144
221
|
exports.getMovieColorRating = getMovieColorRating;
|
|
145
222
|
exports.getMovieDescriptions = getMovieDescriptions;
|
|
@@ -159,4 +236,7 @@ exports.getMovieTrivia = getMovieTrivia;
|
|
|
159
236
|
exports.getMovieType = getMovieType;
|
|
160
237
|
exports.getMovieVods = getMovieVods;
|
|
161
238
|
exports.getMovieYear = getMovieYear;
|
|
239
|
+
exports.getSeasonorEpisodeParent = getSeasonorEpisodeParent;
|
|
240
|
+
exports.getSeasonsOrEpisodes = getSeasonsOrEpisodes;
|
|
241
|
+
exports.getSerieasAndSeasonTitle = getSerieasAndSeasonTitle;
|
|
162
242
|
//# sourceMappingURL=movie.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movie.helper.js","names":["getColor","parseISO8601Duration","el","addProtocol","parseIdFromUrl","vods: CSFDVod[]","movieListItem: CSFDMovieListItem[]","premiere: CSFDPremiere[]"],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { CSFDColorRating } from '../dto/global';\nimport {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDPremiere,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService\n} from '../dto/movie';\nimport { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl } from './global.helper';\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 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 = (el: string): number => {\n try {\n const jsonLd = JSON.parse(el);\n return +jsonLd.dateCreated;\n } catch (error) {\n console.error('node-csfd-api: Error parsing JSON-LD', error);\n return null;\n }\n};\n\nexport const getMovieDuration = (jsonLdRaw: string, el: HTMLElement): number => {\n let duration = null;\n try {\n const jsonLd = JSON.parse(jsonLdRaw);\n duration = jsonLd.duration;\n return parseISO8601Duration(duration);\n } catch (error) {\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 duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\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\nexport const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups): 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 getMovieType = (el: HTMLElement): string => {\n const type = el.querySelector('.film-header-name .type');\n return type?.innerText?.replace(/[{()}]/g, '') || 'film';\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttons = el.querySelectorAll('.box-buttons .button');\n const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));\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 = (el: HTMLElement, boxName: CSFDBoxContent): 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 [date, ...company] = title?.split(' ');\n\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 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":";;;AAoBA,MAAa,iBAAiB,OAA4B;AACxD,QAAO,GAAG,cAAc,KAAK,CAAC,UAAU,MAAM,IAAI,CAAC,GAAG,MAAM;;AAG9D,MAAa,kBAAkB,OAAkC;AAE/D,QADkB,GAAG,cAAc,UAAU,CAAC,YAC7B,MAAM,MAAM;;AAG/B,MAAa,mBAAmB,OAA8B;AAG5D,QAFmB,GAAG,cAAc,UAAU,CAAC,YACpB,MAAM,IAAI,CAAC,GACvB,MAAM,MAAM;;AAG7B,MAAa,uBAAuB,gBAA2C;AAC7E,QAAOA,+BAAS,YAAY,GAAG;;AAGjC,MAAa,kBAAkB,OAA4B;CAEzD,MAAM,SADY,GAAG,cAAc,uBAAuB,CAAC,aACjC,QAAQ,MAAM,GAAG,CAAC,MAAM;CAClD,MAAM,YAAY,SAAS,OAAO;AAElC,KAAI,OAAO,UAAU,UAAU,CAC7B,QAAO;KAEP,QAAO;;AAIX,MAAa,uBAAuB,OAA4B;CAE9D,MAAM,cAAc,EADG,GAAG,cAAc,iCAAiC,EAAE,cACtC,QAAQ,WAAW,GAAG;AAC3D,KAAI,OAAO,UAAU,YAAY,CAC/B,QAAO;KAEP,QAAO;;AAIX,MAAa,gBAAgB,OAAuB;AAClD,KAAI;AAEF,SAAO,CADQ,KAAK,MAAM,GAAG,CACd;UACR,OAAO;AACd,UAAQ,MAAM,wCAAwC,MAAM;AAC5D,SAAO;;;AAIX,MAAa,oBAAoB,WAAmB,OAA4B;CAC9E,IAAI,WAAW;AACf,KAAI;AAEF,aADe,KAAK,MAAM,UAAU,CAClB;AA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qC,EAAE;CAE7C,MAAM,kBADM,cAAc,IAAI,QAAQ,EACT,iBAAiB,mCAAmC;AACjF,KAAI,iBAAiB,OACnB,MAAK,MAAM,QAAQ,gBACjB,eAAc,KAAK;EACjB,IAAIF,qCAAe,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,MAAMG,WAA2B,EAAE;AACnC,MAAK,MAAM,gBAAgB,eAAe;EACxC,MAAM,QAAQ,aAAa,cAAc,WAAW,CAAC,WAAW;AAEhE,MAAI,OAAO;GACT,MAAM,CAAC,MAAM,GAAG,WAAW,OAAO,MAAM,IAAI;AAE5C,YAAS,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;;;AAGN,QAAO;;AAGT,MAAa,gBAAgB,OAA8B;AAEzD,QADgB,GAAG,iBAAiB,kCAAgC,CACrD,KAAK,QAAQ,IAAI,YAAY"}
|
|
1
|
+
{"version":3,"file":"movie.helper.js","names":["getColor","parseISO8601Duration","el","addProtocol","parseIdFromUrl","parseLastIdFromUrl","vods: CSFDVod[]","movieListItem: CSFDMovieListItem[]","premiere: CSFDPremiere[]"],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { CSFDColorRating } from '../dto/global';\nimport {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDParent,\n CSFDPremiere,\n CSFDSeason,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService\n} from '../dto/movie';\nimport { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl, parseLastIdFromUrl } from './global.helper';\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 getSerieasAndSeasonTitle = (el: HTMLElement): { seriesName: string; 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 = (el: string): number => {\n try {\n const jsonLd = JSON.parse(el);\n return +jsonLd.dateCreated;\n } catch (error) {\n console.error('node-csfd-api: Error parsing JSON-LD', error);\n return null;\n }\n};\n\nexport const getMovieDuration = (jsonLdRaw: string, el: HTMLElement): number => {\n let duration = null;\n try {\n const jsonLd = JSON.parse(jsonLdRaw);\n duration = jsonLd.duration;\n return parseISO8601Duration(duration);\n } catch (error) {\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 duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\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\nexport const getSeasonsOrEpisodes = (el: HTMLElement, serie?: { id: number; title: string; }): CSFDSeason[] | 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 return {\n id: parseLastIdFromUrl(nameContainer?.getAttribute('href') || ''),\n name: nameContainer?.textContent?.trim() || null,\n url: nameContainer?.getAttribute('href') || null,\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, serie?: { id: number; name: string; }): CSFDParent | null => {\n const parents = el.querySelectorAll('.film-header h2 a');\n if (parents.length === 0) {\n if (!serie) return null;\n return { series: serie, season: null };\n }\n\n const [parentSeries, parentSeason] = parents;\n\n const seriesId = parseIdFromUrl(parentSeries?.getAttribute('href'));\n const seasonId = parseIdFromUrl(parentSeason?.getAttribute('href'));\n const seriesName = parentSeries?.textContent?.trim() || null;\n const seasonName = parentSeason?.textContent?.trim() || null;\n\n const series = seriesId && seriesName ? { id: seriesId, name: seriesName } : null;\n const season = seasonId && seasonName ? { id: seasonId, name: seasonName } : null;\n\n if (!series && !season) return null;\n\n return { series, season };\n}\n\nexport const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups): 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 getMovieType = (el: HTMLElement): string => {\n const type = el.querySelector('.film-header-name .type');\n return type?.innerText?.replace(/[{()}]/g, '') || 'film';\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttons = el.querySelectorAll('.box-buttons .button');\n const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));\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 = (el: HTMLElement, boxName: CSFDBoxContent): 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 [date, ...company] = title?.split(' ');\n\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 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":";;;AAsBA,MAAa,4BAA4B,OAAuE;CAC9G,MAAM,eAAe,GAAG,cAAc,KAAK;AAC3C,KAAI,CAAC,aACH,QAAO;EAAE,YAAY;EAAM,YAAY;EAAM;CAG/C,MAAM,WAAW,aAAa,UAAU,MAAM;AAG9C,KAAI,SAAS,SAAS,MAAM,EAAE;EAC5B,MAAM,CAAC,YAAY,cAAc,SAAS,MAAM,MAAM,CAAC,KAAI,SAAQ,KAAK,MAAM,CAAC;AAC/E,SAAO;GAAE;GAAY;GAAY;;AAInC,QAAO;EAAE,YAAY;EAAU,YAAY;EAAM;;AAGnD,MAAa,iBAAiB,OAA4B;AACxD,QAAO,GAAG,cAAc,KAAK,CAAC,UAAU,MAAM,IAAI,CAAC,GAAG,MAAM;;AAG9D,MAAa,kBAAkB,OAAkC;AAE/D,QADkB,GAAG,cAAc,UAAU,CAAC,YAC7B,MAAM,MAAM;;AAG/B,MAAa,mBAAmB,OAA8B;AAG5D,QAFmB,GAAG,cAAc,UA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AK,WAAW;EAC5C,CAAC;AAGN,QAAO;;AAGT,MAAa,qBAAqB,OAAoC;CACpE,MAAM,gBAAgB,GAAG,iBAAiB,oBAAoB;CAC9D,MAAMI,WAA2B,EAAE;AACnC,MAAK,MAAM,gBAAgB,eAAe;EACxC,MAAM,QAAQ,aAAa,cAAc,WAAW,CAAC,WAAW;AAEhE,MAAI,OAAO;GACT,MAAM,CAAC,MAAM,GAAG,WAAW,OAAO,MAAM,IAAI;AAE5C,YAAS,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;;;AAGN,QAAO;;AAGT,MAAa,gBAAgB,OAA8B;AAEzD,QADgB,GAAG,iBAAiB,kCAAgC,CACrD,KAAK,QAAQ,IAAI,YAAY"}
|
package/helpers/movie.helper.mjs
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
-
import { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl } from "./global.helper.mjs";
|
|
1
|
+
import { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl, parseLastIdFromUrl } from "./global.helper.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/movie.helper.ts
|
|
4
|
+
const getSerieasAndSeasonTitle = (el) => {
|
|
5
|
+
const titleElement = el.querySelector("h1");
|
|
6
|
+
if (!titleElement) return {
|
|
7
|
+
seriesName: null,
|
|
8
|
+
seasonName: null
|
|
9
|
+
};
|
|
10
|
+
const fullText = titleElement.innerText.trim();
|
|
11
|
+
if (fullText.includes(" - ")) {
|
|
12
|
+
const [seriesName, seasonName] = fullText.split(" - ").map((part) => part.trim());
|
|
13
|
+
return {
|
|
14
|
+
seriesName,
|
|
15
|
+
seasonName
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
seriesName: fullText,
|
|
20
|
+
seasonName: null
|
|
21
|
+
};
|
|
22
|
+
};
|
|
4
23
|
const getMovieTitle = (el) => {
|
|
5
24
|
return el.querySelector("h1").innerText.split(`(`)[0].trim();
|
|
6
25
|
};
|
|
@@ -87,6 +106,62 @@ const parseMoviePeople = (el) => {
|
|
|
87
106
|
};
|
|
88
107
|
});
|
|
89
108
|
};
|
|
109
|
+
const getSeasonsOrEpisodes = (el, serie) => {
|
|
110
|
+
const childrenList = el.querySelector(".film-episodes-list");
|
|
111
|
+
if (!childrenList) return null;
|
|
112
|
+
const childrenNodes = childrenList.querySelectorAll(".film-title");
|
|
113
|
+
if (!childrenNodes?.length) return [];
|
|
114
|
+
return childrenNodes.map((season) => {
|
|
115
|
+
const nameContainer = season.querySelector(".film-title-name");
|
|
116
|
+
const infoContainer = season.querySelector(".info");
|
|
117
|
+
return {
|
|
118
|
+
id: parseLastIdFromUrl(nameContainer?.getAttribute("href") || ""),
|
|
119
|
+
name: nameContainer?.textContent?.trim() || null,
|
|
120
|
+
url: nameContainer?.getAttribute("href") || null,
|
|
121
|
+
info: infoContainer?.textContent?.replace(/[{()}]/g, "").trim() || null
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const getEpisodeCode = (el) => {
|
|
126
|
+
const filmHeaderName = el.querySelector(".film-header-name h1");
|
|
127
|
+
if (!filmHeaderName) return null;
|
|
128
|
+
const match = (filmHeaderName.textContent?.trim() || "").match(/\(([^)]+)\)/);
|
|
129
|
+
return match ? match[1] : null;
|
|
130
|
+
};
|
|
131
|
+
const detectSeasonOrEpisodeListType = (el) => {
|
|
132
|
+
const headerText = el.querySelector(".box-header h3")?.innerText.trim() ?? "";
|
|
133
|
+
if (headerText.includes("Série")) return "seasons";
|
|
134
|
+
if (headerText.startsWith("Epizody")) return "episodes";
|
|
135
|
+
return null;
|
|
136
|
+
};
|
|
137
|
+
const getSeasonorEpisodeParent = (el, serie) => {
|
|
138
|
+
const parents = el.querySelectorAll(".film-header h2 a");
|
|
139
|
+
if (parents.length === 0) {
|
|
140
|
+
if (!serie) return null;
|
|
141
|
+
return {
|
|
142
|
+
series: serie,
|
|
143
|
+
season: null
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const [parentSeries, parentSeason] = parents;
|
|
147
|
+
const seriesId = parseIdFromUrl(parentSeries?.getAttribute("href"));
|
|
148
|
+
const seasonId = parseIdFromUrl(parentSeason?.getAttribute("href"));
|
|
149
|
+
const seriesName = parentSeries?.textContent?.trim() || null;
|
|
150
|
+
const seasonName = parentSeason?.textContent?.trim() || null;
|
|
151
|
+
const series = seriesId && seriesName ? {
|
|
152
|
+
id: seriesId,
|
|
153
|
+
name: seriesName
|
|
154
|
+
} : null;
|
|
155
|
+
const season = seasonId && seasonName ? {
|
|
156
|
+
id: seasonId,
|
|
157
|
+
name: seasonName
|
|
158
|
+
} : null;
|
|
159
|
+
if (!series && !season) return null;
|
|
160
|
+
return {
|
|
161
|
+
series,
|
|
162
|
+
season
|
|
163
|
+
};
|
|
164
|
+
};
|
|
90
165
|
const getMovieGroup = (el, group) => {
|
|
91
166
|
const element = el.querySelectorAll(".creators h4").filter((elem) => elem.textContent.trim().includes(group))[0];
|
|
92
167
|
if (element?.parentNode) return parseMoviePeople(element.parentNode);
|
|
@@ -140,5 +215,5 @@ const getMovieTags = (el) => {
|
|
|
140
215
|
};
|
|
141
216
|
|
|
142
217
|
//#endregion
|
|
143
|
-
export { getMovieBoxMovies, getMovieColorRating, getMovieDescriptions, getMovieDuration, getMovieGenres, getMovieGroup, getMovieOrigins, getMoviePoster, getMoviePremieres, getMovieRandomPhoto, getMovieRating, getMovieRatingCount, getMovieTags, getMovieTitle, getMovieTitlesOther, getMovieTrivia, getMovieType, getMovieVods, getMovieYear };
|
|
218
|
+
export { detectSeasonOrEpisodeListType, getEpisodeCode, getMovieBoxMovies, getMovieColorRating, getMovieDescriptions, getMovieDuration, getMovieGenres, getMovieGroup, getMovieOrigins, getMoviePoster, getMoviePremieres, getMovieRandomPhoto, getMovieRating, getMovieRatingCount, getMovieTags, getMovieTitle, getMovieTitlesOther, getMovieTrivia, getMovieType, getMovieVods, getMovieYear, getSeasonorEpisodeParent, getSeasonsOrEpisodes, getSerieasAndSeasonTitle };
|
|
144
219
|
//# sourceMappingURL=movie.helper.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movie.helper.mjs","names":["el","vods: CSFDVod[]","movieListItem: CSFDMovieListItem[]","premiere: CSFDPremiere[]"],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { CSFDColorRating } from '../dto/global';\nimport {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDPremiere,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService\n} from '../dto/movie';\nimport { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl } from './global.helper';\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 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 = (el: string): number => {\n try {\n const jsonLd = JSON.parse(el);\n return +jsonLd.dateCreated;\n } catch (error) {\n console.error('node-csfd-api: Error parsing JSON-LD', error);\n return null;\n }\n};\n\nexport const getMovieDuration = (jsonLdRaw: string, el: HTMLElement): number => {\n let duration = null;\n try {\n const jsonLd = JSON.parse(jsonLdRaw);\n duration = jsonLd.duration;\n return parseISO8601Duration(duration);\n } catch (error) {\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 duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\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\nexport const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups): 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 getMovieType = (el: HTMLElement): string => {\n const type = el.querySelector('.film-header-name .type');\n return type?.innerText?.replace(/[{()}]/g, '') || 'film';\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttons = el.querySelectorAll('.box-buttons .button');\n const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));\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 = (el: HTMLElement, boxName: CSFDBoxContent): 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 [date, ...company] = title?.split(' ');\n\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 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":";;;AAoBA,MAAa,iBAAiB,OAA4B;AACxD,QAAO,GAAG,cAAc,KAAK,CAAC,UAAU,MAAM,IAAI,CAAC,GAAG,MAAM;;AAG9D,MAAa,kBAAkB,OAAkC;AAE/D,QADkB,GAAG,cAAc,UAAU,CAAC,YAC7B,MAAM,MAAM;;AAG/B,MAAa,mBAAmB,OAA8B;AAG5D,QAFmB,GAAG,cAAc,UAAU,CAAC,YACpB,MAAM,IAAI,CAAC,GACvB,MAAM,MAAM;;AAG7B,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IAClE,QAAQ,aAAa,cAAc,IAAI,CAAC,YAAY,MAAM,EAAE,MAAM,MAAM,CAAC;IACzE;IACA,SAAS,QAAQ,KAAK,IAAI;IAC3B,CAAC;;;AAGN,QAAO;;AAGT,MAAa,gBAAgB,OAA8B;AAEzD,QADgB,GAAG,iBAAiB,kCAAgC,CACrD,KAAK,QAAQ,IAAI,YAAY"}
|
|
1
|
+
{"version":3,"file":"movie.helper.mjs","names":["el","vods: CSFDVod[]","movieListItem: CSFDMovieListItem[]","premiere: CSFDPremiere[]"],"sources":["../../src/helpers/movie.helper.ts"],"sourcesContent":["import { HTMLElement } from 'node-html-parser';\nimport { CSFDColorRating } from '../dto/global';\nimport {\n CSFDBoxContent,\n CSFDCreatorGroups,\n CSFDGenres,\n CSFDMovieCreator,\n CSFDMovieListItem,\n CSFDParent,\n CSFDPremiere,\n CSFDSeason,\n CSFDTitlesOther,\n CSFDVod,\n CSFDVodService\n} from '../dto/movie';\nimport { addProtocol, getColor, parseISO8601Duration, parseIdFromUrl, parseLastIdFromUrl } from './global.helper';\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 getSerieasAndSeasonTitle = (el: HTMLElement): { seriesName: string; 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 = (el: string): number => {\n try {\n const jsonLd = JSON.parse(el);\n return +jsonLd.dateCreated;\n } catch (error) {\n console.error('node-csfd-api: Error parsing JSON-LD', error);\n return null;\n }\n};\n\nexport const getMovieDuration = (jsonLdRaw: string, el: HTMLElement): number => {\n let duration = null;\n try {\n const jsonLd = JSON.parse(jsonLdRaw);\n duration = jsonLd.duration;\n return parseISO8601Duration(duration);\n } catch (error) {\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 duration = hoursMins.length > 1 ? +hoursMins[0] * 60 + +hoursMins[1] : +hoursMins[0];\n return duration;\n } else {\n return null;\n }\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\nexport const getSeasonsOrEpisodes = (el: HTMLElement, serie?: { id: number; title: string; }): CSFDSeason[] | 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 return {\n id: parseLastIdFromUrl(nameContainer?.getAttribute('href') || ''),\n name: nameContainer?.textContent?.trim() || null,\n url: nameContainer?.getAttribute('href') || null,\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, serie?: { id: number; name: string; }): CSFDParent | null => {\n const parents = el.querySelectorAll('.film-header h2 a');\n if (parents.length === 0) {\n if (!serie) return null;\n return { series: serie, season: null };\n }\n\n const [parentSeries, parentSeason] = parents;\n\n const seriesId = parseIdFromUrl(parentSeries?.getAttribute('href'));\n const seasonId = parseIdFromUrl(parentSeason?.getAttribute('href'));\n const seriesName = parentSeries?.textContent?.trim() || null;\n const seasonName = parentSeason?.textContent?.trim() || null;\n\n const series = seriesId && seriesName ? { id: seriesId, name: seriesName } : null;\n const season = seasonId && seasonName ? { id: seasonId, name: seasonName } : null;\n\n if (!series && !season) return null;\n\n return { series, season };\n}\n\nexport const getMovieGroup = (el: HTMLElement, group: CSFDCreatorGroups): 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 getMovieType = (el: HTMLElement): string => {\n const type = el.querySelector('.film-header-name .type');\n return type?.innerText?.replace(/[{()}]/g, '') || 'film';\n};\n\nexport const getMovieVods = (el: HTMLElement | null): CSFDVod[] => {\n let vods: CSFDVod[] = [];\n if (el) {\n const buttons = el.querySelectorAll('.box-buttons .button');\n const buttonsVod = buttons.filter((x) => !x.classNames.includes('button-social'));\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 = (el: HTMLElement, boxName: CSFDBoxContent): 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 [date, ...company] = title?.split(' ');\n\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 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":";;;AAsBA,MAA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import { CSFDColorRating, CSFDFilmTypes, CSFDScreening, CSFDStars } from "./dto/global.mjs";
|
|
2
|
-
import { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDPremiere, CSFDTitlesOther, CSFDVod, CSFDVodService } from "./dto/movie.mjs";
|
|
2
|
+
import { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDParent, CSFDPremiere, CSFDSeason, CSFDTitlesOther, CSFDVod, CSFDVodService } from "./dto/movie.mjs";
|
|
3
3
|
import { CSFDCinema, CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie, CSFDCinemaPeriod } from "./dto/cinema.mjs";
|
|
4
4
|
import { CSFDCreator, CSFDCreatorScreening } from "./dto/creator.mjs";
|
|
5
5
|
import { CSFDSearch, CSFDSearchCreator, CSFDSearchCreators, CSFDSearchMovie, CSFDSearchUser } from "./dto/search.mjs";
|
|
@@ -26,5 +26,5 @@ declare class Csfd {
|
|
|
26
26
|
}
|
|
27
27
|
declare const csfd: Csfd;
|
|
28
28
|
//#endregion
|
|
29
|
-
export { CSFDBoxContent, CSFDCinema, CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie, CSFDCinemaPeriod, CSFDColorRating, CSFDCreator, CSFDCreatorGroups, CSFDCreatorScreening, CSFDCreators, CSFDFilmTypes, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDPremiere, CSFDScreening, CSFDSearch, CSFDSearchCreator, CSFDSearchCreators, CSFDSearchMovie, CSFDSearchUser, CSFDStars, CSFDTitlesOther, CSFDUserRatingConfig, CSFDUserRatings, CSFDVod, CSFDVodService, Colors, Csfd, csfd };
|
|
29
|
+
export { CSFDBoxContent, CSFDCinema, CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie, CSFDCinemaPeriod, CSFDColorRating, CSFDCreator, CSFDCreatorGroups, CSFDCreatorScreening, CSFDCreators, CSFDFilmTypes, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDParent, CSFDPremiere, CSFDScreening, CSFDSearch, CSFDSearchCreator, CSFDSearchCreators, CSFDSearchMovie, CSFDSearchUser, CSFDSeason, CSFDStars, CSFDTitlesOther, CSFDUserRatingConfig, CSFDUserRatings, CSFDVod, CSFDVodService, Colors, Csfd, csfd };
|
|
30
30
|
//# sourceMappingURL=index.d.mts.map
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CSFDColorRating, CSFDFilmTypes, CSFDScreening, CSFDStars } from "./dto/global.js";
|
|
2
|
-
import { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDPremiere, CSFDTitlesOther, CSFDVod, CSFDVodService } from "./dto/movie.js";
|
|
2
|
+
import { CSFDBoxContent, CSFDCreatorGroups, CSFDCreators, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDParent, CSFDPremiere, CSFDSeason, CSFDTitlesOther, CSFDVod, CSFDVodService } from "./dto/movie.js";
|
|
3
3
|
import { CSFDCinema, CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie, CSFDCinemaPeriod } from "./dto/cinema.js";
|
|
4
4
|
import { CSFDCreator, CSFDCreatorScreening } from "./dto/creator.js";
|
|
5
5
|
import { CSFDSearch, CSFDSearchCreator, CSFDSearchCreators, CSFDSearchMovie, CSFDSearchUser } from "./dto/search.js";
|
|
@@ -26,5 +26,5 @@ declare class Csfd {
|
|
|
26
26
|
}
|
|
27
27
|
declare const csfd: Csfd;
|
|
28
28
|
//#endregion
|
|
29
|
-
export { CSFDBoxContent, CSFDCinema, CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie, CSFDCinemaPeriod, CSFDColorRating, CSFDCreator, CSFDCreatorGroups, CSFDCreatorScreening, CSFDCreators, CSFDFilmTypes, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDPremiere, CSFDScreening, CSFDSearch, CSFDSearchCreator, CSFDSearchCreators, CSFDSearchMovie, CSFDSearchUser, CSFDStars, CSFDTitlesOther, CSFDUserRatingConfig, CSFDUserRatings, CSFDVod, CSFDVodService, Colors, Csfd, csfd };
|
|
29
|
+
export { CSFDBoxContent, CSFDCinema, CSFDCinemaGroupedFilmsByDate, CSFDCinemaMeta, CSFDCinemaMovie, CSFDCinemaPeriod, CSFDColorRating, CSFDCreator, CSFDCreatorGroups, CSFDCreatorScreening, CSFDCreators, CSFDFilmTypes, CSFDGenres, CSFDMovie, CSFDMovieCreator, CSFDMovieListItem, CSFDParent, CSFDPremiere, CSFDScreening, CSFDSearch, CSFDSearchCreator, CSFDSearchCreators, CSFDSearchMovie, CSFDSearchUser, CSFDSeason, CSFDStars, CSFDTitlesOther, CSFDUserRatingConfig, CSFDUserRatings, CSFDVod, CSFDVodService, Colors, Csfd, csfd };
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -19,14 +19,18 @@ var MovieScraper = class {
|
|
|
19
19
|
return this.film;
|
|
20
20
|
}
|
|
21
21
|
buildMovie(movieId, el, asideEl, pageClasses, jsonLd) {
|
|
22
|
+
const type = require_movie_helper.getMovieType(el);
|
|
23
|
+
const { seriesName = null, seasonName = null } = type === "série" ? require_movie_helper.getSerieasAndSeasonTitle(el) : {};
|
|
24
|
+
const seasonOrEpisodeListType = require_movie_helper.detectSeasonOrEpisodeListType(el);
|
|
25
|
+
const title = type === "série" && seriesName ? seriesName : require_movie_helper.getMovieTitle(el);
|
|
22
26
|
this.film = {
|
|
23
27
|
id: movieId,
|
|
24
|
-
title
|
|
28
|
+
title,
|
|
25
29
|
year: require_movie_helper.getMovieYear(jsonLd),
|
|
26
30
|
duration: require_movie_helper.getMovieDuration(jsonLd, el),
|
|
27
31
|
descriptions: require_movie_helper.getMovieDescriptions(el),
|
|
28
32
|
genres: require_movie_helper.getMovieGenres(el),
|
|
29
|
-
type
|
|
33
|
+
type,
|
|
30
34
|
url: require_vars.movieUrl(movieId),
|
|
31
35
|
origins: require_movie_helper.getMovieOrigins(el),
|
|
32
36
|
colorRating: require_movie_helper.getMovieColorRating(pageClasses),
|
|
@@ -52,7 +56,15 @@ var MovieScraper = class {
|
|
|
52
56
|
tags: require_movie_helper.getMovieTags(asideEl),
|
|
53
57
|
premieres: require_movie_helper.getMoviePremieres(asideEl),
|
|
54
58
|
related: require_movie_helper.getMovieBoxMovies(asideEl, "Související"),
|
|
55
|
-
similar: require_movie_helper.getMovieBoxMovies(asideEl, "Podobné")
|
|
59
|
+
similar: require_movie_helper.getMovieBoxMovies(asideEl, "Podobné"),
|
|
60
|
+
seasons: seasonOrEpisodeListType === "seasons" ? require_movie_helper.getSeasonsOrEpisodes(el) : null,
|
|
61
|
+
episodes: seasonOrEpisodeListType === "episodes" ? require_movie_helper.getSeasonsOrEpisodes(el) : null,
|
|
62
|
+
parent: type === "seriál" ? null : require_movie_helper.getSeasonorEpisodeParent(el, {
|
|
63
|
+
id: movieId,
|
|
64
|
+
name: title
|
|
65
|
+
}),
|
|
66
|
+
episodeCode: type === "epizoda" ? require_movie_helper.getEpisodeCode(el) : null,
|
|
67
|
+
seasonName
|
|
56
68
|
};
|
|
57
69
|
}
|
|
58
70
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movie.service.js","names":["fetchPage","movieUrl","getMovieTitle","getMovieYear","getMovieDuration","getMovieDescriptions","getMovieGenres","
|
|
1
|
+
{"version":3,"file":"movie.service.js","names":["fetchPage","movieUrl","getMovieType","getSerieasAndSeasonTitle","detectSeasonOrEpisodeListType","getMovieTitle","getMovieYear","getMovieDuration","getMovieDescriptions","getMovieGenres","getMovieOrigins","getMovieColorRating","getMovieRating","getMovieRatingCount","getMovieTitlesOther","getMoviePoster","getMovieRandomPhoto","getMovieTrivia","getMovieGroup","getMovieVods","getMovieTags","getMoviePremieres","getMovieBoxMovies","getSeasonsOrEpisodes","getSeasonorEpisodeParent","getEpisodeCode"],"sources":["../../src/services/movie.service.ts"],"sourcesContent":["import { HTMLElement, parse } from 'node-html-parser';\nimport { CSFDFilmTypes } from '../dto/global';\nimport { CSFDMovie } from '../dto/movie';\nimport { fetchPage } from '../fetchers';\nimport {\n detectSeasonOrEpisodeListType,\n getEpisodeCode,\n getMovieBoxMovies,\n getMovieColorRating,\n getMovieDescriptions,\n getMovieDuration,\n getMovieGenres,\n getMovieGroup,\n getMovieOrigins,\n getMoviePoster,\n getMoviePremieres,\n getMovieRandomPhoto,\n getMovieRating,\n getMovieRatingCount,\n getMovieTags,\n getMovieTitle,\n getMovieTitlesOther,\n getMovieTrivia,\n getMovieType,\n getMovieVods,\n getMovieYear,\n getSeasonorEpisodeParent,\n getSeasonsOrEpisodes,\n getSerieasAndSeasonTitle\n} from '../helpers/movie.helper';\nimport { movieUrl } from '../vars';\n\nexport class MovieScraper {\n private film: CSFDMovie;\n\n public async movie(movieId: number): Promise<CSFDMovie> {\n const id = Number(movieId);\n if (isNaN(id)) {\n throw new Error('node-csfd-api: movieId must be a valid number');\n }\n const url = movieUrl(id);\n const response = await fetchPage(url);\n\n const movieHtml = parse(response);\n\n const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');\n const asideNode = movieHtml.querySelector('.aside-movie-profile');\n const movieNode = movieHtml.querySelector('.main-movie-profile');\n const jsonLd = movieHtml.querySelector('script[type=\"application/ld+json\"]').innerText;\n this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);\n return this.film;\n }\n\n private buildMovie(\n movieId: number,\n el: HTMLElement,\n asideEl: HTMLElement,\n pageClasses: string[],\n jsonLd: string\n ) {\n const type = getMovieType(el) as CSFDFilmTypes;\n const { seriesName = null, seasonName = null } = type === 'série' ? getSerieasAndSeasonTitle(el) : {};\n const seasonOrEpisodeListType = detectSeasonOrEpisodeListType(el);\n\n const title = type === 'série' && seriesName ? seriesName : getMovieTitle(el);\n this.film = {\n id: movieId,\n title,\n year: getMovieYear(jsonLd),\n duration: getMovieDuration(jsonLd, el),\n descriptions: getMovieDescriptions(el),\n genres: getMovieGenres(el),\n type,\n url: movieUrl(movieId),\n origins: getMovieOrigins(el),\n colorRating: getMovieColorRating(pageClasses),\n rating: getMovieRating(asideEl),\n ratingCount: getMovieRatingCount(asideEl),\n titlesOther: getMovieTitlesOther(el),\n poster: getMoviePoster(el),\n photo: getMovieRandomPhoto(el),\n trivia: getMovieTrivia(el),\n creators: {\n directors: getMovieGroup(el, 'Režie'),\n writers: getMovieGroup(el, 'Scénář'),\n cinematography: getMovieGroup(el, 'Kamera'),\n music: getMovieGroup(el, 'Hudba'),\n actors: getMovieGroup(el, 'Hrají'),\n basedOn: getMovieGroup(el, 'Předloha'),\n producers: getMovieGroup(el, 'Produkce'),\n filmEditing: getMovieGroup(el, 'Střih'),\n costumeDesign: getMovieGroup(el, 'Kostýmy'),\n productionDesign: getMovieGroup(el, 'Scénografie'),\n },\n vod: getMovieVods(asideEl),\n tags: getMovieTags(asideEl),\n premieres: getMoviePremieres(asideEl),\n related: getMovieBoxMovies(asideEl, 'Související'),\n similar: getMovieBoxMovies(asideEl, 'Podobné'),\n seasons: seasonOrEpisodeListType === 'seasons' ? getSeasonsOrEpisodes(el) : null,\n episodes: seasonOrEpisodeListType === 'episodes' ? getSeasonsOrEpisodes(el) : null,\n parent: (type === 'seriál') ? null : getSeasonorEpisodeParent(el, { id: movieId, name: title }),\n episodeCode: type === 'epizoda' ? getEpisodeCode(el) : null,\n seasonName,\n };\n }\n}\n"],"mappings":";;;;;;;;AAgCA,IAAa,eAAb,MAA0B;CAGxB,MAAa,MAAM,SAAqC;EACtD,MAAM,KAAK,OAAO,QAAQ;AAC1B,MAAI,MAAM,GAAG,CACX,OAAM,IAAI,MAAM,gDAAgD;EAKlE,MAAM,w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IAAI,QAAQ;IACvC,eAAeA,mCAAc,IAAI,UAAU;IAC3C,kBAAkBA,mCAAc,IAAI,cAAc;IACnD;GACD,KAAKC,kCAAa,QAAQ;GAC1B,MAAMC,kCAAa,QAAQ;GAC3B,WAAWC,uCAAkB,QAAQ;GACrC,SAASC,uCAAkB,SAAS,cAAc;GAClD,SAASA,uCAAkB,SAAS,UAAU;GAC9C,SAAS,4BAA4B,YAAYC,0CAAqB,GAAG,GAAG;GAC5E,UAAU,4BAA4B,aAAaA,0CAAqB,GAAG,GAAG;GAC9E,QAAS,SAAS,WAAY,OAAOC,8CAAyB,IAAI;IAAE,IAAI;IAAS,MAAM;IAAO,CAAC;GAC/F,aAAa,SAAS,YAAYC,oCAAe,GAAG,GAAG;GACvD;GACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fetchPage } from "../fetchers/index.mjs";
|
|
2
2
|
import { movieUrl } from "../vars.mjs";
|
|
3
|
-
import { getMovieBoxMovies, getMovieColorRating, getMovieDescriptions, getMovieDuration, getMovieGenres, getMovieGroup, getMovieOrigins, getMoviePoster, getMoviePremieres, getMovieRandomPhoto, getMovieRating, getMovieRatingCount, getMovieTags, getMovieTitle, getMovieTitlesOther, getMovieTrivia, getMovieType, getMovieVods, getMovieYear } from "../helpers/movie.helper.mjs";
|
|
3
|
+
import { detectSeasonOrEpisodeListType, getEpisodeCode, getMovieBoxMovies, getMovieColorRating, getMovieDescriptions, getMovieDuration, getMovieGenres, getMovieGroup, getMovieOrigins, getMoviePoster, getMoviePremieres, getMovieRandomPhoto, getMovieRating, getMovieRatingCount, getMovieTags, getMovieTitle, getMovieTitlesOther, getMovieTrivia, getMovieType, getMovieVods, getMovieYear, getSeasonorEpisodeParent, getSeasonsOrEpisodes, getSerieasAndSeasonTitle } from "../helpers/movie.helper.mjs";
|
|
4
4
|
import { parse } from "node-html-parser";
|
|
5
5
|
|
|
6
6
|
//#region src/services/movie.service.ts
|
|
@@ -17,14 +17,18 @@ var MovieScraper = class {
|
|
|
17
17
|
return this.film;
|
|
18
18
|
}
|
|
19
19
|
buildMovie(movieId, el, asideEl, pageClasses, jsonLd) {
|
|
20
|
+
const type = getMovieType(el);
|
|
21
|
+
const { seriesName = null, seasonName = null } = type === "série" ? getSerieasAndSeasonTitle(el) : {};
|
|
22
|
+
const seasonOrEpisodeListType = detectSeasonOrEpisodeListType(el);
|
|
23
|
+
const title = type === "série" && seriesName ? seriesName : getMovieTitle(el);
|
|
20
24
|
this.film = {
|
|
21
25
|
id: movieId,
|
|
22
|
-
title
|
|
26
|
+
title,
|
|
23
27
|
year: getMovieYear(jsonLd),
|
|
24
28
|
duration: getMovieDuration(jsonLd, el),
|
|
25
29
|
descriptions: getMovieDescriptions(el),
|
|
26
30
|
genres: getMovieGenres(el),
|
|
27
|
-
type
|
|
31
|
+
type,
|
|
28
32
|
url: movieUrl(movieId),
|
|
29
33
|
origins: getMovieOrigins(el),
|
|
30
34
|
colorRating: getMovieColorRating(pageClasses),
|
|
@@ -50,7 +54,15 @@ var MovieScraper = class {
|
|
|
50
54
|
tags: getMovieTags(asideEl),
|
|
51
55
|
premieres: getMoviePremieres(asideEl),
|
|
52
56
|
related: getMovieBoxMovies(asideEl, "Související"),
|
|
53
|
-
similar: getMovieBoxMovies(asideEl, "Podobné")
|
|
57
|
+
similar: getMovieBoxMovies(asideEl, "Podobné"),
|
|
58
|
+
seasons: seasonOrEpisodeListType === "seasons" ? getSeasonsOrEpisodes(el) : null,
|
|
59
|
+
episodes: seasonOrEpisodeListType === "episodes" ? getSeasonsOrEpisodes(el) : null,
|
|
60
|
+
parent: type === "seriál" ? null : getSeasonorEpisodeParent(el, {
|
|
61
|
+
id: movieId,
|
|
62
|
+
name: title
|
|
63
|
+
}),
|
|
64
|
+
episodeCode: type === "epizoda" ? getEpisodeCode(el) : null,
|
|
65
|
+
seasonName
|
|
54
66
|
};
|
|
55
67
|
}
|
|
56
68
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movie.service.mjs","names":[],"sources":["../../src/services/movie.service.ts"],"sourcesContent":["import { HTMLElement, parse } from 'node-html-parser';\nimport { CSFDFilmTypes } from '../dto/global';\nimport { CSFDMovie } from '../dto/movie';\nimport { fetchPage } from '../fetchers';\nimport {\n getMovieBoxMovies,\n getMovieColorRating,\n getMovieDescriptions,\n getMovieDuration,\n getMovieGenres,\n getMovieGroup,\n getMovieOrigins,\n getMoviePoster,\n getMoviePremieres,\n getMovieRandomPhoto,\n getMovieRating,\n getMovieRatingCount,\n getMovieTags,\n getMovieTitle,\n getMovieTitlesOther,\n getMovieTrivia,\n getMovieType,\n getMovieVods,\n getMovieYear\n} from '../helpers/movie.helper';\nimport { movieUrl } from '../vars';\n\nexport class MovieScraper {\n private film: CSFDMovie;\n\n public async movie(movieId: number): Promise<CSFDMovie> {\n const id = Number(movieId);\n if (isNaN(id)) {\n throw new Error('node-csfd-api: movieId must be a valid number');\n }\n const url = movieUrl(id);\n const response = await fetchPage(url);\n\n const movieHtml = parse(response);\n\n const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');\n const asideNode = movieHtml.querySelector('.aside-movie-profile');\n const movieNode = movieHtml.querySelector('.main-movie-profile');\n const jsonLd = movieHtml.querySelector('script[type=\"application/ld+json\"]').innerText;\n this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);\n return this.film;\n }\n\n private buildMovie(\n movieId: number,\n el: HTMLElement,\n asideEl: HTMLElement,\n pageClasses: string[],\n jsonLd: string\n ) {\n this.film = {\n id: movieId,\n title
|
|
1
|
+
{"version":3,"file":"movie.service.mjs","names":[],"sources":["../../src/services/movie.service.ts"],"sourcesContent":["import { HTMLElement, parse } from 'node-html-parser';\nimport { CSFDFilmTypes } from '../dto/global';\nimport { CSFDMovie } from '../dto/movie';\nimport { fetchPage } from '../fetchers';\nimport {\n detectSeasonOrEpisodeListType,\n getEpisodeCode,\n getMovieBoxMovies,\n getMovieColorRating,\n getMovieDescriptions,\n getMovieDuration,\n getMovieGenres,\n getMovieGroup,\n getMovieOrigins,\n getMoviePoster,\n getMoviePremieres,\n getMovieRandomPhoto,\n getMovieRating,\n getMovieRatingCount,\n getMovieTags,\n getMovieTitle,\n getMovieTitlesOther,\n getMovieTrivia,\n getMovieType,\n getMovieVods,\n getMovieYear,\n getSeasonorEpisodeParent,\n getSeasonsOrEpisodes,\n getSerieasAndSeasonTitle\n} from '../helpers/movie.helper';\nimport { movieUrl } from '../vars';\n\nexport class MovieScraper {\n private film: CSFDMovie;\n\n public async movie(movieId: number): Promise<CSFDMovie> {\n const id = Number(movieId);\n if (isNaN(id)) {\n throw new Error('node-csfd-api: movieId must be a valid number');\n }\n const url = movieUrl(id);\n const response = await fetchPage(url);\n\n const movieHtml = parse(response);\n\n const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');\n const asideNode = movieHtml.querySelector('.aside-movie-profile');\n const movieNode = movieHtml.querySelector('.main-movie-profile');\n const jsonLd = movieHtml.querySelector('script[type=\"application/ld+json\"]').innerText;\n this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);\n return this.film;\n }\n\n private buildMovie(\n movieId: number,\n el: HTMLElement,\n asideEl: HTMLElement,\n pageClasses: string[],\n jsonLd: string\n ) {\n const type = getMovieType(el) as CSFDFilmTypes;\n const { seriesName = null, seasonName = null } = type === 'série' ? getSerieasAndSeasonTitle(el) : {};\n const seasonOrEpisodeListType = detectSeasonOrEpisodeListType(el);\n\n const title = type === 'série' && seriesName ? seriesName : getMovieTitle(el);\n this.film = {\n id: movieId,\n title,\n year: getMovieYear(jsonLd),\n duration: getMovieDuration(jsonLd, el),\n descriptions: getMovieDescriptions(el),\n genres: getMovieGenres(el),\n type,\n url: movieUrl(movieId),\n origins: getMovieOrigins(el),\n colorRating: getMovieColorRating(pageClasses),\n rating: getMovieRating(asideEl),\n ratingCount: getMovieRatingCount(asideEl),\n titlesOther: getMovieTitlesOther(el),\n poster: getMoviePoster(el),\n photo: getMovieRandomPhoto(el),\n trivia: getMovieTrivia(el),\n creators: {\n directors: getMovieGroup(el, 'Režie'),\n writers: getMovieGroup(el, 'Scénář'),\n cinematography: getMovieGroup(el, 'Kamera'),\n music: getMovieGroup(el, 'Hudba'),\n actors: getMovieGroup(el, 'Hrají'),\n basedOn: getMovieGroup(el, 'Předloha'),\n producers: getMovieGroup(el, 'Produkce'),\n filmEditing: getMovieGroup(el, 'Střih'),\n costumeDesign: getMovieGroup(el, 'Kostýmy'),\n productionDesign: getMovieGroup(el, 'Scénografie'),\n },\n vod: getMovieVods(asideEl),\n tags: getMovieTags(asideEl),\n premieres: getMoviePremieres(asideEl),\n related: getMovieBoxMovies(asideEl, 'Související'),\n similar: getMovieBoxMovies(asideEl, 'Podobné'),\n seasons: seasonOrEpisodeListType === 'seasons' ? getSeasonsOrEpisodes(el) : null,\n episodes: seasonOrEpisodeListType === 'episodes' ? getSeasonsOrEpisodes(el) : null,\n parent: (type === 'seriál') ? null : getSeasonorEpisodeParent(el, { id: movieId, name: title }),\n episodeCode: type === 'epizoda' ? getEpisodeCode(el) : null,\n seasonName,\n };\n }\n}\n"],"mappings":";;;;;;AAgCA,IAAa,eAAb,MAA0B;CAGxB,MAAa,MAAM,SAAqC;EACtD,MAAM,KAAK,OAAO,QAAQ;AAC1B,MAAI,MAAM,GAAG,CACX,OAAM,IAAI,MAAM,gDAAgD;EAKlE,MAAM,YAAY,MAFD,MAAM,UADX,SAAS,GAAG,CACa,CAEJ;EAEjC,MAAM,cAAc,UAAU,cAAc,gBAAgB,CAAC,WAAW,MAAM,IAAI;EAClF,MAAM,YAAY,UAAU,cAAc,uBAAuB;EACjE,MAAM,YAAY,UAAU,cAAc,sBAAsB;EAChE,MAAM,SAAS,UAAU,cAAc,uCAAqC,CAAC;AAC7E,OAAK,WAAW,CAAC,SAAS,WAAW,WAAW,aAAa,OAAO;AACpE,SAAO,KAAK;;CAGd,AAAQ,WACN,SACA,IACA,SACA,aACA,QACA;EACA,MAAM,OAAO,aAAa,GAAG;EAC7B,MAA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