better-trakt
Version:
A Trakt.tv client with native Typescript support and quality of life features
276 lines • 11.3 kB
JavaScript
"use strict";
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Shows = void 0;
const media_1 = require("../media");
const utils_1 = require("../utils");
/**
* Shows api namespace
*/
class Shows {
constructor(config) {
this.config = {
apiUrl: `${config.apiUrl}/shows`,
client: config.client,
};
}
/**
* Returns a single shows's details.
* @param showId show id
* @returns
*/
summary({ showId }) {
(0, utils_1.checkRequiredArg)(showId, 'showId', 'string');
return (0, media_1.getMediaSummary_Full)(this.config, showId);
}
/**
* Returns all cast and crew for a show.
* @param showId show id
* @returns
*/
people({ showId }) {
(0, utils_1.checkRequiredArg)(showId, 'showId', 'string');
return (0, media_1.getMediaPeople)(this.config, showId);
}
/**
* Returns all shows being watched right now.
* @param pagination
* @returns
*/
trending({ pagination, filters, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getTrendingMedia)(this.config, 'shows', { pagination, filters });
}
/**
* Returns the most popular shows.
* @param pagination
* @returns
*/
popular({ pagination, filters, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getPopularMedia)(this.config, 'shows', { pagination, filters });
}
/**
* Returns the most recommended shows in the specified time period, defaulting to weekly. All stats are relative to the specific time period.
* @param param0
* @returns
*/
recommended({ pagination, filters, period, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getRecommendedMedia)(this.config, 'shows', { pagination, filters, period });
}
/**
* Returns the most played (a single user can watch multiple episodes multiple times) shows in the specified time period, defaulting to weekly. All stats are relative to the specific time period.
* @param param0
* @returns
*/
played({ pagination, filters, period, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getPlayedMedia)(this.config, 'shows', { pagination, filters, period });
}
/**
* Returns the most watched (unique users) shows in the specified time period, defaulting to weekly. All stats are relative to the specific time period.
* @param param0
* @returns
*/
watched({ pagination, filters, period, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getWatchedMedia)(this.config, 'shows', { pagination, filters, period });
}
/**
* Returns the most watched (unique users) shows in the specified time period, defaulting to weekly. All stats are relative to the specific time period.
* @param param0
* @returns
*/
collected({ pagination, filters, period, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getCollectedMedia)(this.config, 'shows', { pagination, filters, period });
}
/**
* Returns the most anticipated shows based on the number of lists a show appears on.
* @param param0
* @returns
*/
anticipated({ pagination, filters, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getAnticipatedMedia)(this.config, 'shows', { pagination, filters });
}
/**
* Returns the top 10 grossing shows in the U.S. box office last weekend. Updated every Monday morning.
* @returns
*/
boxOffice() {
return (0, media_1.getBoxOfficeMedia)(this.config, 'shows');
}
/**
* Returns all shows updated since the specified UTC date and time.
* We recommended storing the X-Start-Date header you can be efficient using this method moving forward.
* By default, 10 results are returned. You can send a limit to get up to 100 results per page.
*
* **Important!**
* The start_date is only accurate to the hour, for caching purposes.
* Please drop the minutes and seconds from your timestamp to help optimize our cached data.
* For example, use 2021-07-17T12:00:00Z and not 2021-07-17T12:23:34Z.
*
* Note: The start_date can only be a maximum of 30 days in the past.
* @param param0
* @returns
*/
updates({ pagination, startDate, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getUpdatesMedia)(this.config, 'shows', { pagination, startDate });
}
/**
* Returns all movie Trakt IDs updated since the specified UTC date and time.
* We recommended storing the X-Start-Date header you can be efficient using this method moving forward.
* By default, 10 results are returned. You can send a limit to get up to 100 results per page.
*
* **Important!**
* The start_date is only accurate to the hour, for caching purposes.
* Please drop the minutes and seconds from your timestamp to help optimize our cached data.
* For example, use 2021-07-17T12:00:00Z and not 2021-07-17T12:23:34Z.
*
* Note: The start_date can only be a maximum of 30 days in the past.
* @param param0
* @returns
*/
updatedIDs({ pagination, startDate, }) {
(0, utils_1.checkRequiredArg)(pagination, 'pagination', 'object');
return (0, media_1.getUpdatedIDsMedia)(this.config, 'shows', { pagination, startDate });
}
/**
* Returns all title aliases for a show. Includes country where name is different.
* @param param0
* @returns
*/
aliases({ showID }) {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getAliasesMedia)(this.config, 'shows', { mediaID: showID });
}
/**
* Gets all content certifications for a show, including the country.
* @param param0
* @returns all content certifications for a show
*/
certifications({ showID }) {
return __awaiter(this, void 0, void 0, function* () {
const url = `${this.config.apiUrl}/shows/${showID}/certifications`;
const response = yield (0, utils_1.fetch)(this.config.client, url);
return response;
});
}
/**
* Returns all translations for a show, including language and translated values for title and overview.
* @param param0
* @returns
*/
translations({ showID, language, }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getMediaTranslations)(this.config, 'shows', showID, language);
});
}
/**
* Returns all top level comments for a movie. By default, the newest comments are returned first.
* Other sorting options include oldest, most likes, most replies, highest rated, lowest rated, and most plays.
* @param param0
* @returns
*/
comments({ showID, pagination, sort, }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getMediaComments)(this.config, 'shows', showID, { pagination, sort });
});
}
/**
* Returns all lists that contain this show. By default, personal lists are returned sorted by the most popular.
* @param param0
* @returns
*/
lists({ showID, pagination, sort, type, }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getListsWithMedia)(this.config, 'shows', showID, { pagination, sort, type });
});
}
/**
* Returns rating (between 0 and 10) and distribution for a show.
* @param param0
* @returns
*/
ratings({ showID }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getMediaRating)(this.config, 'shows', showID);
});
}
/**
* Returns related and similar shows.
* @param param0
* @returns
*/
related({ showID, pagination, }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getRelatedMedia)(this.config, 'shows', showID, { pagination });
});
}
/**
* Returns lots of show stats.
* @param param0
* @returns
*/
stats({ showID }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getMediaStats)(this.config, 'shows', showID);
});
}
/**
* Returns all users watching this show right now.
* @param param0
* @returns
*/
watching({ showID }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
return (0, media_1.getWatchingMedia)(this.config, 'shows', showID);
});
}
/**
* Returns the next scheduled to air episode. If no episode is found, a 204 HTTP status code will be returned.
* @param param0
* @returns
*/
nextEpisode({ showID }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
const url = `${this.config.apiUrl}/shows/${showID}/next_episode`;
const response = yield (0, utils_1.fetch)(this.config.client, url);
return response;
});
}
/**
* Returns the most recently aired episode. If no episode is found, a 204 HTTP status code will be returned.
* @param param0
* @returns
*/
lastEpisode({ showID }) {
return __awaiter(this, void 0, void 0, function* () {
(0, utils_1.checkRequiredArg)(showID, 'showID', 'string');
const url = `${this.config.apiUrl}/shows/${showID}/last_episode`;
const response = yield (0, utils_1.fetch)(this.config.client, url);
return response;
});
}
}
exports.Shows = Shows;
//# sourceMappingURL=index.js.map