Spaces:
Paused
Paused
Download node_modules/yts-api-node/dist/main.js from no1b4me/hytranslator: direct link, hf CLI and curl.
- Browser
- Download file 6.75 kB
-
https://huggingface.co/spaces/no1b4me/hytranslator/resolve/main/node_modules/yts-api-node/dist/main.js
- Command line
-
hf download hf://spaces/no1b4me/hytranslator/node_modules/yts-api-node/dist/main.js
-
curl -L -o main.js https://huggingface.co/spaces/no1b4me/hytranslator/resolve/main/node_modules/yts-api-node/dist/main.js
6.75 kB
| ; | |
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | |
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | |
| return new (P || (P = Promise))(function (resolve, reject) { | |
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | |
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | |
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | |
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | |
| }); | |
| }; | |
| var __importDefault = (this && this.__importDefault) || function (mod) { | |
| return (mod && mod.__esModule) ? mod : { "default": mod }; | |
| }; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.config = void 0; | |
| exports.search = search; | |
| exports.details = details; | |
| exports.suggestions = suggestions; | |
| exports.comments = comments; | |
| exports.reviews = reviews; | |
| exports.parentals = parentals; | |
| exports.upcomming = upcomming; | |
| const cross_fetch_1 = __importDefault(require("cross-fetch")); | |
| /** | |
| * TODO: Implement proxy? | |
| */ | |
| exports.config = { | |
| baseUrl: 'https://yts.mx/api/v2/', | |
| format: 'json', | |
| paths: { | |
| search: '/list_movies', | |
| details: '/movie_details', | |
| suggestions: '/movie_suggestions', | |
| comments: '/movie_comments', | |
| reviews: '/movie_reviews', | |
| parentals: '/movie_parental_guides', | |
| upcomming: '/list_upcoming', | |
| } | |
| }; | |
| /** | |
| * TypeScript compiler complains about strings only | |
| * This helper converts all params to strings | |
| * | |
| * @param params | |
| * @returns URLSearchParams | |
| */ | |
| function searchParams(params) { | |
| Object.keys(params).forEach(param => params[param] = params[param].toString()); | |
| return new URLSearchParams(params); | |
| } | |
| /** | |
| * Send a request to YTS API | |
| * | |
| * @param path - path to api endpoint | |
| * @param params - https://yts.mx/api | |
| * @param format - json|jsonp|xml | |
| * @returns | |
| */ | |
| function doFetch(path_1, params_1) { | |
| return __awaiter(this, arguments, void 0, function* (path, params, format = exports.config.format) { | |
| try { | |
| return yield (0, cross_fetch_1.default)(`${exports.config.baseUrl}/${path}?${params}`.replace('///', '/')).then((response) => __awaiter(this, void 0, void 0, function* () { | |
| if (format === 'xml') { | |
| return yield response.text(); | |
| } | |
| return yield response.json(); | |
| })); | |
| } | |
| catch (e) { | |
| if (e instanceof Error) { | |
| throw new YtsApiException(e.message); | |
| } | |
| throw new YtsApiException('Could not fullfill request'); | |
| } | |
| }); | |
| } | |
| /** | |
| * Used to list and search through out all the available movies. Can sort, filter, search and order the results | |
| * | |
| * @param params | |
| * @param format | |
| * @returns | |
| */ | |
| function search(params, format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| return yield doFetch(`${exports.config.paths.search}.${format || exports.config.format}`, params ? searchParams(params) : undefined, format); | |
| }); | |
| } | |
| /** | |
| * Returns the information about a specific movie | |
| * | |
| * @param params | |
| * @param format | |
| * @returns | |
| */ | |
| function details(params, format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| if (typeof params.movie_id === 'string' && params.movie_id.match(/tt/)) { | |
| return yield doFetch(`${exports.config.paths.details}.${format || exports.config.format}`, searchParams(Object.assign({ imdb_id: params.movie_id }, params)), format); | |
| } | |
| return yield doFetch(`${exports.config.paths.details}.${format || exports.config.format}`, searchParams(params), format); | |
| }); | |
| } | |
| /** | |
| * Returns 4 related movies as suggestions for the user | |
| * | |
| * @param params | |
| * @param format | |
| * @returns | |
| */ | |
| function suggestions(params, format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| return yield doFetch(`${exports.config.paths.suggestions}.${format || exports.config.format}`, searchParams(params), format); | |
| }); | |
| } | |
| /** | |
| * Returns all the comments for the specified movie | |
| * | |
| * ! NOTE: The API route is broken, this function is non functional for the time being | |
| * ! Mabye in the future this will be working again. This is a YTS problem and not a package problem | |
| * ! As soon as these routings are working as intended I will remove the @deprecated marker | |
| * @deprecated This method is not working, API route is not working on YTS side | |
| * @param params | |
| * @param format | |
| */ | |
| function comments(params, format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| return yield doFetch(`${exports.config.paths.comments}.${format || exports.config.format}`, searchParams(params), format); | |
| }); | |
| } | |
| /** | |
| * Returns all the IMDb movie reviews for the specified movie | |
| * | |
| * ! NOTE: The API route is broken, this function is non functional for the time being | |
| * ! Mabye in the future this will be working again. This is a YTS problem and not a package problem | |
| * ! As soon as these routings are working as intended I will remove the @deprecated marker | |
| * @deprecated This method is not working, API route is not working on YTS side | |
| * @param params | |
| * @param format | |
| */ | |
| function reviews(params, format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| return yield doFetch(`${exports.config.paths.reviews}.${format || exports.config.format}`, searchParams(params), format); | |
| }); | |
| } | |
| /** | |
| * Returns all the parental guide ratings for the specified movie | |
| * | |
| * ! Apparently this is not yet implemented inside the YTS API | |
| * | |
| * @param params | |
| * @param format | |
| * @returns | |
| */ | |
| function parentals(params, format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| return yield doFetch(`${exports.config.paths.parentals}.${format || exports.config.format}`, searchParams(params), format); | |
| }); | |
| } | |
| /** | |
| * Returns the 4 latest upcoming movies | |
| * | |
| * ! NOTE: The API route is broken, this function is non functional for the time being | |
| * ! Mabye in the future this will be working again. This is a YTS problem and not a package problem | |
| * ! As soon as these routings are working as intended I will remove the @deprecated marker | |
| * @deprecated This method is not working, API route is not working on YTS side | |
| * @param format | |
| * @returns | |
| */ | |
| function upcomming(format) { | |
| return __awaiter(this, void 0, void 0, function* () { | |
| return yield doFetch(`${exports.config.paths.upcomming}.${format || exports.config.format}`, undefined, format); | |
| }); | |
| } | |
| class YtsApiException extends Error { | |
| } | |
| //# sourceMappingURL=main.js.map |