Giter VIP home page Giter VIP logo

node-imdb-api's Introduction

node-imdb-api

A non-scraping, functional node.js interface to imdb

Badges

NPM version pipeline status Dependency Freshness coverage report Join the chat at https://gitter.im/worr/node-imdb-api

Github / Gitlab

Gitlab is the official upstream, and commits are mirrored to Github. I look at issues and PRs/MRs on both. Feel free to contribute on either.

API Docs

API docs are now here

Use

Import the library using require

const imdb = require('imdb-api')

or ES6 import

import imdb from 'imdb-api'

Call get to get a single movie

imdb.get({name: 'The Toxic Avenger'}, {apiKey: 'foo', timeout: 30000}).then(console.log).catch(console.log);

Movie {
  title: 'The Toxic Avenger',
  ...
}

Furthermore if you already know the id you can call get with different args:

imdb.get({id: 'tt0090190'}, {apiKey: 'foo'}).then(console.log);

Movie {
  title: 'The Toxic Avenger',
  ...
}

You can search for movies, and get multiple results by using the search function.

imdb.search({
  name: 'Toxic Avenger'
}, {
  apiKey: 'foo'
}).then(console.log).catch(console.log);

TV shows have an episodes method that you can use to fetch all of the episodes from that TV series.

imdb.get({name: 'How I Met Your Mother'}, {apiKey: 'foo'}).then((things) => {
    return things.episodes()
}).then((eps) => {
    console.log(eps);
});

Episode {
  season: 2,
  name: 'The Scorpion and the Toad',
  released: '2006-10-25T07:00:00.000Z',
  episode: 2,
  rating: '8.3',
  imdbid: 'tt0869673' },
...

Using a Client object

imdb-api also exported a Client object that you can use to store options for subsequent requests.

import imdb = require('imdb');
const cli = new imdb.Client({apiKey: 'xxxxxx'});
cli.get({'name': 'The Toxic Avenger'}).then(console.log);

Client also has a search method for searching.

import imdb = require('imdb');
const cli = new imdb.Client({apiKey: 'xxxxxx'});
cli.search({'name': 'The Toxic Avenger'}).then((search) => {
  for (const result of search.results) {
    console.log(result.title);
  }
});

FAQ

I see an API key in your examples? Is it required? How do I get one?

Yes, it is required! omdb made this a requirement as of May 8, 2017. This is unfortunate, but totally understandable. While I plan on working on finding an alternative to provide the movie info you crave, I've enabled you to pass in an apikey.

You can get one by going here.

Why? There are like 3 other interfaces to imdb in npm

Most of them scrape imdb. imdb explicitly forbids scraping.

And what happens when the site layout changes? Well then your screen scraping solution fails in interesting ways. Screen scraping is also pretty slow, and we can't have that.

WOAH I looked at your code and you're using unofficial APIs!

There isn't an official API to imdb. As soon as one is released (and I notice), I'll update the module.

imdb DOES release all of their data in text files nightly, so unofficial sites have popped up providing RESTful APIs against that data.

I have to use a few, since none of them are complete.

What if one of the unofficial APIs disappears?

File a bug. I'll get creative.

node-imdb-api's People

Contributors

adeelk93 avatar amilajack avatar breakbb avatar danielwerg avatar dependabot[bot] avatar dheffx avatar gitter-badger avatar juanpabloaj avatar ka2er avatar minigod avatar worr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-imdb-api's Issues

Need a bit of clarification

So this is the first time i am using an external api for my web project. I have used the install command listed and i am wondering how exactly does the process work for using this project?

In my home directory I do have the the package.json, only dependencies it has is imdb-api:^2.2.0.

To use this project, does our project have to be a node.js project? if so, how can I have it also look at the package.json file i have on my home directory? And if it does not need to be a node.js file, I would like to use it in my php code, how to do so? Apologies if this is not the correct place to ask this question.

Video trailer

Can you add the front video trailer url (not all, just the preselected one on the movie's front page)?

Not handling shows with same name when getting episode list

From http://imdbapi.poromenos.org/:

If there are multiple shows with the same name, you can pass the "year" parameter as well to select a year.

Currently we have this:
http://imdbapi.poromenos.org/js/?name=The%20Walking%20Dead

{
    "shows": [{
        "name": "The Walking Dead",
        "year": 2010
    }, {
        "name": "The Walking Dead",
        "year": 2011
    }]
}

Which throws error:

Cannot read property 'episodes' of undefined
TypeError: Cannot read property 'episodes' of undefined
    at IncomingMessage.onEnd (/home/me/shitz/node_modules/imdb-api/lib/imdb.js:80:48)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

Adding year:
http://imdbapi.poromenos.org/js/?name=The%20Walking%20Dead&year=2010

{"The Walking Dead": {"episodes": [{"season": 2, "name": "18 Miles Out", "number": 10}, {"season": 3,............

Is there a way to return more than one result?

I've tried the different methods exposed by your api, but everything seems to just return one result. Is there a way to return a list of search results based on a particular query, or is that not yet supported?

Thanks

trying to get episodes for a show throws error

Hi, thanks for your work on this. Following your example on how to get the episodes for a show, it always fails with TypeError: invalid release date or TypeError: invalid rating, depending on what show I query.

Here is the code I use

  const imdbid = 'tt4270492';
  imdb.get(
    {id: imdbid},{
      apiKey: MyApiKey
  }).then((show) => {
    return show.episodes();
  }).then((episodes) => {
    console.log(episodes);
  }).catch(console.log);

Error in example code in README.md

There is an error in this example on the README

let movie;
imdb.getReq({ id: '0090190' }, (err, things) => {
    movie = things;
});

The id should be 'tt0090190'

OMDB now needs a key!!

Hi,
It seems your package does not work any more since omdb api now requests a private key.
"ERR IMDB: 401 - {"Response":"False","Error":"No API key provided."}"
Would you please update the package soon?

Thanks a lot!

Episode release date

The episode releases seem to be off by 1 month.

I could be wrong, but it looks like the date constructor takes 0-11 for the month and it's given a parsed 1-12. (imdb.js line 26)

Budget?

Hey I'm wondering if the API can be expanded on to add the movie's estimated Budget - I know IMDB displays it, but I'm not sure whether the various APIs make it accessible.

Unable to resolve module 'os'

When getting the imdb object I get this error:

screen shot 2017-03-27 at 12 03 21

What does this mean, why is it happening and how can I fix it? I need this module for my app, it's for a school project and it's the only good imdb api out there.

Here's my project structure:

screen shot 2017-03-27 at 12 06 21

Thank you

Episodes of a Movie ?

I realize there aren't really episodes for movies so I guess that's the problem though it probably shouldn't contain an episodes function if there are none

On a related note, it seems like its only returning the first result, maybe an option to get the top N results ?

var imdb = require('imdb-api');

var query = process.argv[2];

if(!query)
  return;

console.log("SEARCHING FOR", query);

imdb.get(query, function(err, things) {

    console.log("RESULTS FOR", query,'\n', things);

    if(things && things.episodes)
    things.episodes(function(err, moreThings) {
      console.log("EPISODES FOR", query,'\n', moreThings);
    });
});

node moviez.js 'godfather'

SEARCHING FOR godfather
RESULTS FOR godfather
 { _episodes: [],
  imdbid: 'tt0068646',
  imdburl: 'http://www.imdb.com/title/tt0068646/',
  genres: 'Crime,Drama',
  languages: 'English,Italian,Latin',
  country: 'USA',
  votes: '682507',
  stv: 0,
  series: 0,
  rating: '9.2',
  runtime: '175min',
  title: 'The Godfather',
  year: '1972',
  usascreens: 323,
  ukscreens: 2,
  cacheExpiry: 1367505168 }

/Volumes/jpillora/Code/Node/system/moviez/node_modules/imdb-api/lib/imdb.js:65
            eps = JSON.parse(eps)[tvShow.title].episodes;
                                 ^
TypeError: Cannot read property 'The Godfather' of null
    at IncomingMessage.onEnd (/Volumes/jpillora/Code/Node/system/moviez/node_modules/imdb-api/lib/imdb.js:65:34)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:870:14
    at process._tickCallback (node.js:415:13)

Change language in headers

Hi,

Is it possible to add an optional parameter which will specify the language we want to request IMDB with ?
I actually did it manually for a specific need, and forced request in english in the movies.js file :
request({headers: {'Accept-Language': 'en-US'}, uri: 'http://www.imdb.com/title/' + id + '/'}, function (error, response, body) {

getting 403

I'm getting this 403 error:
Unhandled rejection StatusCodeError: 403

followed by a bunch of html, which says:

Please enable cookies.

Sorry, you have been blocked

You are unable to access omdbapi.com

Why have I been blocked?

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.

Cloudflare Ray ID: 32dc0019e6fd51ca
Your IP: xxx.xxx.xxx.xxx
Performance & security by Cloudflare

not an issue!

just wanted to mention how awesome you are for using the "toxic avenger" in the example ;)

Search Feature not working for year attribute.

The 'search' function exposed by the imdb module does not filter based on year.

FIX ๐Ÿ‘ :
Go to imdb.ts (line 60-66). Inside method 'reqtoqueryobj' under the condition to check if year is undefined, change req["y"] = req.year into ret["y"] = req.year. This will add the 'y' paramter to the return and not the request.

getByReq

When calling getByReq by

getByReq({id:'tt1258197'}, function(err, things){console.log(things);});

You will get to see on your console:

null

, which it shouldn't because tt1258197 is a valid imdb id.

The fault lies at line number 110 in lib/imdb.js:

if(req.name !== null).

The if statment will return true with the given example.

This can be fixed by not checking against null but against undefined. But the functions get and getById should then also be altered since they call getByReg with either name or id set on null, which will break with the given fix.

I'm using node v0.10.5.

not throwing correctly errors but strings instead

Hey,
first of all thanks for your great work. Maybe you could implement to give correct errors and maybe also attach the name of the film which is throwing that error (Not Found). So the user can handle that by setting a property or sth.

Spruce

imdb.getReq generate error when cb is not set and api returns an error

Trying to use the API, I got the following error:

TypeError: cb is not a function
    at imdb-api\lib\imdb.js:152:20

Looking at the source code of your module:

if (interfaces_1.isError(data)) {
    return cb(new ImdbError(data.Error + ": " + (req.name ? req.name : req.id), req), undefined);
}

It seems to require cb when there is an error from the API endpoint.

tests broken in node 10.7.0

Seems the release of node 10.7.0 about a week or so ago has broken the test suite, and Travis is using it for the node10 ci jobs.

How to recreate:

sudo n 10.7.0
npm run check

Working tests:

sudo n 10.6.0
npm run check

Effected files:

test/test-getReq.t
test/test-client.t
  1. tests client creation and use
    merges options from client args:
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/dheffner/dev/node-imdb-api/test/test-client.ts)

  2. tests client creation and use
    merges options from client args when performing a search:
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/dheffner/dev/node-imdb-api/test/test-client.ts)

  3. get
    times out making a request:
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/dheffner/dev/node-imdb-api/test/test-getReq.ts)

  4. get
    times out fetching episodes:
    Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/dheffner/dev/node-imdb-api/test/test-getReq.ts)

Obtaining movie/tv show cast

Hello
I didn't notice any way of obtaining a movie cast, i.e. list of actors along with their role in the movie.
Is this possible to do this with the current version?

Movie/TV Poster Images

Would it be at all possible to add an attribute for an image link in the returned JSON? Or would that violate the no scraping?

Response data isn't accurate with what's on the website.

The IMDB ID: tt1519397

Shows a rating of 9.4 with 5 votes at the time of writing this from the API, if you go to the IMDB site it's 6.7 with 13 votes.

The ID of tt1539700

Has a rating of 8.4 with 36 votes but the website shows a rating of 8.5 with 60 votes.

Also, the ID of 1090023 fails to fetch for me but I can see it here: https://www.imdb.com/title/tt1090023/ super weird.

tmp_id = 'tt1090023'
imdb.get({ id: tmp_id }, { apiKey: _api_key }).then(console.log).catch(error => {
    console.log('Error', error);
});
Error TypeError: invalid episode
    at new Episode (./node_modules/imdb-api/lib/imdb.js:96:23)

Do you know why the API response data is not the same as the website?

Still working?

Does this still work? I'm getting 'null' result from the example.

Cross origin issue

I'm attempting to try to pull in some data using the API and I keep receiving this error in my browser console.

(index):1 XMLHttpRequest cannot load https://www.omdbapi.com/?plot=full&r=json&t=The%20Toxic%20Avengers. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

I'm using Meteor build tools and this is my exact code. Any advice would be greatly appreciated.

const imdb = require('imdb-api');
let movie='';

imdb.getReq({name:'The Toxic Avengers'}, (err,things) => {
movie = things;
console.log(movie);
});

Not working?

I see one of your unofficial api has gone down, does that mean this will api no longer work as well?

Accessing to the results

Hi, I've been working with the API and Ember and I don't know how to extract the value returned in the Promise. I have tried in different ways and I would really appreciate some help

// search has already been caught and imdb imported
imdb.get(search).then((result) => {
     //Here is where I need help
});

I have tried different ways these are the two main ones

self = this;
imdb.get(search).then((result)=>{
  self.movies = result
})
console.log(self.movies) //Returns undefined
console.log(self) // Returns an object Class, the propery class is in there but I can't access it

I also tried

data = {};
imdb.get(search).then((result) => { data.movies : result; });
console.log(data.movies)  //Returns undefined
console.log(data) //Returns {}.movie

Help please

Error 503

StatusCodeError: 503 - "The service is unavailable."

Auto Complete

Any ideas how I can fetch data to use for auto completion, since getting the data depends on a correctly spelling the show or the movie name.

Thanks. @worr

SyntaxError: Unexpected end of input

Whenever I use imdb.getReq({name: searchstring},callback), I get an error saying "SyntaxError: Unexpected end of input". What does this mean and how do I fix it?

Doubts about Legal problems

Hi, thank you for releasing this API.
I'm thinking about a project and i wanna know: can i have legal issues by using this API ?
I read this page and with my limited legal knowledge I think I'm not allowed to republish their database information.

Will I have legal problems ?

Thanks in advance.

node-imdb-api broken? Querying deanclatworthy.com directly works, though

Hi worr, All,
I have just tried using node-imdb-api with a simple query in the Nodejs interactive shell:

var imdb = require('imdb-api');
imdb.getReq({ name: 'Skyfall' }, function(err, things) { return things; });

... and what I get is very different from what described in your docs, see below.

Oddly enough, if I query deanclatworthy.com directly using http://deanclatworthy.com/imdb/?q=Skyfall&yg=0 the data I get back is in order. I am using Nodejs v0.10.24.

{ domain: null,
  _events: 
   { response: { [Function: g] listener: [Function: onResponse] },
     socket: { [Function: g] listener: [Function] },
     error: [Function: onError] },
  _maxListeners: 10,
  output: [ 'GET /imdb/?q=Skyfall&yg=0 HTTP/1.1\r\nHost: deanclatworthy.com\r\nConnection: keep-alive\r\n\r\n' ],
  outputEncodings: [ undefined ],
  writable: true,
  _last: true,
  chunkedEncoding: false,
  shouldKeepAlive: true,
  useChunkedEncodingByDefault: false,
  sendDate: false,
  _headerSent: true,
  _header: 'GET /imdb/?q=Skyfall&yg=0 HTTP/1.1\r\nHost: deanclatworthy.com\r\nConnection: keep-alive\r\n\r\n',
  _hasBody: true,
  _trailer: '',
  finished: true,
  _hangupClose: false,
  socket: null,
  connection: null,
  agent: 
   { domain: null,
     _events: { free: [Function] },
     _maxListeners: 10,
     options: {},
     requests: {},
     sockets: { 'deanclatworthy.com:80': [Object] },
     maxSockets: 5,
     createConnection: [Function] },
  socketPath: undefined,
  method: 'GET',
  path: '/imdb/?q=Skyfall&yg=0',
  _headers: { host: 'deanclatworthy.com' },
  _headerNames: { host: 'Host' } }

timeout values in documentation

I did a straight cut & paste of the demo code in the documentation to do a quick test and got timeouts, the timeout value is set to 30ms in the example code which wasn't long enough.

option to request short plot summary

Request:
an option to pass plot: short to get short plots from omdbapi


I haven't done anything with typescript before, so not too sure what the extent of changes needed for a proper pull request, but my guess is that this would be enough:

export interface MovieRequest {
    name?: string;
    id?: string;
    year?: number;
    plot?: string;
}
...
    let qs = {r: "json", y: req.year};
    qs["plot"] = (req.plot) ? req.plot ? "full";

Please distribute your module as JavaScript

I saw you are using TypeScript which is cool! But please, pretty please distribute your module as JavaScript, since in Windows world there is no "make" command. So your module fail to build in Windows and plus if you really think about this TypeScript it's an unnnecesary dependency.

okthxbye

apiKey on each request?

Would it be possible to set the default apiKey on the omdb instance, such that it isn't necessary to send the key on each request? Maybe something like:

imdb.configure({ apiKey: 'foo' });
// allowing...
imdb.get('The Toxic Avenger', {timeout: 30000}) // No #apiKey necessary

Might also be good to allow setting other default config options (like timeout) this way (while enabling overrides on a per-call basis)

ReferenceError: Can't find variable: require

var imdb = require("imdb-api");

gives me the following error

ReferenceError: Can't find variable: require

My node is verison: v6.5.0

Any ideas? I just started using node.js. Maybe I got forgot a dependency?

Bogus exception handling

Here was a bugs bug report, which I found out was actual error in my application, but I had now way of diagnosing that without digging around a and changing some code in imdb.js.

My app was throwing some (unexpected) exception in the getReqById callback, but for some reason the imdb catches all exceptions inside prom, so it didn't propagate further and was returned as an cb(err, undefined), so I 1) had no way to find there this error actually occurred 2) thought it was internal imdb error.

Wish: production company, original title

This is great. However, I am wondering if there are plans to extend the API to also pick up the production company and the original title (for non-EN films)? Many thanks.

Getting Error

Hi! Thank you for making this! I've been looking for it! But I haven't been able to use it so far, I keep getting this when I try to run de app

$ node app.js

module.js:340
throw err;
^
Error: Cannot find module 'imdb'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object. (/Applications/MAMP/htdocs/labs/node/imdb-api/app.js:10:12)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)

I can't figure out the problem. Can you help me? Thanks a lot!

filtering movies with same title

Hello worr,

I think there should be a direct way to filter movies with same title

imdb.getReq({ name: 'RoboCop' }, function(err, things) {});

That request returns the movie from 1987. Lets say that instead of that one I want to see the movie from 2014. I tried querying with year, _year and _year_data parameters but nothing's changed.

Am I missing something here?

Unhandled rejection RequestError: Error: connect ETIMEDOUT 104.20.135.15:443

I am trying to integrate this API in my application by using following code

var imdb = require('imdb-api');
imdb.getById('tt0090190', {apiKey: 'XXXXXX'}).then(console.log);

But I am getting following error

Unhandled rejection RequestError: Error: connect ETIMEDOUT 104.20.135.15:443
    at new RequestError (C:\xampp\test\node_modules\request-promise-core\lib\errors.js:14:15)
    at Request.plumbing.callback (C:\xampp\test\node_modules\request-promise-core\lib\plumbing.js:87:29)
    at Request.RP$callback [as _callback] (C:\xampp\test\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at self.callback (C:\xampp\test\node_modules\request\request.js:188:22)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.onRequestError (C:\xampp\test\node_modules\request\request.js:884:8)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at TLSSocket.socketErrorListener (_http_client.js:310:9)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at emitErrorNT (net.js:1278:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I am trying to resolve from many hours. But not finding the proper solution.

Please guide me in this whether I am doing anything wrong in this. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.