Skip to content

Commit

Permalink
Fix broken season number in episode (Fixes #73, #74)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
worr committed Jun 29, 2020
1 parent e8d2a6a commit 2874784
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/imdb.ts
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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`);
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Expand Up @@ -49,6 +49,7 @@ export interface OmdbTvshow {
export interface OmdbEpisode {
Title: string;
Released: string;
Season: string;
Episode: string;
Type: string;
imdbRating: string;
Expand Down

0 comments on commit 2874784

Please sign in to comment.