Comparing version 4.1.1 to 4.2.0
@@ -0,1 +1,22 @@ | ||
# Version 4.2.0 | ||
* Added the following fields: | ||
All types: | ||
* `ratings` (different than `rating`) | ||
* `awards` | ||
`Movie`: | ||
* `production` | ||
* `boxoffice` | ||
* `dvd` | ||
* `website` | ||
`Episode`: | ||
* `seriesid` | ||
* Migration to [ky](https://github.com/sindresorhus/ky) from [requests](https://github.com/request/request) | ||
* Migration to eslint from tslint | ||
* Prettifier | ||
# Version 4.1.0 | ||
@@ -2,0 +23,0 @@ |
@@ -18,2 +18,6 @@ import { OmdbEpisode, OmdbMovie, OmdbSearch, OmdbSearchResult, OmdbTvshow } from "./interfaces"; | ||
} | ||
export declare class Rating { | ||
source: string; | ||
value: string; | ||
} | ||
export declare class Movie { | ||
@@ -41,3 +45,9 @@ imdbid: string; | ||
name: string; | ||
protected _year_data: string; | ||
awards: string; | ||
website?: string; | ||
ratings: Rating[]; | ||
dvd?: Date; | ||
production?: string; | ||
boxoffice?: string; | ||
protected _yearData: string; | ||
constructor(obj: OmdbMovie); | ||
@@ -48,2 +58,3 @@ } | ||
episode: number; | ||
seriesid: string; | ||
constructor(obj: OmdbEpisode, season?: number); | ||
@@ -90,3 +101,3 @@ } | ||
search(req: SearchRequest, page?: number, opts?: MovieOpts): Promise<SearchResults>; | ||
private merge_opts; | ||
private mergeOpts; | ||
} |
134
lib/imdb.js
@@ -27,16 +27,23 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Client = exports.search = exports.get = exports.ImdbError = exports.SearchResults = exports.SearchResult = exports.TVShow = exports.Episode = exports.Movie = exports.Rating = void 0; | ||
var ky = require("ky-universal"); | ||
var url_1 = require("url"); | ||
var interfaces_1 = require("./interfaces"); | ||
var rp = require("request-promise-native"); | ||
var omdbapi = "https://www.omdbapi.com/"; | ||
var omdbapi = "https://www.omdbapi.com"; | ||
function reqtoqueryobj(req, apikey, page) { | ||
return { | ||
var r = new url_1.URLSearchParams({ | ||
apikey: apikey, | ||
page: page, | ||
s: req.name, | ||
page: String(page), | ||
r: "json", | ||
s: req.name, | ||
type: req.reqtype, | ||
y: req.year, | ||
}; | ||
}); | ||
if (req.year !== undefined) { | ||
r.append("y", String(req.year)); | ||
} | ||
if (req.reqtype !== undefined) { | ||
r.append("type", String(req.reqtype)); | ||
} | ||
return r; | ||
} | ||
var trans_table = { | ||
var transTable = { | ||
Genre: "genres", | ||
@@ -47,9 +54,16 @@ Language: "languages", | ||
}; | ||
var Rating = (function () { | ||
function Rating() { | ||
} | ||
return Rating; | ||
}()); | ||
exports.Rating = Rating; | ||
var Movie = (function () { | ||
function Movie(obj) { | ||
this.ratings = []; | ||
for (var _i = 0, _a = Object.getOwnPropertyNames(obj); _i < _a.length; _i++) { | ||
var attr = _a[_i]; | ||
if (attr === "Year") { | ||
this._year_data = obj[attr]; | ||
if (!obj[attr].match(/\d{4}[\-–](?:\d{4})?/)) { | ||
this._yearData = obj[attr]; | ||
if (!obj[attr].match(/\d{4}[-–](?:\d{4})?/)) { | ||
var val = parseInt(obj[attr], 10); | ||
@@ -71,10 +85,25 @@ if (isNaN(val)) { | ||
} | ||
else if (attr === "DVD") { | ||
var val = new Date(obj[attr]); | ||
if (isNaN(val.getTime())) { | ||
this.dvd = undefined; | ||
} | ||
else { | ||
this.dvd = val; | ||
} | ||
} | ||
else if (attr === "imdbRating") { | ||
var key = trans_table[attr]; | ||
var key = transTable[attr]; | ||
var val = parseFloat(obj[attr]); | ||
this[key] = isNaN(val) ? 0 : val; | ||
} | ||
else if (trans_table[attr] !== undefined) { | ||
this[trans_table[attr]] = obj[attr]; | ||
else if (transTable[attr] !== undefined) { | ||
this[transTable[attr]] = obj[attr]; | ||
} | ||
else if (attr === "Ratings") { | ||
for (var _b = 0, _c = obj[attr]; _b < _c.length; _b++) { | ||
var rating = _c[_b]; | ||
this.ratings.push({ source: rating.Source, value: rating.Value }); | ||
} | ||
} | ||
else { | ||
@@ -85,3 +114,3 @@ this[attr.toLowerCase()] = obj[attr]; | ||
this.name = this.title; | ||
this.series = this.type === "movie" ? false : true; | ||
this.series = this.type !== "movie"; | ||
this.imdburl = "https://www.imdb.com/title/" + this.imdbid; | ||
@@ -105,3 +134,3 @@ } | ||
} | ||
if (obj.hasOwnProperty("Episode")) { | ||
if (Object.prototype.hasOwnProperty.call(obj, "Episode")) { | ||
_this.episode = parseInt(obj.Episode, 10); | ||
@@ -122,3 +151,3 @@ if (isNaN(_this.episode)) { | ||
_this._episodes = []; | ||
var years = _this._year_data.split("-"); | ||
var years = _this._yearData.split("-"); | ||
_this.start_year = parseInt(years[0], 10); | ||
@@ -138,4 +167,3 @@ _this.end_year = parseInt(years[1], 10) ? parseInt(years[1], 10) : undefined; | ||
var reqopts = { | ||
json: true, | ||
qs: { | ||
searchParams: { | ||
Season: i, | ||
@@ -146,5 +174,6 @@ apikey: tvShow.opts.apiKey, | ||
}, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
timeout: undefined, | ||
url: omdbapi, | ||
withCredentials: false, | ||
}; | ||
@@ -154,9 +183,8 @@ if ("timeout" in this.opts) { | ||
} | ||
funcs.push(rp(reqopts)); | ||
funcs.push(ky(omdbapi, reqopts).json()); | ||
} | ||
var prom = Promise.all(funcs) | ||
.then(function (ep_data) { | ||
var prom = Promise.all(funcs).then(function (epData) { | ||
var eps = []; | ||
for (var _i = 0, ep_data_1 = ep_data; _i < ep_data_1.length; _i++) { | ||
var datum = ep_data_1[_i]; | ||
for (var _i = 0, epData_1 = epData; _i < epData_1.length; _i++) { | ||
var datum = epData_1[_i]; | ||
if (interfaces_1.isError(datum)) { | ||
@@ -246,3 +274,3 @@ throw new ImdbError(datum.Error); | ||
function Client(opts) { | ||
if (!opts.hasOwnProperty("apiKey")) { | ||
if (!Object.prototype.hasOwnProperty.call(opts, "apiKey")) { | ||
throw new ImdbError("Missing api key in opts"); | ||
@@ -253,16 +281,16 @@ } | ||
Client.prototype.get = function (req, opts) { | ||
opts = this.merge_opts(opts); | ||
var qs = { | ||
apikey: opts.apiKey, | ||
i: undefined, | ||
plot: req.short_plot ? "short" : "full", | ||
r: "json", | ||
t: undefined, | ||
y: req.year, | ||
}; | ||
opts = this.mergeOpts(opts); | ||
var qs = [ | ||
["apikey", opts.apiKey], | ||
["plot", req.short_plot ? "short" : "full"], | ||
["r", "json"], | ||
]; | ||
if (req.year !== undefined) { | ||
qs.push(["y", String(req.year)]); | ||
} | ||
if (req.name) { | ||
qs.t = req.name; | ||
qs.push(["t", req.name]); | ||
} | ||
else if (req.id) { | ||
qs.i = req.id; | ||
qs.push(["i", req.id]); | ||
} | ||
@@ -273,7 +301,7 @@ else { | ||
var reqopts = { | ||
json: true, | ||
qs: qs, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
searchParams: qs, | ||
timeout: undefined, | ||
url: omdbapi, | ||
withCredentials: false, | ||
}; | ||
@@ -283,3 +311,5 @@ if ("timeout" in opts) { | ||
} | ||
var prom = rp(reqopts).then(function (data) { | ||
var prom = ky(omdbapi, reqopts) | ||
.json() | ||
.then(function (data) { | ||
var ret; | ||
@@ -306,3 +336,3 @@ if (interfaces_1.isError(data)) { | ||
Client.prototype.search = function (req, page, opts) { | ||
opts = this.merge_opts(opts); | ||
opts = this.mergeOpts(opts); | ||
if (page === undefined) { | ||
@@ -312,7 +342,15 @@ page = 1; | ||
var qs = reqtoqueryobj(req, opts.apiKey, page); | ||
var reqopts = { qs: qs, url: omdbapi, json: true, timeout: undefined, withCredentials: false }; | ||
var reqopts = { | ||
searchParams: qs, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
timeout: undefined, | ||
}; | ||
if ("timeout" in opts) { | ||
reqopts.timeout = opts.timeout; | ||
} | ||
var prom = rp(reqopts).then(function (data) { | ||
var prom = ky(omdbapi, reqopts) | ||
.json() | ||
.then(function (data) { | ||
if (interfaces_1.isError(data)) { | ||
@@ -325,5 +363,5 @@ throw new ImdbError(data.Error + ": " + req.name); | ||
}; | ||
Client.prototype.merge_opts = function (opts) { | ||
Client.prototype.mergeOpts = function (opts) { | ||
if (opts !== undefined) { | ||
return Object.assign(__assign({}, this.opts), opts); | ||
return __assign(__assign({}, this.opts), opts); | ||
} | ||
@@ -330,0 +368,0 @@ return __assign({}, this.opts); |
@@ -0,1 +1,5 @@ | ||
export interface OmdbRating { | ||
Source: string; | ||
Value: string; | ||
} | ||
export interface OmdbMovie { | ||
@@ -20,2 +24,7 @@ Title: string; | ||
imdbID: string; | ||
Website?: string; | ||
Ratings?: OmdbRating[]; | ||
DVD?: string; | ||
BoxOffice?: string; | ||
Production?: string; | ||
Type: string; | ||
@@ -43,2 +52,3 @@ Response: string; | ||
imdbID: string; | ||
Ratings?: OmdbRating[]; | ||
Type: string; | ||
@@ -69,2 +79,3 @@ Response: string; | ||
Poster: string; | ||
Ratings?: OmdbRating[]; | ||
Metascore: string; | ||
@@ -71,0 +82,0 @@ Response: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEpisode = exports.isMovie = exports.isTvshow = exports.isError = void 0; | ||
function isError(response) { | ||
@@ -4,0 +5,0 @@ return response.Response === "False"; |
@@ -5,3 +5,3 @@ { | ||
"description": "Queries unofficial imdb APIs to get movie and television information from imdb", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"main": "./lib/imdb.js", | ||
@@ -18,5 +18,4 @@ "types": "./lib/imdb.d.ts", | ||
"prepare": "npm run build", | ||
"prepublish": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"lint": "tslint --project tsconfig.json", | ||
"format": "prettier --write --parser typescript src/*.ts test/*.ts", | ||
"lint": "eslint --ignore-path .gitignore --ext .ts . && prettier --check --parser typescript src/*.ts test/*.ts", | ||
"test": "nyc --reporter lcov mocha", | ||
@@ -29,16 +28,30 @@ "check": "npm run lint && npm run test", | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "^0.1.3", | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.7", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@types/chai": "^4.2.12", | ||
"@types/chai-as-promised": "^7.1.3", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^14.0.27", | ||
"@typescript-eslint/eslint-plugin": "^3.7.1", | ||
"@typescript-eslint/parser": "^3.7.1", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.5", | ||
"js-beautify": "^1.10.1", | ||
"mocha": "^6.2.0", | ||
"nock": "^10.0.6", | ||
"nyc": "^14.1.1", | ||
"source-map-support": "^0.5.13", | ||
"ts-node": "^8.3.0", | ||
"tslint": "^5.18.0", | ||
"typedoc": "^0.15.0", | ||
"typescript": "^3.5.3" | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.6.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-config-semistandard": "^15.0.1", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-plugin-import": "^2.22.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"js-beautify": "^1.11.0", | ||
"mocha": "^8.1.0", | ||
"nock": "^13.0.3", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.0.5", | ||
"source-map-support": "^0.5.19", | ||
"ts-node": "^8.10.2", | ||
"typedoc": "^0.17.8", | ||
"typescript": "^3.9.7" | ||
}, | ||
@@ -57,7 +70,14 @@ "optionalDependencies": {}, | ||
"dependencies": { | ||
"@types/request": "^2.48.2", | ||
"@types/request-promise-native": "^1.0.16", | ||
"request": "^2.88.0", | ||
"request-promise-native": "^1.0.7" | ||
"ky": "^0.23.0", | ||
"ky-universal": "^0.8.1" | ||
}, | ||
"mocha": { | ||
"require": [ | ||
"ts-node/register", | ||
"source-map-support/register" | ||
], | ||
"extension": [ | ||
"ts" | ||
] | ||
} | ||
} |
1002
src/imdb.ts
@@ -1,23 +0,21 @@ | ||
"use strict"; | ||
import * as ky from "ky-universal"; | ||
import { URLSearchParams } from "url"; | ||
import { | ||
isEpisode, | ||
isError, | ||
isMovie, | ||
isTvshow, | ||
OmdbEpisode, | ||
OmdbError, | ||
OmdbMovie, | ||
OmdbSearch, | ||
OmdbSearchResult, | ||
OmdbSeason, | ||
OmdbTvshow, | ||
isEpisode, | ||
isError, | ||
isMovie, | ||
isTvshow, | ||
OmdbEpisode, | ||
OmdbError, | ||
OmdbMovie, | ||
OmdbSearch, | ||
OmdbSearchResult, | ||
OmdbSeason, | ||
OmdbTvshow, | ||
} from "./interfaces"; | ||
import rp = require("request-promise-native"); | ||
/** | ||
* @hidden | ||
*/ | ||
const omdbapi = "https://www.omdbapi.com/"; | ||
const omdbapi = "https://www.omdbapi.com"; | ||
@@ -29,13 +27,13 @@ /** | ||
export interface MovieOpts { | ||
/** | ||
* API key for omdbapi. Needed to make any API calls. | ||
* | ||
* Get one [here](https://www.patreon.com/posts/api-is-going-10743518) | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* API key for omdbapi. Needed to make any API calls. | ||
* | ||
* Get one [here](https://www.patreon.com/posts/api-is-going-10743518) | ||
*/ | ||
apiKey?: string; | ||
/** | ||
* Timeout in milliseconds to wait before giving up on a request | ||
*/ | ||
timeout?: number; | ||
/** | ||
* Timeout in milliseconds to wait before giving up on a request | ||
*/ | ||
timeout?: number; | ||
} | ||
@@ -55,24 +53,24 @@ | ||
export interface MovieRequest { | ||
/** | ||
* Name of the movie | ||
* | ||
* Unfortunately, only English names are supported | ||
* by omdb at the moment. | ||
*/ | ||
name?: string; | ||
/** | ||
* Name of the movie | ||
* | ||
* Unfortunately, only English names are supported | ||
* by omdb at the moment. | ||
*/ | ||
name?: string; | ||
/** | ||
* imdb id of the movie | ||
*/ | ||
id?: string; | ||
/** | ||
* imdb id of the movie | ||
*/ | ||
id?: string; | ||
/** | ||
* Year that the movie was released | ||
*/ | ||
year?: number; | ||
/** | ||
* Year that the movie was released | ||
*/ | ||
year?: number; | ||
/** | ||
* Whether or not to request a short plot. Default is full plot. | ||
*/ | ||
short_plot?: boolean; | ||
/** | ||
* Whether or not to request a short plot. Default is full plot. | ||
*/ | ||
short_plot?: boolean; // eslint-disable-line camelcase | ||
} | ||
@@ -83,6 +81,3 @@ | ||
*/ | ||
export type RequestType = "movie" | ||
| "series" | ||
| "episode" | ||
| "game"; | ||
export type RequestType = "movie" | "series" | "episode" | "game"; | ||
@@ -94,17 +89,17 @@ /** | ||
export interface SearchRequest { | ||
/** | ||
* Title of the media that we're looking for. Unfortunately, only English | ||
* names are supported by omdb at the moment. | ||
*/ | ||
name: string; | ||
/** | ||
* Title of the media that we're looking for. Unfortunately, only English | ||
* names are supported by omdb at the moment. | ||
*/ | ||
name: string; | ||
/** | ||
* Type of media we're looking for | ||
*/ | ||
reqtype?: RequestType; | ||
/** | ||
* Type of media we're looking for | ||
*/ | ||
reqtype?: RequestType; | ||
/** | ||
* Year that the media was released | ||
*/ | ||
year?: number; | ||
/** | ||
* Year that the media was released | ||
*/ | ||
year?: number; | ||
} | ||
@@ -115,11 +110,23 @@ | ||
*/ | ||
function reqtoqueryobj(req: SearchRequest, apikey: string, page: number): object { | ||
return { | ||
apikey, | ||
page, | ||
r: "json", | ||
s: req.name, | ||
type: req.reqtype, | ||
y: req.year, | ||
}; | ||
function reqtoqueryobj( | ||
req: SearchRequest, | ||
apikey: string, | ||
page: number | ||
): URLSearchParams { | ||
const r = new URLSearchParams({ | ||
apikey, | ||
s: req.name, | ||
page: String(page), | ||
r: "json", | ||
}); | ||
if (req.year !== undefined) { | ||
r.append("y", String(req.year)); | ||
} | ||
if (req.reqtype !== undefined) { | ||
r.append("type", String(req.reqtype)); | ||
} | ||
return r; | ||
} | ||
@@ -130,10 +137,21 @@ | ||
*/ | ||
const trans_table = { | ||
Genre: "genres", | ||
Language: "languages", | ||
imdbRating: "rating", | ||
imdbVotes: "votes", | ||
const transTable = { | ||
Genre: "genres", | ||
Language: "languages", | ||
imdbRating: "rating", | ||
imdbVotes: "votes", | ||
}; | ||
/** | ||
* Rating for a piece of media. | ||
*/ | ||
export class Rating { | ||
/** Site where the rating came from */ | ||
public source: string; | ||
/** Rating that the media got from the @{link Rating.source} */ | ||
public value: string; | ||
} | ||
/** | ||
* A movie as returned by {@link get}, {@link search}, or any of the methods | ||
@@ -144,95 +162,145 @@ * from {@link Client}. This is not meant to be created directly by consumers of | ||
export class Movie { | ||
/** id of the movie on imdb */ | ||
public imdbid: string; | ||
/** direct URL to the movie on imdb */ | ||
public imdburl: string; | ||
/** the genres that this movie belongs to */ | ||
public genres: string; | ||
/** languages this movie was released in */ | ||
public languages: string; | ||
/** countries this movie was released in */ | ||
public country: string; | ||
/** votes received on imdb */ | ||
public votes: string; | ||
/** whether or not this is a TV series */ | ||
public series: boolean; | ||
/** the rating as it appears on imdb */ | ||
public rating: number; | ||
/** the runtime of the movie */ | ||
public runtime: string; | ||
/** the title of the movie in English */ | ||
public title: string; | ||
/** year the movie was released */ | ||
public year: number; | ||
/** id of the movie on imdb */ | ||
public imdbid: string; | ||
/** type of media (see {@link RequestType}) */ | ||
public type: string; | ||
/** link to the poster for this movie */ | ||
public poster: string; | ||
/** score from a bunch of different review sites */ | ||
public metascore: string; | ||
/** the plot (can either be long or short as specified in {@link MovieRequest}) */ | ||
public plot: string; | ||
/** what the movie was rated in its country of release */ | ||
public rated: string; | ||
/** the directors of the movie */ | ||
public director: string; | ||
/** writers of the movie */ | ||
public writer: string; | ||
/** leading actors that starred in the movie */ | ||
public actors: string; | ||
/** date that the movie was originally released */ | ||
public released?: Date; | ||
/** title of the movie */ | ||
public name: string; | ||
/** direct URL to the movie on imdb */ | ||
public imdburl: string; | ||
/** | ||
* @hidden | ||
*/ | ||
protected _year_data: string; | ||
/** the genres that this movie belongs to */ | ||
public genres: string; | ||
/** | ||
* This takes a result from omdb, and transforms it into an | ||
* object consumable by customers of imdb-api. | ||
* | ||
* This isn't meant for direct consumption by API consumers, | ||
* and consumers should look at {@link get}, {@link search} or | ||
* any of the methods on {@link Client} to get a movie instead. | ||
* | ||
* @param obj Results from omdb | ||
*/ | ||
constructor(obj: OmdbMovie) { | ||
for (const attr of Object.getOwnPropertyNames(obj)) { | ||
if (attr === "Year") { | ||
this._year_data = obj[attr]; | ||
// check for emdash as well | ||
if (!obj[attr].match(/\d{4}[\-–](?:\d{4})?/)) { | ||
const val = parseInt(obj[attr], 10); | ||
if (isNaN(val)) { | ||
throw new TypeError("invalid year"); | ||
} | ||
this[attr.toLowerCase()] = val; | ||
} | ||
} else if (attr === "Released") { | ||
const val = new Date(obj[attr]); | ||
if (isNaN(val.getTime())) { | ||
this.released = undefined; | ||
} else { | ||
this.released = val; | ||
} | ||
} else if (attr === "imdbRating") { | ||
const key = trans_table[attr]; | ||
const val = parseFloat(obj[attr]); | ||
this[key] = isNaN(val) ? 0 : val; | ||
} else if (trans_table[attr] !== undefined) { | ||
this[trans_table[attr]] = obj[attr]; | ||
} else { | ||
this[attr.toLowerCase()] = obj[attr]; | ||
} | ||
/** languages this movie was released in */ | ||
public languages: string; | ||
/** countries this movie was released in */ | ||
public country: string; | ||
/** votes received on imdb */ | ||
public votes: string; | ||
/** whether or not this is a TV series */ | ||
public series: boolean; | ||
/** the rating as it appears on imdb */ | ||
public rating: number; | ||
/** the runtime of the movie */ | ||
public runtime: string; | ||
/** the title of the movie in English */ | ||
public title: string; | ||
/** year the movie was released */ | ||
public year: number; | ||
/** type of media (see {@link RequestType}) */ | ||
public type: string; | ||
/** link to the poster for this movie */ | ||
public poster: string; | ||
/** score from a bunch of different review sites */ | ||
public metascore: string; | ||
/** the plot (can either be long or short as specified in {@link MovieRequest}) */ | ||
public plot: string; | ||
/** what the movie was rated in its country of release */ | ||
public rated: string; | ||
/** the directors of the movie */ | ||
public director: string; | ||
/** writers of the movie */ | ||
public writer: string; | ||
/** leading actors that starred in the movie */ | ||
public actors: string; | ||
/** date that the movie was originally released */ | ||
public released?: Date; | ||
/** title of the movie */ | ||
public name: string; | ||
/** awards won */ | ||
public awards: string; | ||
/** website for the movie */ | ||
public website?: string; | ||
/** ratings for the media from various sources */ | ||
public ratings: Rating[]; | ||
/** date of the DVD release */ | ||
public dvd?: Date; | ||
/** Production studio */ | ||
public production?: string; | ||
/** Box office earnings */ | ||
public boxoffice?: string; | ||
/** | ||
* @hidden | ||
*/ | ||
protected _yearData: string; | ||
/** | ||
* This takes a result from omdb, and transforms it into an | ||
* object consumable by customers of imdb-api. | ||
* | ||
* This isn't meant for direct consumption by API consumers, | ||
* and consumers should look at {@link get}, {@link search} or | ||
* any of the methods on {@link Client} to get a movie instead. | ||
* | ||
* @param obj Results from omdb | ||
*/ | ||
constructor(obj: OmdbMovie) { | ||
this.ratings = []; | ||
for (const attr of Object.getOwnPropertyNames(obj)) { | ||
if (attr === "Year") { | ||
this._yearData = obj[attr]; | ||
// check for emdash as well | ||
if (!obj[attr].match(/\d{4}[-–](?:\d{4})?/)) { | ||
const val = parseInt(obj[attr], 10); | ||
if (isNaN(val)) { | ||
throw new TypeError("invalid year"); | ||
} | ||
this[attr.toLowerCase()] = val; | ||
} | ||
} else if (attr === "Released") { | ||
const val = new Date(obj[attr]); | ||
if (isNaN(val.getTime())) { | ||
this.released = undefined; | ||
} else { | ||
this.released = val; | ||
} | ||
} else if (attr === "DVD") { | ||
const val = new Date(obj[attr]); | ||
if (isNaN(val.getTime())) { | ||
this.dvd = undefined; | ||
} else { | ||
this.dvd = val; | ||
} | ||
} else if (attr === "imdbRating") { | ||
const key = transTable[attr]; | ||
const val = parseFloat(obj[attr]); | ||
this[key] = isNaN(val) ? 0 : val; | ||
} else if (transTable[attr] !== undefined) { | ||
this[transTable[attr]] = obj[attr]; | ||
} else if (attr === "Ratings") { | ||
for (const rating of obj[attr]) { | ||
this.ratings.push({ source: rating.Source, value: rating.Value }); | ||
} | ||
} else { | ||
this[attr.toLowerCase()] = obj[attr]; | ||
} | ||
} | ||
this.name = this.title; | ||
this.series = this.type === "movie" ? false : true; | ||
this.imdburl = "https://www.imdb.com/title/" + this.imdbid; | ||
} | ||
this.name = this.title; | ||
this.series = this.type !== "movie"; | ||
this.imdburl = `https://www.imdb.com/title/${this.imdbid}`; | ||
} | ||
} | ||
@@ -245,35 +313,39 @@ | ||
export class Episode extends Movie { | ||
/** what season this episode is a part of */ | ||
public season: number; | ||
/** what number episode in the season this episode is */ | ||
public episode: number; | ||
/** what season this episode is a part of */ | ||
public season: number; | ||
/** | ||
* Creates an epsiode from results from omdb. This is not intended for consumer use. | ||
* Please prefer {@link TVShow.epsiodes}. | ||
* | ||
* @param obj Episodes fetched from omdb | ||
* @param season Which season this episode belongs to | ||
* | ||
* @throws TypeError when the episode number is invalid | ||
*/ | ||
constructor(obj: OmdbEpisode, season?: number) { | ||
super(obj); | ||
/** what number episode in the season this episode is */ | ||
public episode: number; | ||
if (season !== undefined) { | ||
this.season = season; | ||
} else { | ||
this.season = parseInt(obj.Season, 10); | ||
if (isNaN(this.season)) { | ||
throw new TypeError("invalid season"); | ||
} | ||
} | ||
/** what series this episode is a part of (imdbid) */ | ||
public seriesid: string; | ||
if (obj.hasOwnProperty("Episode")) { | ||
this.episode = parseInt(obj.Episode, 10); | ||
if (isNaN(this.episode)) { | ||
throw new TypeError("invalid episode"); | ||
} | ||
} | ||
/** | ||
* Creates an epsiode from results from omdb. This is not intended for consumer use. | ||
* Please prefer {@link TVShow.epsiodes}. | ||
* | ||
* @param obj Episodes fetched from omdb | ||
* @param season Which season this episode belongs to | ||
* | ||
* @throws TypeError when the episode number is invalid | ||
*/ | ||
constructor(obj: OmdbEpisode, season?: number) { | ||
super(obj); | ||
if (season !== undefined) { | ||
this.season = season; | ||
} else { | ||
this.season = parseInt(obj.Season, 10); | ||
if (isNaN(this.season)) { | ||
throw new TypeError("invalid season"); | ||
} | ||
} | ||
if (Object.prototype.hasOwnProperty.call(obj, "Episode")) { | ||
this.episode = parseInt(obj.Episode, 10); | ||
if (isNaN(this.episode)) { | ||
throw new TypeError("invalid episode"); | ||
} | ||
} | ||
} | ||
} | ||
@@ -287,93 +359,96 @@ | ||
export class TVShow extends Movie { | ||
/** year this show started */ | ||
public start_year: number; | ||
/** year this show ended if it's ended */ | ||
public end_year?: number; | ||
/** how many seasons this show ran */ | ||
public totalseasons: number; | ||
/** year this show started */ | ||
public start_year: number; // eslint-disable-line camelcase | ||
/** | ||
* @hidden | ||
*/ | ||
private _episodes: Episode[] = []; | ||
/** year this show ended if it's ended */ | ||
public end_year?: number; // eslint-disable-line camelcase | ||
/** | ||
* @hidden | ||
*/ | ||
private opts: MovieOpts; | ||
/** how many seasons this show ran */ | ||
public totalseasons: number; | ||
/** | ||
* Creates a new {@link TVShow} from omdb results. This isn't intended to be | ||
* used by consumers of this library, instead see {@link get}, {@link search} | ||
* or any methods from {@link Client}. | ||
* | ||
* @param obj The tv show info we got from omdb | ||
* @param opts Options that we used to fetch this TVShow, so we can use | ||
* them to fetch episodes | ||
*/ | ||
constructor(obj: OmdbTvshow, opts: MovieOpts) { | ||
super(obj); | ||
const years = this._year_data.split("-"); | ||
this.start_year = parseInt(years[0], 10); | ||
this.end_year = parseInt(years[1], 10) ? parseInt(years[1], 10) : undefined; | ||
this.totalseasons = parseInt(obj.totalSeasons, 10); | ||
this.opts = opts; | ||
/** | ||
* @hidden | ||
*/ | ||
private _episodes: Episode[] = []; | ||
/** | ||
* @hidden | ||
*/ | ||
private opts: MovieOpts; | ||
/** | ||
* Creates a new {@link TVShow} from omdb results. This isn't intended to be | ||
* used by consumers of this library, instead see {@link get}, {@link search} | ||
* or any methods from {@link Client}. | ||
* | ||
* @param obj The tv show info we got from omdb | ||
* @param opts Options that we used to fetch this TVShow, so we can use | ||
* them to fetch episodes | ||
*/ | ||
constructor(obj: OmdbTvshow, opts: MovieOpts) { | ||
super(obj); | ||
const years = this._yearData.split("-"); | ||
this.start_year = parseInt(years[0], 10); | ||
this.end_year = parseInt(years[1], 10) ? parseInt(years[1], 10) : undefined; | ||
this.totalseasons = parseInt(obj.totalSeasons, 10); | ||
this.opts = opts; | ||
} | ||
/** | ||
* Fetches episodes of a TV show | ||
* | ||
* @return Promise yielding list of episodes | ||
*/ | ||
public episodes(): Promise<Episode[]> { | ||
if (this._episodes.length !== 0) { | ||
return Promise.resolve(this._episodes); | ||
} | ||
/** | ||
* Fetches episodes of a TV show | ||
* | ||
* @return Promise yielding list of episodes | ||
*/ | ||
public episodes(): Promise<Episode[]> { | ||
if (this._episodes.length !== 0) { | ||
return Promise.resolve(this._episodes); | ||
} | ||
const tvShow = this; | ||
const tvShow = this; | ||
const funcs = []; | ||
for (let i = 1; i <= tvShow.totalseasons; i++) { | ||
const reqopts = { | ||
searchParams: { | ||
Season: i, | ||
apikey: tvShow.opts.apiKey, | ||
i: tvShow.imdbid, | ||
r: "json", | ||
}, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
timeout: undefined, | ||
}; | ||
const funcs = []; | ||
for (let i = 1; i <= tvShow.totalseasons; i++) { | ||
const reqopts = { | ||
json: true, | ||
qs: { | ||
Season: i, | ||
apikey: tvShow.opts.apiKey, | ||
i: tvShow.imdbid, | ||
r: "json", | ||
}, | ||
timeout: undefined, | ||
url: omdbapi, | ||
withCredentials: false, | ||
}; | ||
if ("timeout" in this.opts) { | ||
reqopts.timeout = this.opts.timeout; | ||
} | ||
if ("timeout" in this.opts) { | ||
reqopts.timeout = this.opts.timeout; | ||
} | ||
funcs.push(ky(omdbapi, reqopts).json()); | ||
} | ||
funcs.push(rp(reqopts)); | ||
} | ||
const prom = Promise.all(funcs).then( | ||
(epData: OmdbSeason[] | OmdbError[]) => { | ||
const eps: Episode[] = []; | ||
const prom = Promise.all(funcs) | ||
.then((ep_data: OmdbSeason[] | OmdbError[]) => { | ||
const eps: Episode[] = []; | ||
for (const datum of epData) { | ||
if (isError(datum)) { | ||
throw new ImdbError(datum.Error); | ||
} | ||
for (const datum of ep_data) { | ||
if (isError(datum)) { | ||
throw new ImdbError(datum.Error); | ||
} | ||
const season = parseInt(datum.Season, 10); | ||
for (const ep of Object.getOwnPropertyNames(datum.Episodes)) { | ||
eps.push(new Episode(datum.Episodes[ep], season)); | ||
} | ||
} | ||
const season = parseInt(datum.Season, 10); | ||
for (const ep of Object.getOwnPropertyNames(datum.Episodes)) { | ||
eps.push(new Episode(datum.Episodes[ep], season)); | ||
} | ||
} | ||
tvShow._episodes = eps; | ||
tvShow._episodes = eps; | ||
return Promise.resolve(eps); | ||
} | ||
); | ||
return Promise.resolve(eps); | ||
}); | ||
return prom; | ||
} | ||
return prom; | ||
} | ||
} | ||
@@ -386,26 +461,31 @@ | ||
export class SearchResult { | ||
/** name of the movie */ | ||
public title: string; | ||
/** name of the movie */ | ||
public name: string; | ||
/** year the movie was released */ | ||
public year: number; | ||
/** imdb id of the movie */ | ||
public imdbid: string; | ||
/** type of media we found */ | ||
public type: RequestType; | ||
/** link to the poster for this movie */ | ||
public poster: string; | ||
/** name of the movie */ | ||
public title: string; | ||
constructor(obj: OmdbSearchResult) { | ||
for (const attr of Object.getOwnPropertyNames(obj)) { | ||
if (attr === "Year") { | ||
this[attr.toLowerCase()] = parseInt(obj[attr], 10); | ||
} else { | ||
this[attr.toLowerCase()] = obj[attr]; | ||
} | ||
} | ||
/** name of the movie */ | ||
public name: string; | ||
this.name = this.title; | ||
/** year the movie was released */ | ||
public year: number; | ||
/** imdb id of the movie */ | ||
public imdbid: string; | ||
/** type of media we found */ | ||
public type: RequestType; | ||
/** link to the poster for this movie */ | ||
public poster: string; | ||
constructor(obj: OmdbSearchResult) { | ||
for (const attr of Object.getOwnPropertyNames(obj)) { | ||
if (attr === "Year") { | ||
this[attr.toLowerCase()] = parseInt(obj[attr], 10); | ||
} else { | ||
this[attr.toLowerCase()] = obj[attr]; | ||
} | ||
} | ||
this.name = this.title; | ||
} | ||
} | ||
@@ -419,61 +499,67 @@ | ||
export class SearchResults { | ||
public results: SearchResult[] = []; | ||
public totalresults: number; | ||
public results: SearchResult[] = []; | ||
/** | ||
* @hidden | ||
*/ | ||
private page: number; | ||
public totalresults: number; | ||
/** | ||
* @hidden | ||
*/ | ||
private opts: MovieOpts; | ||
/** | ||
* @hidden | ||
*/ | ||
private page: number; | ||
/** | ||
* @hidden | ||
*/ | ||
private req: SearchRequest; | ||
/** | ||
* @hidden | ||
*/ | ||
private opts: MovieOpts; | ||
/** | ||
* Builds a new {@link SearchResults}. Not intended to be called directly by | ||
* API consumers, as it only creates the object from omdb results. | ||
* | ||
* @param obj Search results from omdb | ||
* @param page Page number we're fetching | ||
* @param opts Stored options from our initial request | ||
* @param req A reference to the original request | ||
*/ | ||
constructor(obj: OmdbSearch, page: number, opts: MovieOpts, req: SearchRequest) { | ||
this.page = page; | ||
this.req = req; | ||
this.opts = opts; | ||
/** | ||
* @hidden | ||
*/ | ||
private req: SearchRequest; | ||
for (const attr of Object.getOwnPropertyNames(obj)) { | ||
if (attr === "Search") { | ||
for (const result of obj.Search) { | ||
this.results.push(new SearchResult(result)); | ||
} | ||
} else if (attr === "totalResults") { | ||
this[attr.toLowerCase()] = parseInt(obj[attr], 10); | ||
} else { | ||
this[attr.toLowerCase()] = obj[attr]; | ||
} | ||
/** | ||
* Builds a new {@link SearchResults}. Not intended to be called directly by | ||
* API consumers, as it only creates the object from omdb results. | ||
* | ||
* @param obj Search results from omdb | ||
* @param page Page number we're fetching | ||
* @param opts Stored options from our initial request | ||
* @param req A reference to the original request | ||
*/ | ||
constructor( | ||
obj: OmdbSearch, | ||
page: number, | ||
opts: MovieOpts, | ||
req: SearchRequest | ||
) { | ||
this.page = page; | ||
this.req = req; | ||
this.opts = opts; | ||
for (const attr of Object.getOwnPropertyNames(obj)) { | ||
if (attr === "Search") { | ||
for (const result of obj.Search) { | ||
this.results.push(new SearchResult(result)); | ||
} | ||
} else if (attr === "totalResults") { | ||
this[attr.toLowerCase()] = parseInt(obj[attr], 10); | ||
} else { | ||
this[attr.toLowerCase()] = obj[attr]; | ||
} | ||
} | ||
} | ||
/** | ||
* Returns the next page of search results | ||
* | ||
* @return next page of search results | ||
*/ | ||
public next(): Promise<SearchResults> { | ||
return search(this.req, this.opts, this.page + 1); | ||
} | ||
/** | ||
* Returns the next page of search results | ||
* | ||
* @return next page of search results | ||
*/ | ||
public next(): Promise<SearchResults> { | ||
return search(this.req, this.opts, this.page + 1); | ||
} | ||
} | ||
export class ImdbError { | ||
public name: string = "imdb api error"; | ||
public name = "imdb api error"; | ||
constructor(public message: string) { } | ||
constructor(public message: string) {} | ||
} | ||
@@ -490,7 +576,7 @@ | ||
export function get(req: MovieRequest, opts: MovieOpts): Promise<Movie> { | ||
try { | ||
return new Client(opts).get(req); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
try { | ||
return new Client(opts).get(req); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
@@ -507,4 +593,8 @@ | ||
*/ | ||
export function search(req: SearchRequest, opts: MovieOpts, page?: number): Promise<SearchResults> { | ||
return new Client(opts).search(req, page); | ||
export function search( | ||
req: SearchRequest, | ||
opts: MovieOpts, | ||
page?: number | ||
): Promise<SearchResults> { | ||
return new Client(opts).search(req, page); | ||
} | ||
@@ -538,126 +628,142 @@ | ||
export class Client { | ||
/** | ||
* @hidden | ||
*/ | ||
private opts: MovieOpts; | ||
/** | ||
* @hidden | ||
*/ | ||
private opts: MovieOpts; | ||
/** | ||
* Creates a new {@link Client} object. | ||
* | ||
* @param opts A set of {@link MovieOpts} that will be applied to all | ||
* requests made by this object unless overridden. | ||
* | ||
* @throws {@link ImdbError} if an invalid {@link MovieOpts} is passed | ||
*/ | ||
constructor(opts: MovieOpts) { | ||
if (!opts.hasOwnProperty("apiKey")) { | ||
throw new ImdbError("Missing api key in opts"); | ||
} | ||
this.opts = opts; | ||
/** | ||
* Creates a new {@link Client} object. | ||
* | ||
* @param opts A set of {@link MovieOpts} that will be applied to all | ||
* requests made by this object unless overridden. | ||
* | ||
* @throws {@link ImdbError} if an invalid {@link MovieOpts} is passed | ||
*/ | ||
constructor(opts: MovieOpts) { | ||
if (!Object.prototype.hasOwnProperty.call(opts, "apiKey")) { | ||
throw new ImdbError("Missing api key in opts"); | ||
} | ||
this.opts = opts; | ||
} | ||
/** | ||
* Fetches a single movie by arbitrary criteria | ||
* | ||
* @param req set of requirements to search for | ||
* @param opts options that override the {@link Client}'s options | ||
* | ||
* @return a promise yielding a movie | ||
*/ | ||
public get(req: MovieRequest, opts?: MovieOpts): Promise<Movie> { | ||
opts = this.merge_opts(opts); | ||
/** | ||
* Fetches a single movie by arbitrary criteria | ||
* | ||
* @param req set of requirements to search for | ||
* @param opts options that override the {@link Client}'s options | ||
* | ||
* @return a promise yielding a movie | ||
*/ | ||
public get(req: MovieRequest, opts?: MovieOpts): Promise<Movie> { | ||
opts = this.mergeOpts(opts); | ||
const qs = { | ||
apikey: opts.apiKey, | ||
i: undefined, | ||
plot: req.short_plot ? "short" : "full", | ||
r: "json", | ||
t: undefined, | ||
y: req.year, | ||
}; | ||
const qs = [ | ||
["apikey", opts.apiKey], | ||
["plot", req.short_plot ? "short" : "full"], | ||
["r", "json"], | ||
]; | ||
if (req.name) { | ||
qs.t = req.name; | ||
} else if (req.id) { | ||
qs.i = req.id; | ||
} else { | ||
return Promise.reject(new ImdbError("Missing one of req.id or req.name")); | ||
} | ||
if (req.year !== undefined) { | ||
qs.push(["y", String(req.year)]); | ||
} | ||
const reqopts = { | ||
json: true, | ||
qs, | ||
timeout: undefined, | ||
url: omdbapi, | ||
withCredentials: false, | ||
}; | ||
if (req.name) { | ||
qs.push(["t", req.name]); | ||
} else if (req.id) { | ||
qs.push(["i", req.id]); | ||
} else { | ||
return Promise.reject(new ImdbError("Missing one of req.id or req.name")); | ||
} | ||
if ("timeout" in opts) { | ||
reqopts.timeout = opts.timeout; | ||
const reqopts = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
searchParams: qs, | ||
timeout: undefined, | ||
}; | ||
if ("timeout" in opts) { | ||
reqopts.timeout = opts.timeout; | ||
} | ||
const prom = ky(omdbapi, reqopts) | ||
.json() | ||
.then((data: OmdbMovie | OmdbError) => { | ||
let ret: Movie | Episode; | ||
if (isError(data)) { | ||
throw new ImdbError(`${data.Error}: ${req.name ? req.name : req.id}`); | ||
} | ||
const prom = rp(reqopts).then((data: OmdbMovie | OmdbError) => { | ||
let ret: Movie | Episode; | ||
if (isError(data)) { | ||
throw new ImdbError(`${data.Error}: ${(req.name ? req.name : req.id)}`); | ||
} | ||
if (isMovie(data)) { | ||
ret = new Movie(data); | ||
} else if (isTvshow(data)) { | ||
ret = new TVShow(data, opts); | ||
} else if (isEpisode(data)) { | ||
ret = new Episode(data); | ||
} else { | ||
throw new ImdbError(`type: '${data.Type}' is not valid`); | ||
} | ||
if (isMovie(data)) { | ||
ret = new Movie(data); | ||
} else if (isTvshow(data)) { | ||
ret = new TVShow(data, opts); | ||
} else if (isEpisode(data)) { | ||
ret = new Episode(data); | ||
} else { | ||
throw new ImdbError(`type: '${data.Type}' is not valid`); | ||
} | ||
return Promise.resolve(ret); | ||
}); | ||
return Promise.resolve(ret); | ||
}); | ||
return prom; | ||
} | ||
return prom; | ||
/** | ||
* Searches for a movie by arbitrary criteria | ||
* | ||
* @param req set of requirements to search for | ||
* @param opts options that override the {@link Client}'s options | ||
* @param page page number to return | ||
* | ||
* @return a promise yielding search results | ||
*/ | ||
public search( | ||
req: SearchRequest, | ||
page?: number, | ||
opts?: MovieOpts | ||
): Promise<SearchResults> { | ||
opts = this.mergeOpts(opts); | ||
if (page === undefined) { | ||
page = 1; | ||
} | ||
/** | ||
* Searches for a movie by arbitrary criteria | ||
* | ||
* @param req set of requirements to search for | ||
* @param opts options that override the {@link Client}'s options | ||
* @param page page number to return | ||
* | ||
* @return a promise yielding search results | ||
*/ | ||
public search(req: SearchRequest, page?: number, opts?: MovieOpts): Promise<SearchResults> { | ||
opts = this.merge_opts(opts); | ||
if (page === undefined) { | ||
page = 1; | ||
} | ||
const qs = reqtoqueryobj(req, opts.apiKey, page); | ||
const reqopts = { | ||
searchParams: qs, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
timeout: undefined, | ||
}; | ||
const qs = reqtoqueryobj(req, opts.apiKey, page); | ||
const reqopts = { qs, url: omdbapi, json: true, timeout: undefined, withCredentials: false }; | ||
if ("timeout" in opts) { | ||
reqopts.timeout = opts.timeout; | ||
if ("timeout" in opts) { | ||
reqopts.timeout = opts.timeout; | ||
} | ||
const prom = ky(omdbapi, reqopts) | ||
.json() | ||
.then((data: OmdbSearch | OmdbError) => { | ||
if (isError(data)) { | ||
throw new ImdbError(`${data.Error}: ${req.name}`); | ||
} | ||
const prom = rp(reqopts).then((data: OmdbSearch | OmdbError) => { | ||
if (isError(data)) { | ||
throw new ImdbError(`${data.Error}: ${req.name}`); | ||
} | ||
return Promise.resolve(new SearchResults(data, page, opts, req)); | ||
}); | ||
return Promise.resolve(new SearchResults(data, page, opts, req)); | ||
}); | ||
return prom; | ||
} | ||
return prom; | ||
/** | ||
* @hidden | ||
*/ | ||
private mergeOpts(opts?: MovieOpts): MovieOpts { | ||
if (opts !== undefined) { | ||
return { ...this.opts, ...opts }; | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
private merge_opts(opts?: MovieOpts): MovieOpts { | ||
if (opts !== undefined) { | ||
return Object.assign({ ...this.opts }, opts); | ||
} | ||
return { ...this.opts }; | ||
} | ||
return { ...this.opts }; | ||
} | ||
} |
@@ -0,115 +1,135 @@ | ||
export interface OmdbRating { | ||
Source: string; | ||
Value: string; | ||
} | ||
export interface OmdbMovie { | ||
Title: string; | ||
Year: string; | ||
Rated: string; | ||
Released: string; | ||
Runtime: string; | ||
Genre: string; | ||
Director: string; | ||
Writer: string; | ||
Actors: string; | ||
Plot: string; | ||
Language: string; | ||
Country: string; | ||
Awards: string; | ||
Poster: string; | ||
Metascore: string; | ||
imdbRating: string; | ||
imdbVotes: string; | ||
imdbID: string; | ||
Type: string; | ||
Response: string; | ||
Title: string; | ||
Year: string; | ||
Rated: string; | ||
Released: string; | ||
Runtime: string; | ||
Genre: string; | ||
Director: string; | ||
Writer: string; | ||
Actors: string; | ||
Plot: string; | ||
Language: string; | ||
Country: string; | ||
Awards: string; | ||
Poster: string; | ||
Metascore: string; | ||
imdbRating: string; | ||
imdbVotes: string; | ||
imdbID: string; | ||
Website?: string; | ||
Ratings?: OmdbRating[]; | ||
DVD?: string; | ||
BoxOffice?: string; | ||
Production?: string; | ||
Type: string; | ||
Response: string; | ||
} | ||
export interface OmdbTvshow { | ||
Title: string; | ||
Year: string; | ||
Rated: string; | ||
Released: string; | ||
Runtime: string; | ||
Genre: string; | ||
Director: string; | ||
Writer: string; | ||
Actors: string; | ||
Plot: string; | ||
Language: string; | ||
Country: string; | ||
Awards: string; | ||
Poster: string; | ||
Metascore: string; | ||
imdbRating: string; | ||
imdbVotes: string; | ||
imdbID: string; | ||
Type: string; | ||
Response: string; | ||
Title: string; | ||
Year: string; | ||
Rated: string; | ||
Released: string; | ||
Runtime: string; | ||
Genre: string; | ||
Director: string; | ||
Writer: string; | ||
Actors: string; | ||
Plot: string; | ||
Language: string; | ||
Country: string; | ||
Awards: string; | ||
Poster: string; | ||
Metascore: string; | ||
imdbRating: string; | ||
imdbVotes: string; | ||
imdbID: string; | ||
Ratings?: OmdbRating[]; | ||
Type: string; | ||
Response: string; | ||
totalSeasons: string; | ||
totalSeasons: string; | ||
} | ||
export interface OmdbEpisode { | ||
Title: string; | ||
Released: string; | ||
Season: string; | ||
Episode: string; | ||
Type: string; | ||
imdbRating: string; | ||
imdbID: string; | ||
imdbVotes: string; | ||
Year: string; | ||
Rated: string; | ||
Runtime: string; | ||
Genre: string; | ||
Director: string; | ||
Writer: string; | ||
Actors: string; | ||
Plot: string; | ||
Language: string; | ||
Country: string; | ||
Awards: string; | ||
Poster: string; | ||
Metascore: string; | ||
Response: string; | ||
Title: string; | ||
Released: string; | ||
Season: string; | ||
Episode: string; | ||
Type: string; | ||
imdbRating: string; | ||
imdbID: string; | ||
imdbVotes: string; | ||
Year: string; | ||
Rated: string; | ||
Runtime: string; | ||
Genre: string; | ||
Director: string; | ||
Writer: string; | ||
Actors: string; | ||
Plot: string; | ||
Language: string; | ||
Country: string; | ||
Awards: string; | ||
Poster: string; | ||
Ratings?: OmdbRating[]; | ||
Metascore: string; | ||
Response: string; | ||
} | ||
export interface OmdbSeason { | ||
Title: string; | ||
Season: string; | ||
totalEpisodes: string; | ||
Episodes: OmdbEpisode[]; | ||
Response: string; | ||
Title: string; | ||
Season: string; | ||
totalEpisodes: string; | ||
Episodes: OmdbEpisode[]; | ||
Response: string; | ||
} | ||
export interface OmdbSearchResult { | ||
Title: string; | ||
Year: string; | ||
imdbID: string; | ||
Type: string; | ||
Poster: string; | ||
Title: string; | ||
Year: string; | ||
imdbID: string; | ||
Type: string; | ||
Poster: string; | ||
} | ||
export interface OmdbSearch { | ||
Search: OmdbSearchResult[]; | ||
totalResults: string; | ||
Response: string; | ||
Search: OmdbSearchResult[]; | ||
totalResults: string; | ||
Response: string; | ||
} | ||
export interface OmdbError { | ||
Response: string; | ||
Error: string; | ||
Response: string; | ||
Error: string; | ||
} | ||
export function isError(response: OmdbSearch | OmdbSeason | OmdbTvshow | OmdbMovie | OmdbError): response is OmdbError { | ||
return response.Response === "False"; | ||
export function isError( | ||
response: OmdbSearch | OmdbSeason | OmdbTvshow | OmdbMovie | OmdbError | ||
): response is OmdbError { | ||
return response.Response === "False"; | ||
} | ||
export function isTvshow(response: OmdbMovie | OmdbTvshow | OmdbEpisode): response is OmdbTvshow { | ||
return response.Type === "series"; | ||
export function isTvshow( | ||
response: OmdbMovie | OmdbTvshow | OmdbEpisode | ||
): response is OmdbTvshow { | ||
return response.Type === "series"; | ||
} | ||
export function isMovie(response: OmdbMovie | OmdbTvshow | OmdbEpisode): response is OmdbTvshow { | ||
return response.Type === "movie"; | ||
export function isMovie( | ||
response: OmdbMovie | OmdbTvshow | OmdbEpisode | ||
): response is OmdbTvshow { | ||
return response.Type === "movie"; | ||
} | ||
export function isEpisode(response: OmdbMovie | OmdbTvshow | OmdbEpisode): response is OmdbEpisode { | ||
return response.Type === "episode"; | ||
export function isEpisode( | ||
response: OmdbMovie | OmdbTvshow | OmdbEpisode | ||
): response is OmdbEpisode { | ||
return response.Type === "episode"; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
59076
28
12
1361
+ Addedky@^0.23.0
+ Addedky-universal@^0.8.1
+ Addedabort-controller@3.0.0(transitive)
+ Addeddata-uri-to-buffer@3.0.1(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedfetch-blob@2.1.2(transitive)
+ Addedky@0.23.0(transitive)
+ Addedky-universal@0.8.2(transitive)
+ Addednode-fetch@3.0.0-beta.9(transitive)
- Removed@types/request@^2.48.2
- Removedrequest@^2.88.0
- Removedrequest-promise-native@^1.0.7
- Removed@types/caseless@0.12.5(transitive)
- Removed@types/node@22.9.3(transitive)
- Removed@types/request@2.48.12(transitive)
- Removed@types/request-promise-native@1.0.21(transitive)
- Removed@types/tough-cookie@4.0.5(transitive)
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.32.5.2(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.13.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise-core@1.1.4(transitive)
- Removedrequest-promise-native@1.0.9(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstealthy-require@1.1.1(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removedundici-types@6.19.8(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)