node-csfd-api 5.5.0 → 5.6.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/export-ratings.js +1 -1
- package/bin/mcp-server.js +1 -1
- package/bin/server.js +1 -1
- package/cli.js +19 -6
- package/package.js +1 -1
- package/package.json +5 -2
- package/src/fetchers/fetch.polyfill.js +0 -6
- package/src/fetchers/index.js +0 -76
- package/src/helpers/cinema.helper.js +0 -80
- package/src/helpers/creator.helper.js +0 -69
- package/src/helpers/global.helper.js +0 -101
- package/src/helpers/movie.helper.js +0 -302
- package/src/helpers/search-creator.helper.js +0 -17
- package/src/helpers/search-user.helper.js +0 -24
- package/src/helpers/search.helper.js +0 -46
- package/src/helpers/user-ratings.helper.js +0 -35
- package/src/helpers/user-reviews.helper.js +0 -48
- package/src/index.js +0 -65
- package/src/services/cinema.service.js +0 -32
- package/src/services/creator.service.js +0 -33
- package/src/services/movie.service.js +0 -62
- package/src/services/search.service.js +0 -76
- package/src/services/user-ratings.service.js +0 -66
- package/src/services/user-reviews.service.js +0 -68
- package/src/vars.js +0 -22
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { fetchPage } from "../fetchers/index.js";
|
|
3
|
-
import { getUrlByLanguage, searchUrl } from "../vars.js";
|
|
4
|
-
import { parseIdFromUrl } from "../helpers/global.helper.js";
|
|
5
|
-
import { getCreatorImage, getCreatorName, getCreatorUrl } from "../helpers/search-creator.helper.js";
|
|
6
|
-
import { getAvatar, getUser, getUserRealName, getUserUrl } from "../helpers/search-user.helper.js";
|
|
7
|
-
import { getSearchColorRating, getSearchOrigins, getSearchPoster, getSearchTitle, getSearchType, getSearchUrl, getSearchYear, parseSearchPeople } from "../helpers/search.helper.js";
|
|
8
|
-
import { parse } from "node-html-parser";
|
|
9
|
-
|
|
10
|
-
//#region src/services/search.service.ts
|
|
11
|
-
var SearchScraper = class {
|
|
12
|
-
async search(text, options) {
|
|
13
|
-
const html = parse(await fetchPage(searchUrl(text, { language: options?.language }), { ...options?.request }));
|
|
14
|
-
const moviesNode = html.querySelectorAll(".main-movies article");
|
|
15
|
-
const usersNode = html.querySelectorAll(".main-users article");
|
|
16
|
-
const tvSeriesNode = html.querySelectorAll(".main-series article");
|
|
17
|
-
const creatorsNode = html.querySelectorAll(".main-authors article");
|
|
18
|
-
return this.parseSearch(moviesNode, usersNode, tvSeriesNode, creatorsNode, options?.language);
|
|
19
|
-
}
|
|
20
|
-
parseSearch(moviesNode, usersNode, tvSeriesNode, creatorsNode, language) {
|
|
21
|
-
const baseUrl = getUrlByLanguage(language);
|
|
22
|
-
const movies = [];
|
|
23
|
-
const users = [];
|
|
24
|
-
const tvSeries = [];
|
|
25
|
-
const creators = [];
|
|
26
|
-
const movieMapper = (m) => {
|
|
27
|
-
const url = getSearchUrl(m);
|
|
28
|
-
return {
|
|
29
|
-
id: parseIdFromUrl(url),
|
|
30
|
-
title: getSearchTitle(m),
|
|
31
|
-
year: getSearchYear(m),
|
|
32
|
-
url: `${baseUrl}${url}`,
|
|
33
|
-
type: getSearchType(m),
|
|
34
|
-
colorRating: getSearchColorRating(m),
|
|
35
|
-
poster: getSearchPoster(m),
|
|
36
|
-
origins: getSearchOrigins(m),
|
|
37
|
-
creators: {
|
|
38
|
-
directors: parseSearchPeople(m, "directors"),
|
|
39
|
-
actors: parseSearchPeople(m, "actors")
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
const userMapper = (m) => {
|
|
44
|
-
const url = getUserUrl(m);
|
|
45
|
-
return {
|
|
46
|
-
id: parseIdFromUrl(url),
|
|
47
|
-
user: getUser(m),
|
|
48
|
-
userRealName: getUserRealName(m),
|
|
49
|
-
avatar: getAvatar(m),
|
|
50
|
-
url: `${baseUrl}${url}`
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
const creatorMapper = (m) => {
|
|
54
|
-
const url = getCreatorUrl(m);
|
|
55
|
-
return {
|
|
56
|
-
id: parseIdFromUrl(url),
|
|
57
|
-
name: getCreatorName(m),
|
|
58
|
-
image: getCreatorImage(m),
|
|
59
|
-
url: `${baseUrl}${url}`
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
movies.push(...moviesNode.map(movieMapper));
|
|
63
|
-
users.push(...usersNode.map(userMapper));
|
|
64
|
-
tvSeries.push(...tvSeriesNode.map(movieMapper));
|
|
65
|
-
creators.push(...creatorsNode.map(creatorMapper));
|
|
66
|
-
return {
|
|
67
|
-
movies,
|
|
68
|
-
users,
|
|
69
|
-
tvSeries,
|
|
70
|
-
creators
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
export { SearchScraper };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { fetchPage } from "../fetchers/index.js";
|
|
3
|
-
import { userRatingsUrl } from "../vars.js";
|
|
4
|
-
import { sleep } from "../helpers/global.helper.js";
|
|
5
|
-
import { getUserRating, getUserRatingColorRating, getUserRatingDate, getUserRatingId, getUserRatingTitle, getUserRatingType, getUserRatingUrl, getUserRatingYear } from "../helpers/user-ratings.helper.js";
|
|
6
|
-
import { parse } from "node-html-parser";
|
|
7
|
-
|
|
8
|
-
//#region src/services/user-ratings.service.ts
|
|
9
|
-
var UserRatingsScraper = class {
|
|
10
|
-
async userRatings(user, config, options) {
|
|
11
|
-
let allMovies = [];
|
|
12
|
-
const pageToFetch = config?.page || 1;
|
|
13
|
-
const url = userRatingsUrl(user, pageToFetch > 1 ? pageToFetch : void 0, { language: options?.language });
|
|
14
|
-
const items = parse(await fetchPage(url, { ...options?.request }));
|
|
15
|
-
const movies = items.querySelectorAll("#snippet--ratings table tr");
|
|
16
|
-
const pagesNode = items.querySelector(".pagination");
|
|
17
|
-
const pages = +pagesNode?.childNodes[pagesNode.childNodes.length - 4].rawText || 1;
|
|
18
|
-
allMovies = this.getPage(config, movies);
|
|
19
|
-
if (config?.allPages) {
|
|
20
|
-
console.log("User", user, url);
|
|
21
|
-
console.log("Fetching all pages", pages);
|
|
22
|
-
for (let i = 2; i <= pages; i++) {
|
|
23
|
-
console.log("Fetching page", i, "out of", pages, "...");
|
|
24
|
-
const movies = parse(await fetchPage(userRatingsUrl(user, i, { language: options?.language }), { ...options?.request })).querySelectorAll("#snippet--ratings table tr");
|
|
25
|
-
allMovies = [...allMovies, ...this.getPage(config, movies)];
|
|
26
|
-
if (config.allPagesDelay) await sleep(config.allPagesDelay);
|
|
27
|
-
}
|
|
28
|
-
return allMovies;
|
|
29
|
-
}
|
|
30
|
-
return allMovies;
|
|
31
|
-
}
|
|
32
|
-
getPage(config, movies) {
|
|
33
|
-
const films = [];
|
|
34
|
-
if (config) {
|
|
35
|
-
if (config.includesOnly?.length && config.excludes?.length) console.warn(`node-csfd-api:
|
|
36
|
-
You can not use both parameters 'includesOnly' and 'excludes'.
|
|
37
|
-
Parameter 'includesOnly' will be used now:`, config.includesOnly);
|
|
38
|
-
}
|
|
39
|
-
const includesSet = config?.includesOnly?.length ? new Set(config.includesOnly) : null;
|
|
40
|
-
const excludesSet = config?.excludes?.length ? new Set(config.excludes) : null;
|
|
41
|
-
for (const el of movies) {
|
|
42
|
-
const type = getUserRatingType(el);
|
|
43
|
-
if (includesSet) {
|
|
44
|
-
if (includesSet.has(type)) films.push(this.buildUserRatings(el, type));
|
|
45
|
-
} else if (excludesSet) {
|
|
46
|
-
if (!excludesSet.has(type)) films.push(this.buildUserRatings(el, type));
|
|
47
|
-
} else films.push(this.buildUserRatings(el, type));
|
|
48
|
-
}
|
|
49
|
-
return films;
|
|
50
|
-
}
|
|
51
|
-
buildUserRatings(el, type) {
|
|
52
|
-
return {
|
|
53
|
-
id: getUserRatingId(el),
|
|
54
|
-
title: getUserRatingTitle(el),
|
|
55
|
-
year: getUserRatingYear(el),
|
|
56
|
-
type,
|
|
57
|
-
url: getUserRatingUrl(el),
|
|
58
|
-
colorRating: getUserRatingColorRating(el),
|
|
59
|
-
userDate: getUserRatingDate(el),
|
|
60
|
-
userRating: getUserRating(el)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { UserRatingsScraper };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { fetchPage } from "../fetchers/index.js";
|
|
3
|
-
import { userReviewsUrl } from "../vars.js";
|
|
4
|
-
import { sleep } from "../helpers/global.helper.js";
|
|
5
|
-
import { getUserReviewColorRating, getUserReviewDate, getUserReviewId, getUserReviewPoster, getUserReviewRating, getUserReviewText, getUserReviewTitle, getUserReviewType, getUserReviewUrl, getUserReviewYear } from "../helpers/user-reviews.helper.js";
|
|
6
|
-
import { parse } from "node-html-parser";
|
|
7
|
-
|
|
8
|
-
//#region src/services/user-reviews.service.ts
|
|
9
|
-
var UserReviewsScraper = class {
|
|
10
|
-
async userReviews(user, config, options) {
|
|
11
|
-
let allReviews = [];
|
|
12
|
-
const pageToFetch = config?.page || 1;
|
|
13
|
-
const url = userReviewsUrl(user, pageToFetch > 1 ? pageToFetch : void 0, { language: options?.language });
|
|
14
|
-
const items = parse(await fetchPage(url, { ...options?.request }));
|
|
15
|
-
const reviews = items.querySelectorAll(".user-tab-reviews .article");
|
|
16
|
-
const pagesNode = items.querySelector(".pagination");
|
|
17
|
-
const pages = +pagesNode?.childNodes[pagesNode.childNodes.length - 4].rawText || 1;
|
|
18
|
-
allReviews = this.getPage(config, reviews);
|
|
19
|
-
if (config?.allPages) {
|
|
20
|
-
console.log("User", user, url);
|
|
21
|
-
console.log("Fetching all pages", pages);
|
|
22
|
-
for (let i = 2; i <= pages; i++) {
|
|
23
|
-
console.log("Fetching page", i, "out of", pages, "...");
|
|
24
|
-
const reviews = parse(await fetchPage(userReviewsUrl(user, i, { language: options?.language }), { ...options?.request })).querySelectorAll(".user-tab-reviews .article");
|
|
25
|
-
allReviews = [...allReviews, ...this.getPage(config, reviews)];
|
|
26
|
-
if (config.allPagesDelay) await sleep(config.allPagesDelay);
|
|
27
|
-
}
|
|
28
|
-
return allReviews;
|
|
29
|
-
}
|
|
30
|
-
return allReviews;
|
|
31
|
-
}
|
|
32
|
-
getPage(config, reviews) {
|
|
33
|
-
const films = [];
|
|
34
|
-
if (config) {
|
|
35
|
-
if (config.includesOnly?.length && config.excludes?.length) console.warn(`node-csfd-api:
|
|
36
|
-
You can not use both parameters 'includesOnly' and 'excludes'.
|
|
37
|
-
Parameter 'includesOnly' will be used now:`, config.includesOnly);
|
|
38
|
-
}
|
|
39
|
-
const includesSet = config?.includesOnly?.length ? new Set(config.includesOnly) : null;
|
|
40
|
-
const excludesSet = config?.excludes?.length ? new Set(config.excludes) : null;
|
|
41
|
-
for (const el of reviews) {
|
|
42
|
-
const type = getUserReviewType(el);
|
|
43
|
-
if (includesSet) {
|
|
44
|
-
if (includesSet.has(type)) films.push(this.buildUserReviews(el, type));
|
|
45
|
-
} else if (excludesSet) {
|
|
46
|
-
if (!excludesSet.has(type)) films.push(this.buildUserReviews(el, type));
|
|
47
|
-
} else films.push(this.buildUserReviews(el, type));
|
|
48
|
-
}
|
|
49
|
-
return films;
|
|
50
|
-
}
|
|
51
|
-
buildUserReviews(el, type) {
|
|
52
|
-
return {
|
|
53
|
-
id: getUserReviewId(el),
|
|
54
|
-
title: getUserReviewTitle(el),
|
|
55
|
-
year: getUserReviewYear(el),
|
|
56
|
-
type,
|
|
57
|
-
url: getUserReviewUrl(el),
|
|
58
|
-
colorRating: getUserReviewColorRating(el),
|
|
59
|
-
userDate: getUserReviewDate(el),
|
|
60
|
-
userRating: getUserReviewRating(el),
|
|
61
|
-
text: getUserReviewText(el),
|
|
62
|
-
poster: getUserReviewPoster(el)
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
export { UserReviewsScraper };
|
package/src/vars.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
//#region src/vars.ts
|
|
3
|
-
const LANGUAGE_DOMAIN_MAP = {
|
|
4
|
-
cs: "https://www.csfd.cz",
|
|
5
|
-
en: "https://www.csfd.cz/en",
|
|
6
|
-
sk: "https://www.csfd.cz/sk"
|
|
7
|
-
};
|
|
8
|
-
let BASE_URL = LANGUAGE_DOMAIN_MAP.cs;
|
|
9
|
-
const getUrlByLanguage = (language) => {
|
|
10
|
-
if (language && language in LANGUAGE_DOMAIN_MAP) return LANGUAGE_DOMAIN_MAP[language];
|
|
11
|
-
return BASE_URL;
|
|
12
|
-
};
|
|
13
|
-
const userUrl = (user, options) => `${getUrlByLanguage(options?.language)}/uzivatel/${encodeURIComponent(user)}`;
|
|
14
|
-
const userRatingsUrl = (user, page, options = {}) => `${userUrl(user, options)}/hodnoceni/${page ? "?page=" + page : ""}`;
|
|
15
|
-
const userReviewsUrl = (user, page, options = {}) => `${userUrl(user, options)}/recenze/${page ? "?page=" + page : ""}`;
|
|
16
|
-
const movieUrl = (movie, options) => `${getUrlByLanguage(options?.language)}/film/${encodeURIComponent(movie)}/prehled/`;
|
|
17
|
-
const creatorUrl = (creator, options) => `${getUrlByLanguage(options?.language)}/tvurce/${encodeURIComponent(creator)}`;
|
|
18
|
-
const cinemasUrl = (district, period, options) => `${getUrlByLanguage(options?.language)}/kino/?period=${period}&district=${district}`;
|
|
19
|
-
const searchUrl = (text, options) => `${getUrlByLanguage(options?.language)}/hledat/?q=${encodeURIComponent(text)}`;
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
export { cinemasUrl, creatorUrl, getUrlByLanguage, movieUrl, searchUrl, userRatingsUrl, userReviewsUrl };
|