-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (33 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var wi = require('wiki-infobox');
var wikiPages = require('./wiki-pages.json');
var noe = function(title, cb) {
if (title in wikiPages) {
title = wikiPages[title];
}
wi(title, 'en', function(err, infobox) {
if (
(err && title.indexOf('series') === -1) ||
(infobox && typeof infobox.num_episodes === 'undefined')
) {
// There's an error but we didn't add 'TV SERIES' to the title
noe(title + ' (TV series)', cb);
return;
} else if (err) {
cb(new Error('No episodes found :('));
return;
}
var episodes = infobox.num_episodes;
if (Array.isArray(infobox.num_episodes)) {
episodes = infobox.num_episodes.filter(function(element) {
var parsed = parseInt(element.value, 10);
return element.type === 'text' &&
typeof parsed === 'number' &&
!Number.isNaN(parsed);
}).pop();
}
episodes = episodes && episodes.value ? parseInt(episodes.value, 10) : 0;
cb(err, episodes);
});
};
module.exports = noe;