-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.js
executable file
·60 lines (53 loc) · 2.16 KB
/
build.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
#!/usr/bin/env node
const fs = require('fs');
const fetch = require('node-fetch');
const validator = require('@stremio/stremio-core-validator');
const localAddonManifest = require('stremio-local-addon/lib/manifestNoCatalogs');
const legacyManifestMapper = require('stremio-addon-client/lib/transports/legacy/mapper');
const LEGACY_REQUEST_PARAM = '/q.json?b=eyJwYXJhbXMiOltdLCJtZXRob2QiOiJtZXRhIiwiaWQiOjEsImpzb25ycGMiOiIyLjAifQ==';
const PROTECTED_URLS = [
'https://v3-cinemeta.strem.io/manifest.json',
'http://127.0.0.1:11470/local-addon/manifest.json',
];
const OFFICIAL_URLS = [
'https://v3-cinemeta.strem.io/manifest.json',
'https://v3-channels.strem.io/manifest.json',
'https://watchhub.strem.io/manifest.json',
'https://caching.stremio.net/publicdomainmovies.now.sh/manifest.json',
'https://opensubtitles-v3.strem.io/manifest.json',
'http://127.0.0.1:11470/local-addon/manifest.json',
];
function getManifest(transportUrl) {
if (transportUrl === 'http://127.0.0.1:11470/local-addon/manifest.json') {
return Promise.resolve(localAddonManifest);
}
const legacy = transportUrl.endsWith('stremio/v1');
return fetch(legacy ? `${transportUrl}${LEGACY_REQUEST_PARAM}` : transportUrl)
.then((resp) => resp.json())
.then((resp) => legacy ? legacyManifestMapper.mapManifest(resp.result) : resp);
}
function getDescriptor(transportUrl) {
return getManifest(transportUrl)
.then((manifest) => ({
manifest,
transportUrl,
flags: {
official: true,
protected: PROTECTED_URLS.includes(transportUrl)
}
}));
}
Promise.all(OFFICIAL_URLS.map((url) => getDescriptor(url)))
.then((descriptors) => {
return descriptors
.map((descriptor) => {
const validated = validator.descriptor(descriptor);
if (validated === null) {
throw new Error(`${descriptor.transportUrl} is invalid`);
}
return validated;
});
})
.then((descriptors) => {
fs.writeFileSync('./addons.json', JSON.stringify(descriptors, null, 4));
});