1.0.0 • Published 5 months ago

@skymansion/imdb v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

IMDB

A simple Node.js wrapper for fetching movie and TV show data from IMDb.

image

npm version

Description

This library provides an easy way to search for movies and TV shows on IMDb and retrieve detailed information about them. It utilizes IMDb's suggestion API for searching and web scraping for detailed data.

Installation

You can install this package using npm:

npm install @skymansion/imdb

Usage

Here's how you can use the IMDb class in your Node.js project:

import IMDb from '@skymansion/imdb';
const imdb = new IMDb();

Get Movie Data

import IMDb from '@skymansion/imdb';

const imdb = new IMDb();

async function moviedata() {
    const movieDetails = await imdb.Getmoviedata('Interstellar', 2014);
    console.log(movieDetails);
}
moviedata();
{
  title: 'Interstellar',
  img: 'https://m.media-amazon.com/images/M/MV5BYzdjMDAxZGItMjI2My00ODA1LTlkNzItOWFjMDU5ZDJlYWY3XkEyXkFqcGc@._V1_.jpg',
  description: 'When Earth becomes uninhabitable in the future, a farmer and ex-NASA pilot, Joseph Cooper, is tasked to pilot a spacecraft, along with a team of researchers',
  language: 'English',
  genre: 'Adventure,Drama,Sci-Fi',
  datePublished: '2014-11-07',
  rating: 8.7,
  duration: '2 hours and 49 minutes',
  actors: 'Matthew McConaughey,Anne Hathaway,Jessica Chastain',
  director: 'Christopher Nolan',
  CorrectConfidence: 92
}

Get TVShow Data

import IMDb from '@skymansion/imdb';

const imdb = new IMDb();
async function tvSeriesdata() {
    const TvShowDetails = await imdb.GetTvShowdata('Game of Thrones', 2011);
    console.log(TvShowDetails);
}
tvSeriesdata();
{
  title: 'Game of Thrones',
  img: 'https://m.media-amazon.com/images/M/MV5BMTNhMDJmNmYtNDQ5OS00ODdlLWE0ZDAtZTgyYTIwNDY3OTU3XkEyXkFqcGc@._V1_.jpg',
  description: 'Nine noble families fight for control over the lands of Westeros, while an ancient enemy returns after being dormant for millennia.',
  language: 'English',
  genre: 'Action,Adventure,Drama',
  datePublished: '2011-04-17',
  rating: 9.2,
  duration: '',
  actors: 'Emilia Clarke,Peter Dinklage,Kit Harington',
  director: undefined,
  CorrectConfidence: 92
}

API

new IMDb()

Creates a new instance of the IMDb class.

imdb.search(name, year, type)

Searches for movies or TV shows on IMDb based on the provided name, year, and type.

Parameters:

  • name (string): The title of the movie or TV show.
  • year (number, optional): The release year of the movie or TV show.
  • type (string): The type of content to search for. Possible values are 'movie' or 'tvSeries'.

Returns:

A Promise that resolves to an object containing the best matching result, or null if no match is found. The result object has the following properties:

  • title (string): The title of the movie or TV show.
  • id (string): The IMDb ID of the movie or TV show (e.g., tt0111161).
  • type (string): The type of content ('movie' or 'tvSeries').
  • year (number | 'Unknown'): The release year, or 'Unknown' if not available.
  • cast (string): A comma-separated string of the main cast members.
  • image (string): The URL of the movie or TV show's poster image, or 'N/A' if not available.
  • matchConfidence (number): A percentage indicating the confidence of the match.

imdb.Getmoviedata(name, year)

Searches for a movie and retrieves detailed information about it.

Parameters:

  • name (string): The title of the movie.
  • year (number, optional): The release year of the movie.

Returns:

A Promise that resolves to an object containing detailed information about the movie, or 'data not found' if no suitable match is found (with a match confidence below 50%). The detailed movie object has the following properties:

  • title (string): The title of the movie.
  • img (string): The URL of the movie's poster image.
  • description (string): A brief description of the movie.
  • language (string, optional): The language of the movie.
  • genre (string): A comma-separated string of the movie's genres.
  • datePublished (string): The publishing date of the movie.
  • rating (string, optional): The IMDb rating of the movie.
  • duration (string): The runtime of the movie in a human-readable format (e.g., "2 hours and 22 minutes").
  • actors (string): A comma-separated string of the main actors in the movie.
  • director (string, optional): The director of the movie.

imdb.GetTvShowdata(name, year)

Searches for a TV show and retrieves detailed information about it.

Parameters:

  • name (string): The title of the TV show.
  • year (number, optional): The release year of the first episode of the TV show.

Returns:

A Promise that resolves to an object containing detailed information about the TV show, or 'data not found' if no suitable match is found (with a match confidence below 50%). The detailed TV show object has the following properties:

  • title (string): The title of the TV show.
  • img (string): The URL of the TV show's poster image.
  • description (string): A brief description of the TV show.
  • language (string, optional): The language of the TV show.
  • genre (string): A comma-separated string of the TV show's genres.
  • datePublished (string): The publishing date of the first episode of the TV show.
  • rating (string, optional): The IMDb rating of the TV show.
  • duration (string): The runtime of an episode in a human-readable format (e.g., "45 minutes").
  • actors (string): A comma-separated string of the main actors in the TV show.
  • director (string, optional): The director of the TV show (may be for the first episode or series).

Dependencies

This library relies on the following packages:

  • node-fetch: For making HTTP requests.
  • string-similarity: For comparing string similarity to find the best match.
  • node-html-parser: For parsing HTML content from IMDb's mobile site.
  • iso8601-duration: For parsing ISO 8601 duration strings into a readable format.

Error Handling

The WorkspaceResults method includes basic error handling for network requests. The getIMDbMovieDetails method uses Promises to handle successful data retrieval and errors during fetching or JSON parsing. The Getmoviedata and GetTvShowdata methods return 'data not found' if the initial search doesn't yield a result with sufficient confidence.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

MIT

Keywords

imdb, api, wrapper, movie, tv, show, search, details, nodejs

Author

Dilshan - ravindudil5han