This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
addon.js
53 lines (39 loc) · 1.48 KB
/
addon.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
const manifest = require('./manifest');
const {addonBuilder} = require('stremio-addon-sdk');
const imdb = require('./imdb-promise');
const updatePresence = require('./rpc');
const parseMovieDuration = require('./movie-duration');
const addon = new addonBuilder(manifest);
function showStartupPresence() {
updatePresence({
largeImageKey: 'stremio-logo',
details: 'https://stremio.com',
state: 'All the video content you enjoy in one place',
});
}
showStartupPresence();
addon.defineSubtitlesHandler(async args => {
const id = args.id.split(':')[0];
const info = await imdb(args);
if (info == null) throw 'stremio-discord: no imdb data found for ' + id;
const movieDuration = parseMovieDuration(info.runtime);
updatePresence({
state: `⭐ ${info.imdbRating}/10`,
details: `📺 ${info.name} (${info.year})`,
startTimestamp: Date.now(),
endTimestamp: movieDuration.estimatedWatchedDate,
largeImageKey: 'stremio-logo',
});
setTimeout(() => showStartupPresence(), movieDuration.seconds * 1000);
return Promise.resolve({subtitles: []});
});
addon.defineStreamHandler(async (args) => {
const info = await imdb(args);
updatePresence({
state: `😎 about to watch ${info.name}`,
details: `🍿 picking streams for a ${args.type}`,
largeImageKey: 'stremio-logo',
});
return Promise.resolve({streams: {}, cacheMaxAge: 0});
});
module.exports = addon.getInterface();