Comparing version 1.0.1 to 1.1.0
@@ -75,3 +75,3 @@ var http = require('http'); | ||
function onEnd() { | ||
var responseObject | ||
var responseObject; | ||
@@ -100,2 +100,62 @@ try { | ||
} | ||
} | ||
}; | ||
module.exports.getById = function(id, cb) { | ||
var responseData = ""; | ||
if (typeof(cb) !== "function") | ||
throw new TypeError("cb must be a function"); | ||
var intRegex = /^\d+$/; | ||
if(intRegex.test(id)) { | ||
// user give us a raw id we need to prepend it with tt | ||
id = 'tt'+id; | ||
} | ||
var imdbRegex = /^tt\d+$/; | ||
if(! imdbRegex.test(id)) { | ||
throw new TypeError("id must be a an imdb id (tt12345 or 12345)"); | ||
} | ||
var myDeanclatworthy; | ||
myDeanclatworthy = extend(myDeanclatworthy, deanclatworthy); | ||
myDeanclatworthy.path += "?" + querystring.stringify({ id: id}); | ||
return http.get(myDeanclatworthy, onResponse).on('error', onError); | ||
function onResponse(res) { | ||
return res.on('data', onData).on('error', onError).on('end', onEnd); | ||
} | ||
function onData(data) { | ||
responseData += data; | ||
} | ||
function onEnd() { | ||
var responseObject; | ||
try { | ||
responseObject = JSON.parse(responseData); | ||
} catch (e) { | ||
return cb(e); | ||
} | ||
if (responseObject.hasOwnProperty("code") && responseObject.hasOwnProperty("error")) { | ||
return cb(responseObject.error); | ||
} | ||
if (responseObject.stv === 1 || responseObject.series === 1) { | ||
responseObject.episodes = episodes; | ||
} else { | ||
responseObject.episodes = null; | ||
} | ||
return cb(null, responseObject); | ||
} | ||
function onError(err) { | ||
return cb(err); | ||
} | ||
}; | ||
@@ -5,3 +5,3 @@ { | ||
"description": "Queries unofficial imdb APIs to get movie and television information from imdb", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"main": "lib/imdb.js", | ||
@@ -8,0 +8,0 @@ "homepage": "https://github.com/worr/node-imdb-api", |
@@ -39,2 +39,30 @@ # node-imdb-api | ||
Furthermore if you already know the id you can call getById. | ||
var movie; | ||
imdb.getById('0090190', function(err, things) { | ||
movie = things; | ||
}); | ||
DATA | ||
console.log(movie); | ||
{ imdbid: 'tt0090190', | ||
imdburl: 'http://www.imdb.com/title/tt0090190/', | ||
genres: 'Action,Comedy,Horror,Sci-Fi', | ||
languages: 'English', | ||
country: 'USA', | ||
votes: '11103', | ||
stv: 0, | ||
series: 0, | ||
rating: '6.0', | ||
runtime: '87min,Canada:78min,USA:82min(unratedversion:DirectorsCut),Argentina:87min(MardelPlataFilmFestival),USA:78min(R-ratedversion)', | ||
title: 'The Toxic Avenger', | ||
year: '1984', | ||
usascreens: 0, | ||
ukscreens: 0, | ||
episodes: null | ||
} | ||
What is this episodes shit? | ||
@@ -41,0 +69,0 @@ |
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
31017
9
412
284
3