-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.js
49 lines (46 loc) · 1.53 KB
/
core.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
43
44
45
46
47
48
49
"use strict";
var _ = require('lodash');
var request = require('request-promise');
var extend = require('extend');
var baseUrl = 'https://frinkiac.com/api/search';
var captionBaseUrl = 'https://frinkiac.com/api/caption';
var imgBaseUri = 'https://frinkiac.com/img/{episode}/{timestamp}/{size}.jpg';
function Core(logger) {
var self = this;
self.logger = logger;
self.search = function(query) {
return request({
method: 'GET',
uri: baseUrl,
qs: { q: query },
json: true
})
.then(function (scenes) {
return scenes.slice(0, 50);
})
.map(function (scene) {
var imgUri = imgBaseUri
.replace('{episode}', scene.Episode)
.replace('{timestamp}', scene.Timestamp);
scene = extend(scene, {
ImageUri: imgUri.replace('{size}', 'medium'),
ThumbnailUri: imgUri.replace('{size}', 'small')
});
return request({
method: 'GET',
uri: captionBaseUrl,
qs: { e: scene.Episode, t: scene.Timestamp },
json: true
})
.then(function (sceneCaption) {
var caption = _.map(sceneCaption.Subtitles, function(subtitle) {
return subtitle.Content;
}).join(' / ');
return extend(scene, { Caption: caption });
});
});
};
}
module.exports = function (logger) {
return new Core(logger);
};