From 28747844d46f40294b58099d40e42a529a38de14 Mon Sep 17 00:00:00 2001 From: William Orr Date: Mon, 29 Jun 2020 22:26:15 +0200 Subject: [PATCH] Fix broken season number in episode (Fixes #73, #74) Apparently, omdb did not specify the Season number in an Episode object. Checking more recent data, it looks like it does. Now that we have it, we can rely on it rather than forcing the constructor to take an episode number. --- src/imdb.ts | 16 +++++++++++++--- src/interfaces.ts | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/imdb.ts b/src/imdb.ts index 6f9b003..975bb27 100644 --- a/src/imdb.ts +++ b/src/imdb.ts @@ -249,9 +249,19 @@ export class Episode extends Movie { * * @throws TypeError when the episode number is invalid */ - constructor(obj: OmdbEpisode, season: number) { + constructor(obj: OmdbEpisode, season?: number) { super(obj); - this.season = season; + + + if (season !== undefined) { + this.season = season + } else { + this.season = parseInt(obj.Season, 10); + if (isNaN(this.season)) { + throw new TypeError("invalid season"); + } + } + if (obj.hasOwnProperty("Episode")) { this.episode = parseInt(obj.Episode, 10); if (isNaN(this.episode)) { @@ -584,7 +594,7 @@ export class Client { } else if (isTvshow(data)) { ret = new TVShow(data, opts); } else if (isEpisode(data)) { - ret = new Episode(data, 30); + ret = new Episode(data); } else { throw new ImdbError(`type: '${data.Type}' is not valid`); } diff --git a/src/interfaces.ts b/src/interfaces.ts index 99d9873..edd60c4 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -49,6 +49,7 @@ export interface OmdbTvshow { export interface OmdbEpisode { Title: string; Released: string; + Season: string; Episode: string; Type: string; imdbRating: string;