name-to-imdb
Advanced tools
Comparing version 1.2.1 to 1.2.2
41
index.js
var async = require("async"); | ||
var events = require("events"); | ||
var namedQueue = require("named-queue"); | ||
var qs = require("querystring"); | ||
@@ -92,8 +92,2 @@ var _ = require("lodash"); | ||
// Concurrency control | ||
var retriever = new events.EventEmitter(); | ||
retriever.setMaxListeners(0); // Unlimited amount of listeners | ||
var inProgress = { }; | ||
// In-memory cache for matched items, to avoid flooding Google (or whatever search api we use) | ||
@@ -119,26 +113,23 @@ var cache = { }; | ||
// Use a system of an EventEmitter + inProgress map to make sure items of the same name are not retrieved multiple times at once | ||
// Since google searches can take some time and we don't want to repeat | ||
retriever.once(hash, cb); | ||
cb = function(err, id, inf) { retriever.emit(hash, err, id, inf) }; | ||
queue.push({ id: hash, q: q, args: args }, function(err, imdb_id, match) { | ||
if (err) return cb(err); | ||
if (imdb_id) { | ||
cache[hash] = imdb_id; | ||
setTimeout(function() { delete cache[hash] }, CACHE_TTL); | ||
} | ||
cb(null, imdb_id, match); | ||
}); | ||
}; | ||
if (inProgress[hash]) return; | ||
inProgress[hash] = true; | ||
retriever.once(hash, function(err, id) { | ||
delete inProgress[hash]; | ||
// Cache system | ||
cache[hash] = id; | ||
setTimeout(function() { delete cache[hash] }, CACHE_TTL); | ||
}); | ||
var queue = new namedQueue(function(task, cb) { | ||
// Find it in our metadata, if not, fallback to Google | ||
metadataFind(q, function(err, id) { | ||
metadataFind(task.q, function(err, id) { | ||
if (err) return cb(err); | ||
if (id || args.strict || args.noGoogle) return cb(null, id, { match: "metadata" }); // strict means don't search google | ||
webFind(args, cb); | ||
if (id || task.args.strict || task.args.noGoogle) return cb(null, id, { match: "metadata" }); // strict means don't search google | ||
webFind(task.args, cb); | ||
}); | ||
}; | ||
}, 3); | ||
module.exports = nameToImdb; | ||
module.exports.byImdb = byImdb; |
{ | ||
"name": "name-to-imdb", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Finds IMDB ID by movie/series name (fuzzily) and optionally year and type", | ||
@@ -28,2 +28,3 @@ "main": "index.js", | ||
"lodash": "^3.10.1", | ||
"named-queue": "^2.0.0", | ||
"needle": "^0.11.0", | ||
@@ -30,0 +31,0 @@ "stremio-addons": "^2.0.2", |
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
8077
6
110
+ Addednamed-queue@^2.0.0
+ Addednamed-queue@2.2.1(transitive)