-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
128 lines (109 loc) · 3.28 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
var Generic = require('butter-provider');
var inherits = require('util').inherits;
var debug = require('debug')('butter-provider-odd');
// because promise <3
var got = require('got');
var _ = require ('lodash');
function Odd(args) {
if (!(this instanceof Odd)) {
return new Odd();
}
Generic.call(this);
// oddworks vars
this.apiUri = args.apiUrl || 'http://beta.oddworks.io';
this.accessToken = args.accessToken || require('./token.json').token;
debug ('apiURI', this.apiUri);
debug ('accessToken', this.accessToken);
}
inherits(Odd, Generic);
Odd.prototype.config = {
name: 'odd',
uniqueId: 'id',
tabName: 'Oddworks',
type: Generic.TabType.ANIME,
/* should be removed */
//subtitle: 'ysubs',
metadata: 'trakttv:movie-metadata'
};
Odd.prototype.call = function (endpoint, headers) {
// construct method
var req = {
method: 'GET',
url: this.apiUri + endpoint,
headers: {
'Accept': 'application/json',
'Cache-Control': 'no-cache',
'x-access-token': this.accessToken
}
};
// inject additionnal headers
for (var header in headers) {
req.headers[header] = headers[header];
}
//req.headers = Object.assign(req.headers, headers);
// actual call
return got(req.url, req).then(function (response) {
// return json (parse headers here)
return JSON.parse(response.body);
});
}
function formatForButter(data) {
return data.map(function(d) {
return {
id: d.id,
title: d.attributes.title,
year: 'FIXME',
genre: 'FIXME',
rating: 'FIXME',
poster: d.attributes.images,
backdrop: 'FIXME',
torrents: 'FIXME',
subtitle: 'FIXME',
trailer: 'FIXME',
synopsis: 'FIXME',
type: 'movie'
}
});
}
Odd.prototype.fetch = function(filters) {
var that = this;
// get main view
return this.call('/v1/config', {
'Postman-Token': 'bc5ccbf2-322f-0729-63e2-bbac8e167e6c'
}).then(function (data) {
debug(data.links.self, data);
debug('Device:', data.meta.device);
// get featureds for this device
return that.call('/v1/views/' + data.data.attributes.view);
}).then(function (data) {
debug(data.links.self, data);
console.info('featuredMedia', data.data.relationships.featuredMedia);
console.info('featuredCollections', data.data.relationships.featuredCollections);
// get video metadata
return that.call('/v2/videos');
}).then(function (data) {
debug(data.links.self, data);
console.info('available videos:', data.data);
return data.data;
}).then(formatForButter)
.then(function (data) {
// console.info('bhal', data);
return {
results: data,
hasMore: true
}
}).catch(function (err) {
console.error('urh iz borken', err);
});
}
Odd.prototype.extractIds = function (items) {
return _.pluck(items.results, 'imdb_id');
};
Odd.prototype.random = function () {
console.error ('not implemented');
};
Odd.prototype.detail = function (torrent_id, old_data) {
return Promise(old_data);
};
module.exports = Odd