stremiok 2.2.8 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +1 -0
- package/config.xml +1 -1
- package/css/modern.css +146 -0
- package/css/style.css +17 -5
- package/index.html +39 -36
- package/js/focus.js +13 -2
- package/js/jellyfin.js +642 -0
- package/js/player-controls.js +29 -1
- package/js/player-core.js +78 -6
- package/js/player-store.js +2 -1
- package/js/plex.js +530 -0
- package/js/stremio.js +45 -6
- package/js/stvod.js +7 -2
- package/js/util.js +61 -8
- package/js/view-core.js +6 -2
- package/js/view-detail.js +35 -8
- package/js/view-discover.js +10 -5
- package/js/view-home.js +74 -7
- package/js/view-settings.js +197 -6
- package/js/ytplay.js +1 -1
- package/package.json +1 -1
- package/service/index.js +48 -14
package/js/plex.js
ADDED
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
/* Plex servers: yours, or ones shared with you. Global namespace: Plex
|
|
2
|
+
- Added in Settings › Content › Media servers: a code you enter at plex.tv/link (plex.tv's
|
|
3
|
+
PIN sign-in), then one of the account's servers. Its connections are tried, the ones on your
|
|
4
|
+
network first (never Plex's relay), and the first that answers is kept, with that server's own
|
|
5
|
+
sign-in (its access token). What's kept: its address, name and version, the account's name and
|
|
6
|
+
that sign-in.
|
|
7
|
+
- Like Jellyfin and Emby (js/jellyfin.js: what's shared, the player's side too), as a local
|
|
8
|
+
addon ("Plex"): a catalog per Movies or Shows library, Continue watching and Next up (its On
|
|
9
|
+
Deck); a title the server knows the IMDb id of is a card with that id, any other
|
|
10
|
+
pxm.<server>.<item> (a film) or pxs.<server>.<show> (its episodes …:<season>:<episode>).
|
|
11
|
+
- On titles from your addons (tt…, tmdb:…), the server's copies as sources: its titles and
|
|
12
|
+
their ids, read when first needed and again after INDEX_FRESH_MS.
|
|
13
|
+
- Played as the file is (a part's own link: nothing converted), its SRT / VTT files with it;
|
|
14
|
+
what you play goes back to Plex (/:/timeline; watched: /:/scrobble), except during private
|
|
15
|
+
viewing. Sources carry _jf (kind 'plex'), as a Jellyfin one does: place, chapters, markers,
|
|
16
|
+
seek pictures. */
|
|
17
|
+
var Plex = (function () {
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
var KEY = 'stremiok.plex.servers', DEV_KEY = 'stremiok.plex.device', LIBS_KEY = 'stremiok.plex.libs';
|
|
21
|
+
var TV = 'https://clients.plex.tv', LINK = 'https://plex.tv/link';
|
|
22
|
+
var PAGE = 100, INDEX_FRESH_MS = 30 * 60000, INDEX_RETRY_MS = 60000, LIBS_FRESH_MS = 86400000;
|
|
23
|
+
var PIN_EVERY = 3000, PIN_FOR = 10 * 60000, REPORT_EVERY = 60000, PIC_EVERY = 5000;
|
|
24
|
+
var _changeFns = [];
|
|
25
|
+
function onChange(fn) { _changeFns.push(fn); }
|
|
26
|
+
function changed() { _changeFns.forEach(function (fn) { try { fn(); } catch (e) {} }); }
|
|
27
|
+
function enc(v) { return encodeURIComponent('' + v); }
|
|
28
|
+
function rand(n) { return U.randomHex(n); } // (the TV's secure random numbers)
|
|
29
|
+
function none() { return []; }
|
|
30
|
+
function flat(lists) { return [].concat.apply([], lists || []); }
|
|
31
|
+
function clean(v, max) { return ('' + (v == null ? '' : v)).replace(/\s+/g, ' ').trim().slice(0, max || 60); }
|
|
32
|
+
function mc(r) { return (r && r.MediaContainer) || {}; } // (every Plex answer is in one)
|
|
33
|
+
|
|
34
|
+
// ---- Your servers ----
|
|
35
|
+
function servers() {
|
|
36
|
+
var l = U.store.get(KEY, []);
|
|
37
|
+
return Array.isArray(l) ? l.filter(function (s) { return s && s.id && s.url && s.token && s.machineId; }) : [];
|
|
38
|
+
}
|
|
39
|
+
function server(id) { return servers().filter(function (s) { return s.id === id; })[0] || null; }
|
|
40
|
+
function isEnabled() { return servers().length > 0; }
|
|
41
|
+
function deviceId() {
|
|
42
|
+
var d = U.store.get(DEV_KEY, '');
|
|
43
|
+
if (!/^[0-9a-f]{16,40}$/.test('' + d)) { d = rand(32); U.store.set(DEV_KEY, d); }
|
|
44
|
+
return d;
|
|
45
|
+
}
|
|
46
|
+
function version() { // (StremioK's, from the ?v= build.sh stamps on the script tags)
|
|
47
|
+
try {
|
|
48
|
+
var tag = document.querySelector('script[src*="plex.js"]');
|
|
49
|
+
var m = tag && /[?&]v=([0-9][0-9.]*)/.exec(tag.getAttribute('src') || '');
|
|
50
|
+
if (m) { return m[1]; }
|
|
51
|
+
} catch (e) {}
|
|
52
|
+
return '2';
|
|
53
|
+
}
|
|
54
|
+
// Who's asking (StremioK, this TV) and, signed in, its token; answers as JSON.
|
|
55
|
+
function headers(token) {
|
|
56
|
+
var h = { 'Accept': 'application/json', 'X-Plex-Product': 'StremioK', 'X-Plex-Version': version(), 'X-Plex-Client-Identifier': deviceId(),
|
|
57
|
+
'X-Plex-Platform': 'Tizen', 'X-Plex-Device': 'Samsung TV', 'X-Plex-Device-Name': 'StremioK (Samsung TV)' };
|
|
58
|
+
if (token) { h['X-Plex-Token'] = token; }
|
|
59
|
+
return h;
|
|
60
|
+
}
|
|
61
|
+
function get(srv, path, max) { return U.getJSON(srv.url + path, 20000, max || 4 * 1048576, null, headers(srv.token)); }
|
|
62
|
+
function tell(srv, path) { return U.getText(srv.url + path, 15000, 65536, null, true, headers(srv.token)); }
|
|
63
|
+
function linkOf(srv, path) { return srv.url + path + (path.indexOf('?') === -1 ? '?' : '&') + 'X-Plex-Token=' + enc(srv.token); }
|
|
64
|
+
|
|
65
|
+
// ---- Signing in: plex.tv's code, then the account's servers ----
|
|
66
|
+
// cb: onCode(code, link), onServers([{ name, owned, … }]: pick one, then add()), onError(message).
|
|
67
|
+
// Returns a stop.
|
|
68
|
+
function link(cb) {
|
|
69
|
+
var stopped = false, timer = null, t0 = Date.now();
|
|
70
|
+
function fail(msg) { if (!stopped) { stopped = true; cb.onError(msg); } }
|
|
71
|
+
U.getJSON(TV + '/api/v2/pins?strong=false', 15000, 65536, null, headers(''), '').then(function (pin) {
|
|
72
|
+
if (!pin || !pin.id || !pin.code) { throw new Error('no code'); }
|
|
73
|
+
if (stopped) { return; }
|
|
74
|
+
cb.onCode(clean(pin.code, 12), LINK);
|
|
75
|
+
function poll() {
|
|
76
|
+
timer = setTimeout(function () {
|
|
77
|
+
if (stopped) { return; }
|
|
78
|
+
if (Date.now() - t0 > PIN_FOR) { fail('The code ran out: start again.'); return; }
|
|
79
|
+
U.getJSON(TV + '/api/v2/pins/' + enc(pin.id), 10000, 65536, null, headers(''), null, true).then(function (p) {
|
|
80
|
+
if (stopped) { return; }
|
|
81
|
+
if (!p || !p.authToken) { poll(); return; }
|
|
82
|
+
stopped = true;
|
|
83
|
+
accountServers('' + p.authToken).then(function (list) {
|
|
84
|
+
if (!list.length) { cb.onError('Your Plex account has no servers.'); return; }
|
|
85
|
+
cb.onServers(list);
|
|
86
|
+
}, function (e) { cb.onError('Couldn’t list your Plex servers (' + U.problem(e) + ').'); });
|
|
87
|
+
}, function (e) {
|
|
88
|
+
if (/HTTP 404/.test(e && e.message)) { fail('The code ran out: start again.'); } else { poll(); }
|
|
89
|
+
});
|
|
90
|
+
}, PIN_EVERY);
|
|
91
|
+
}
|
|
92
|
+
poll();
|
|
93
|
+
}).then(null, function (e) { fail('Couldn’t get a code from Plex (' + U.problem(e) + ').'); });
|
|
94
|
+
return function () { stopped = true; clearTimeout(timer); };
|
|
95
|
+
}
|
|
96
|
+
// The account's servers (plex.tv's resources), each with its connections and its own token.
|
|
97
|
+
function accountServers(token) {
|
|
98
|
+
return Promise.all([
|
|
99
|
+
U.getJSON(TV + '/api/v2/resources?includeHttps=1&includeRelay=0&includeIPv6=0', 15000, 2 * 1048576, null, headers(token)),
|
|
100
|
+
U.getJSON(TV + '/api/v2/user', 15000, 262144, null, headers(token)).then(null, function () { return null; })
|
|
101
|
+
]).then(function (r) {
|
|
102
|
+
var user = r[1] ? clean(r[1].username || r[1].title || '') : '';
|
|
103
|
+
return U.listOf(r[0], 50, function (x) { return x && /(^|,)server(,|$)/.test('' + x.provides) && x.clientIdentifier; }).map(function (x) {
|
|
104
|
+
return { machineId: '' + x.clientIdentifier, name: clean(x.name) || 'Plex', version: clean(x.productVersion, 20), owned: !!x.owned,
|
|
105
|
+
token: '' + (x.accessToken || token), user: user, connections: U.listOf(x.connections, 20) };
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// The links to try, in order: on your network (its plain http address first: plex.direct's
|
|
110
|
+
// names need DNS that some routers block), then from the internet; never a relay.
|
|
111
|
+
function candidates(res) {
|
|
112
|
+
var out = [];
|
|
113
|
+
function add(u) { u = ('' + (u || '')).replace(/\/+$/, ''); if (/^https?:\/\/[^\/]+$/i.test(u) && out.indexOf(u) === -1) { out.push(u); } }
|
|
114
|
+
[true, false].forEach(function (local) {
|
|
115
|
+
res.connections.forEach(function (c) {
|
|
116
|
+
if (!c || c.relay || !!c.local !== local) { return; }
|
|
117
|
+
if (local && c.address && /^[\d.]+$/.test('' + c.address) && c.port) { add('http://' + c.address + ':' + c.port); }
|
|
118
|
+
add(c.uri);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
// Adds one of onServers' list: its first link that answers as that server, kept.
|
|
124
|
+
function add(res) {
|
|
125
|
+
var list = candidates(res), tried = [];
|
|
126
|
+
function next(i) {
|
|
127
|
+
if (i >= list.length) { return Promise.reject(new Error('No address of “' + res.name + '” answered' + (tried.length ? ' (' + tried.join(', ') + ')' : '') + '.')); }
|
|
128
|
+
return U.getJSON(list[i] + '/identity', 6000, 65536, null, { 'Accept': 'application/json' }, null, true).then(function (r) {
|
|
129
|
+
if (('' + mc(r).machineIdentifier) !== res.machineId) { throw new Error('another server'); }
|
|
130
|
+
return list[i];
|
|
131
|
+
}).then(null, function (e) { tried.push(list[i]); U.log('plex', '“' + res.name + '” didn’t answer at ' + list[i] + ' (' + U.problem(e) + ')'); return next(i + 1); });
|
|
132
|
+
}
|
|
133
|
+
return next(0).then(function (url) {
|
|
134
|
+
var all = servers(), old = all.filter(function (s) { return s.machineId === res.machineId; })[0];
|
|
135
|
+
var srv = { id: old ? old.id : 'p' + rand(8), kind: 'plex', url: url, machineId: res.machineId, name: res.name, version: res.version,
|
|
136
|
+
user: res.user, owned: res.owned, token: res.token, at: Date.now() };
|
|
137
|
+
all = all.filter(function (s) { return s !== old; });
|
|
138
|
+
all.push(srv);
|
|
139
|
+
U.store.set(KEY, all);
|
|
140
|
+
forget(srv.id);
|
|
141
|
+
U.log('plex', 'Signed in to “' + srv.name + '” (Plex ' + srv.version + ')' + (srv.user ? ' as ' + srv.user : ''));
|
|
142
|
+
return refreshLibs(true, srv.id).then(function () { changed(); return srv; });
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function remove(id) {
|
|
146
|
+
if (!server(id)) { return; }
|
|
147
|
+
U.store.set(KEY, servers().filter(function (s) { return s.id !== id; }));
|
|
148
|
+
var libs = libsAll();
|
|
149
|
+
delete libs[id];
|
|
150
|
+
U.store.set(LIBS_KEY, libs);
|
|
151
|
+
forget(id);
|
|
152
|
+
fillCatalogs();
|
|
153
|
+
changed();
|
|
154
|
+
}
|
|
155
|
+
function reload(id) {
|
|
156
|
+
if (!server(id)) { return; }
|
|
157
|
+
forget(id);
|
|
158
|
+
delete _libsAsked[id];
|
|
159
|
+
refreshLibs(true, id);
|
|
160
|
+
}
|
|
161
|
+
function forget(id) {
|
|
162
|
+
delete _index[id];
|
|
163
|
+
_items.clear(); _eps.clear();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ---- Libraries: the catalogs, kept a day (U.store) so Home has its rows at launch ----
|
|
167
|
+
var _libs = null, _libsAsked = {};
|
|
168
|
+
function libsAll() {
|
|
169
|
+
if (!_libs) { var l = U.store.get(LIBS_KEY, {}); _libs = l && typeof l === 'object' && !Array.isArray(l) ? l : {}; }
|
|
170
|
+
return _libs;
|
|
171
|
+
}
|
|
172
|
+
function libsOf(srv) { var l = libsAll()[srv.id]; return l && Array.isArray(l.list) ? l.list : []; }
|
|
173
|
+
function refreshLibs(force, only) {
|
|
174
|
+
return Promise.all(servers().map(function (srv) {
|
|
175
|
+
if (only && srv.id !== only) { return null; }
|
|
176
|
+
var l = libsAll()[srv.id];
|
|
177
|
+
if (!force && ((l && Date.now() - l.at < LIBS_FRESH_MS) || _libsAsked[srv.id])) { return null; }
|
|
178
|
+
_libsAsked[srv.id] = true;
|
|
179
|
+
return get(srv, '/library/sections').then(function (r) {
|
|
180
|
+
var list = U.listOf(mc(r).Directory, 50, function (x) { return x.key != null && (x.type === 'movie' || x.type === 'show'); }).map(function (x) {
|
|
181
|
+
return { id: clean(x.key, 20), name: clean(x.title) || (x.type === 'movie' ? 'Movies' : 'Shows'), type: x.type === 'movie' ? 'movie' : 'series' };
|
|
182
|
+
});
|
|
183
|
+
if (!server(srv.id)) { return; }
|
|
184
|
+
var all = libsAll(), keep = {}, before = JSON.stringify(all[srv.id] && all[srv.id].list);
|
|
185
|
+
servers().forEach(function (s) { if (all[s.id]) { keep[s.id] = all[s.id]; } });
|
|
186
|
+
keep[srv.id] = { at: Date.now(), list: list };
|
|
187
|
+
_libs = keep;
|
|
188
|
+
U.store.set(LIBS_KEY, keep);
|
|
189
|
+
fillCatalogs();
|
|
190
|
+
if (JSON.stringify(list) !== before || force) { changed(); }
|
|
191
|
+
}, function (e) { U.log('plex', '“' + srv.name + '”: its libraries couldn’t be read (' + U.problem(e) + ')'); });
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ---- The addon ("Plex": its rows say so, Source ranking lists it) ----
|
|
196
|
+
var _addon = null;
|
|
197
|
+
var RESOURCES = ['catalog', { name: 'stream', types: ['movie', 'series'], idPrefixes: ['tt', 'tmdb:'] }];
|
|
198
|
+
function catalogsNow() {
|
|
199
|
+
var out = [], many = servers().length > 1;
|
|
200
|
+
servers().forEach(function (srv) {
|
|
201
|
+
var libs = libsOf(srv), on = many ? ' · ' + srv.name : '';
|
|
202
|
+
if (!libs.length) { return; }
|
|
203
|
+
if (libs.some(function (l) { return l.type === 'movie'; })) { out.push({ type: 'movie', id: 'px.' + srv.id + '.resume', name: 'Continue watching' + on, extra: [] }); }
|
|
204
|
+
if (libs.some(function (l) { return l.type === 'series'; })) { out.push({ type: 'series', id: 'px.' + srv.id + '.nextup', name: 'Next up' + on, extra: [] }); }
|
|
205
|
+
libs.forEach(function (lib) {
|
|
206
|
+
out.push({ type: lib.type, id: 'px.' + srv.id + '.' + lib.id, name: lib.name + on, extra: [{ name: 'search' }, { name: 'skip' }] });
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
function fillCatalogs() {
|
|
212
|
+
if (!_addon) { return; }
|
|
213
|
+
var l = _addon.manifest.catalogs;
|
|
214
|
+
l.splice.apply(l, [0, l.length].concat(catalogsNow()));
|
|
215
|
+
_addon.manifest.resources = isEnabled() ? RESOURCES : ['catalog'];
|
|
216
|
+
}
|
|
217
|
+
function synthAddon() {
|
|
218
|
+
if (!_addon) {
|
|
219
|
+
_addon = { __local: true, __sources: true, url: 'local:plex', base: 'local:plex',
|
|
220
|
+
__impl: { catalog: catalog, meta: meta, streams: streams },
|
|
221
|
+
manifest: { id: 'org.stremiok.plex', name: 'Plex', version: '1.0.0', types: ['movie', 'series'], resources: RESOURCES, catalogs: [] } };
|
|
222
|
+
}
|
|
223
|
+
fillCatalogs();
|
|
224
|
+
refreshLibs(false);
|
|
225
|
+
return _addon;
|
|
226
|
+
}
|
|
227
|
+
function synthAddons() { return isEnabled() ? [synthAddon()] : []; }
|
|
228
|
+
|
|
229
|
+
// ---- Titles ----
|
|
230
|
+
// Its ids: includeGuids' list (imdb://tt…, tmdb://…), or an older agent's guid
|
|
231
|
+
// (com.plexapp.agents.imdb://tt…?lang=en, …themoviedb://…).
|
|
232
|
+
function guids(it) {
|
|
233
|
+
var l = U.listOf(it && it.Guid, 20).map(function (g) { return '' + (g && g.id); });
|
|
234
|
+
if (it && it.guid) { l.push('' + it.guid); }
|
|
235
|
+
return l;
|
|
236
|
+
}
|
|
237
|
+
function imdbOf(it) {
|
|
238
|
+
var m = null;
|
|
239
|
+
guids(it).some(function (g) { m = /(?:^imdb|agents\.imdb):\/\/(tt\d{5,10})/.exec(g); return !!m; });
|
|
240
|
+
return m ? m[1] : '';
|
|
241
|
+
}
|
|
242
|
+
function tmdbOf(it) {
|
|
243
|
+
var m = null;
|
|
244
|
+
guids(it).some(function (g) { m = /(?:^tmdb|agents\.themoviedb):\/\/(\d{1,10})(?:\D|$)/.exec(g); return !!m; });
|
|
245
|
+
return m ? m[1] : '';
|
|
246
|
+
}
|
|
247
|
+
function img(srv, path, w, h) {
|
|
248
|
+
if (!path) { return ''; }
|
|
249
|
+
if (/^https?:\/\//i.test(path)) { return '' + path; }
|
|
250
|
+
return linkOf(srv, '/photo/:/transcode?width=' + w + '&height=' + h + '&minSize=1&upscale=1&url=' + enc(path));
|
|
251
|
+
}
|
|
252
|
+
function cardOf(srv, type, it) {
|
|
253
|
+
if (!it || it.ratingKey == null || !it.title) { return null; }
|
|
254
|
+
var tt = imdbOf(it);
|
|
255
|
+
var m = { id: tt || ((type === 'movie' ? 'pxm.' : 'pxs.') + srv.id + '.' + it.ratingKey), type: type, name: clean(it.title, 200), posterShape: 'poster' };
|
|
256
|
+
if (it.thumb) { m.poster = img(srv, it.thumb, 300, 450); }
|
|
257
|
+
if (it.art) { m.background = img(srv, it.art, 1280, 720); }
|
|
258
|
+
if (+it.year > 1880) { m.releaseInfo = '' + it.year; }
|
|
259
|
+
var r = parseFloat(it.audienceRating || it.rating);
|
|
260
|
+
if (r > 0 && r <= 10) { m.imdbRating = r.toFixed(1); }
|
|
261
|
+
return m;
|
|
262
|
+
}
|
|
263
|
+
// On Deck: films part-watched (Continue watching), and a show's next episode or the one
|
|
264
|
+
// part-watched (Next up: its card opens at that episode, _openEp).
|
|
265
|
+
function onDeck(srv) {
|
|
266
|
+
return get(srv, '/library/onDeck?includeGuids=1').then(null, function () { return get(srv, '/hubs/continueWatching/items?includeGuids=1'); }).then(function (r) {
|
|
267
|
+
return U.listOf(mc(r).Metadata, 100);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function resumeCards(srv) {
|
|
271
|
+
return onDeck(srv).then(function (l) {
|
|
272
|
+
return l.filter(function (it) { return it.type === 'movie'; }).slice(0, 50).map(function (it) { return cardOf(srv, 'movie', it); }).filter(Boolean);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function nextUpCards(srv) {
|
|
276
|
+
return Promise.all([onDeck(srv), index(srv)]).then(function (r) {
|
|
277
|
+
var seen = {};
|
|
278
|
+
return r[0].filter(function (e) { return e.type === 'episode' && e.grandparentRatingKey != null && e.parentIndex >= 0 && e.index >= 0; }).map(function (e) {
|
|
279
|
+
var sid = '' + e.grandparentRatingKey, show = (r[1].__ids || {})[sid] || ('pxs.' + srv.id + '.' + sid);
|
|
280
|
+
if (seen[show]) { return null; }
|
|
281
|
+
seen[show] = 1;
|
|
282
|
+
var m = { id: show, type: 'series', name: clean(e.grandparentTitle || e.title, 200), posterShape: 'poster',
|
|
283
|
+
_openEp: show + ':' + e.parentIndex + ':' + e.index, _ep: 'S' + e.parentIndex + 'E' + e.index };
|
|
284
|
+
if (e.grandparentThumb) { m.poster = img(srv, e.grandparentThumb, 300, 450); }
|
|
285
|
+
if (e.grandparentArt || e.art) { m.background = img(srv, e.grandparentArt || e.art, 1280, 720); }
|
|
286
|
+
return m.name ? m : null;
|
|
287
|
+
}).filter(Boolean).slice(0, 50);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
function catalog(catId, extra) {
|
|
291
|
+
var m = /^px\.([^.]+)\.([^.]+)$/.exec(catId || ''), srv = m && server(m[1]);
|
|
292
|
+
if (srv && m[2] === 'resume') { return resumeCards(srv); }
|
|
293
|
+
if (srv && m[2] === 'nextup') { return nextUpCards(srv); }
|
|
294
|
+
var lib = srv && libsOf(srv).filter(function (l) { return l.id === m[2]; })[0];
|
|
295
|
+
if (!lib) { return Promise.resolve([]); }
|
|
296
|
+
var skip = extra && extra.skip ? (parseInt(extra.skip, 10) || 0) : 0, term = extra && extra.search ? ('' + extra.search).slice(0, 120) : '';
|
|
297
|
+
var path = '/library/sections/' + enc(lib.id) + '/all?type=' + (lib.type === 'movie' ? 1 : 2) + '&includeGuids=1' +
|
|
298
|
+
(term ? '&title=' + enc(term) + '&sort=titleSort' : '&sort=addedAt:desc') + '&X-Plex-Container-Start=' + skip + '&X-Plex-Container-Size=' + PAGE;
|
|
299
|
+
return get(srv, path).then(function (r) {
|
|
300
|
+
return U.listOf(mc(r).Metadata, PAGE).map(function (it) { return cardOf(srv, lib.type, it); }).filter(Boolean);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
var _items = U.lru(40), _eps = U.lru(20);
|
|
304
|
+
function kept(cache, k, make) {
|
|
305
|
+
var p = cache.get(k);
|
|
306
|
+
if (p) { return p; }
|
|
307
|
+
p = make();
|
|
308
|
+
cache.set(k, p);
|
|
309
|
+
p.then(null, function () { if (cache.get(k) === p) { cache.set(k, null); } });
|
|
310
|
+
return p;
|
|
311
|
+
}
|
|
312
|
+
// A film, show or episode in full: its versions and their streams, markers and chapters.
|
|
313
|
+
function item(srv, rk) {
|
|
314
|
+
return kept(_items, srv.id + '|' + rk, function () {
|
|
315
|
+
return get(srv, '/library/metadata/' + enc(rk) + '?includeGuids=1&includeMarkers=1&includeChapters=1').then(function (r) { return U.listOf(mc(r).Metadata, 1)[0] || null; });
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
// A show's episodes: [{ season, episode, it }] (it: as listed, without its streams).
|
|
319
|
+
function episodes(srv, sid) {
|
|
320
|
+
return kept(_eps, srv.id + '|' + sid, function () {
|
|
321
|
+
return get(srv, '/library/metadata/' + enc(sid) + '/allLeaves', 16 * 1048576).then(function (r) {
|
|
322
|
+
return U.listOf(mc(r).Metadata, 5000, function (e) { return e.ratingKey != null && e.parentIndex >= 0 && e.index >= 0; }).map(function (e) {
|
|
323
|
+
return { season: +e.parentIndex, episode: +e.index, it: e };
|
|
324
|
+
}).sort(function (a, b) { return a.season - b.season || a.episode - b.episode; });
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function parseId(id) {
|
|
329
|
+
var m = /^px([ms])\.([^.]+)\.(\d{1,12})(?::(\d+):(\d+))?$/.exec('' + id);
|
|
330
|
+
return m ? { kind: m[1], srv: server(m[2]), item: m[3], season: m[4] != null ? +m[4] : null, episode: m[5] != null ? +m[5] : null } : null;
|
|
331
|
+
}
|
|
332
|
+
function tags(l) { return U.listOf(l, 200, function (t) { return t && t.tag; }).slice(0, 12).map(function (t) { return clean(t.tag, 80); }); }
|
|
333
|
+
function meta(type, id) {
|
|
334
|
+
var x = parseId(id);
|
|
335
|
+
if (!x || !x.srv) { return Promise.resolve(null); }
|
|
336
|
+
var srv = x.srv, t = x.kind === 'm' ? 'movie' : 'series';
|
|
337
|
+
return item(srv, x.item).then(function (it) {
|
|
338
|
+
if (!it || !it.title) { return null; }
|
|
339
|
+
var showId = 'px' + x.kind + '.' + srv.id + '.' + it.ratingKey, m = cardOf(srv, t, it);
|
|
340
|
+
m.id = showId; m._from = srv.name;
|
|
341
|
+
if (it.summary) { m.description = ('' + it.summary).slice(0, 2000); }
|
|
342
|
+
if (tags(it.Genre).length) { m.genres = tags(it.Genre); }
|
|
343
|
+
if (tags(it.Role).length) { m.cast = tags(it.Role); }
|
|
344
|
+
if (tags(it.Director).length) { m.director = tags(it.Director); }
|
|
345
|
+
if (+it.duration > 0 && t === 'movie') { m.runtime = Math.round(it.duration / 60000) + ' min'; }
|
|
346
|
+
if (m.releaseInfo) { m.year = m.releaseInfo; }
|
|
347
|
+
if (t === 'movie') { return m; }
|
|
348
|
+
return episodes(srv, it.ratingKey).then(function (eps) {
|
|
349
|
+
m.videos = eps.map(function (e) {
|
|
350
|
+
var v = { id: showId + ':' + e.season + ':' + e.episode, season: e.season, episode: e.episode, title: clean(e.it.title, 200) || 'Episode ' + e.episode };
|
|
351
|
+
if (e.it.summary) { v.overview = ('' + e.it.summary).slice(0, 1000); }
|
|
352
|
+
if (e.it.thumb) { v.thumbnail = img(srv, e.it.thumb, 640, 360); }
|
|
353
|
+
var rel = Date.parse(e.it.originallyAvailableAt || '');
|
|
354
|
+
if (rel) { v.released = new Date(rel).toISOString(); }
|
|
355
|
+
return v;
|
|
356
|
+
});
|
|
357
|
+
return m;
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ---- Which titles each server has (for titles from your addons) ----
|
|
363
|
+
var _index = {};
|
|
364
|
+
function index(srv) {
|
|
365
|
+
var x = _index[srv.id];
|
|
366
|
+
if (x && x.map && (x.p || Date.now() - x.at < INDEX_FRESH_MS)) { return Promise.resolve(x.map); }
|
|
367
|
+
if (x && x.p) { return x.p; }
|
|
368
|
+
var p = Promise.all(libsOf(srv).map(function (lib) {
|
|
369
|
+
return get(srv, '/library/sections/' + enc(lib.id) + '/all?type=' + (lib.type === 'movie' ? 1 : 2) + '&includeGuids=1', 16 * 1048576).then(function (r) {
|
|
370
|
+
return U.listOf(mc(r).Metadata, 100000).map(function (it) { return { t: lib.type, it: it }; });
|
|
371
|
+
});
|
|
372
|
+
})).then(function (lists) {
|
|
373
|
+
var map = { __ids: {} };
|
|
374
|
+
function add(k, v) { (map[k] = map[k] || []).push(v); }
|
|
375
|
+
flat(lists).forEach(function (e) {
|
|
376
|
+
var it = e.it, tt = imdbOf(it), tm = tmdbOf(it);
|
|
377
|
+
if (it.ratingKey == null) { return; }
|
|
378
|
+
if (tt) { add(e.t + '|' + tt, '' + it.ratingKey); map.__ids['' + it.ratingKey] = tt; }
|
|
379
|
+
if (tm) { add(e.t + '|tmdb:' + tm, '' + it.ratingKey); }
|
|
380
|
+
});
|
|
381
|
+
if (_index[srv.id] && _index[srv.id].p === p) { _index[srv.id] = { at: Date.now(), map: map }; }
|
|
382
|
+
return map;
|
|
383
|
+
}, function (e) {
|
|
384
|
+
U.log('plex', '“' + srv.name + '”: its titles couldn’t be read (' + U.problem(e) + ')');
|
|
385
|
+
var old = _index[srv.id], map = (old && old.map) || { __ids: {} };
|
|
386
|
+
if (old && old.p === p) { _index[srv.id] = { at: Date.now() - INDEX_FRESH_MS + INDEX_RETRY_MS, map: map }; }
|
|
387
|
+
return map;
|
|
388
|
+
});
|
|
389
|
+
_index[srv.id] = { at: x ? x.at : 0, map: x ? x.map : null, p: p };
|
|
390
|
+
return x && x.map ? Promise.resolve(x.map) : p;
|
|
391
|
+
}
|
|
392
|
+
function copies(type, id) {
|
|
393
|
+
var key = '', season = null, episode = null;
|
|
394
|
+
if (type === 'movie') { key = /^(tt\d+|tmdb:\d+)$/.test('' + id) ? '' + id : ''; }
|
|
395
|
+
else if (type === 'series') {
|
|
396
|
+
var mm = /^(tt\d+|tmdb:\d+):(\d+):(\d+)$/.exec('' + id);
|
|
397
|
+
if (mm) { key = mm[1]; season = +mm[2]; episode = +mm[3]; }
|
|
398
|
+
}
|
|
399
|
+
if (!key) { return Promise.resolve([]); }
|
|
400
|
+
return Promise.all(servers().map(function (srv) {
|
|
401
|
+
return index(srv).then(function (map) {
|
|
402
|
+
return Promise.all((map[type + '|' + key] || []).slice(0, 3).map(function (rk) {
|
|
403
|
+
return type === 'movie' ? item(srv, rk).then(function (it) { return sourcesOf(srv, it); }, none) : episodeSources(srv, rk, season, episode);
|
|
404
|
+
}));
|
|
405
|
+
}).then(flat, none);
|
|
406
|
+
})).then(flat);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// ---- Sources ----
|
|
410
|
+
var SUB_CODECS = /^(srt|subrip|vtt|webvtt)$/i;
|
|
411
|
+
function share() { return (typeof Jellyfin !== 'undefined' && Jellyfin.shared) || null; }
|
|
412
|
+
function quality(w, h) { return w >= 3200 || h >= 1600 ? '4K' : w >= 1800 || h >= 900 ? '1080p' : w >= 1200 || h >= 600 ? '720p' : h > 0 ? h + 'p' : ''; }
|
|
413
|
+
function human(n) { return n >= 1073741824 ? (n / 1073741824).toFixed(1) + ' GB' : Math.max(1, Math.round(n / 1048576)) + ' MB'; }
|
|
414
|
+
function source(srv, it, media, part) {
|
|
415
|
+
var all = U.listOf(part.Stream, 200), v = all.filter(function (s) { return +s.streamType === 1; })[0] || {};
|
|
416
|
+
var hdr = v.DOVIPresent || /dovi|dolby vision/i.test('' + (v.displayTitle || '')) ? 'DV' : /smpte2084|arib-std-b67/i.test('' + (v.colorTrc || '')) || /hdr|hlg/i.test('' + (v.displayTitle || '')) ? 'HDR' : '';
|
|
417
|
+
var w = +media.width || +v.width || 0, h = +media.height || +v.height || 0, q = quality(w, h);
|
|
418
|
+
var ext = ('' + (part.container || media.container || 'mkv')).toLowerCase().replace(/[^a-z0-9]/g, '').slice(0, 5) || 'mkv', size = +part.size || 0;
|
|
419
|
+
var file = ('' + (part.file || it.title || '')).split(/[\/\\]/).pop() || ('' + it.title);
|
|
420
|
+
var st = {
|
|
421
|
+
url: linkOf(srv, '' + part.key),
|
|
422
|
+
name: 'Plex' + (q ? '\n' + q + (hdr ? ' ' + hdr : '') : ''),
|
|
423
|
+
title: file + '\n' + srv.name + (size ? ' · 💾 ' + human(size) : '') + ' · ' + ext.toUpperCase(),
|
|
424
|
+
behaviorHints: { filename: file, videoSize: size || undefined, bingeGroup: 'stremiok-plex-' + srv.id },
|
|
425
|
+
_jf: placeOf({ srv: srv.id, kind: 'plex', item: '' + it.ratingKey, ms: '' + part.id, dur: Math.round((+it.duration || +media.duration || 0) / 1000) }, it)
|
|
426
|
+
};
|
|
427
|
+
var sh = share(), asJf = { Chapters: chaptersOf(it), RunTimeTicks: (+it.duration || 0) * 10000 };
|
|
428
|
+
var ch = sh && sh.chapterSegments(asJf), named = sh && sh.namedChapters(asJf), mk = markersOf(it), tp = picturesOf(srv, part, st._jf.dur, w, h);
|
|
429
|
+
if (ch) { st._jf.ch = ch; }
|
|
430
|
+
if (mk) { st._jf.mk = mk; }
|
|
431
|
+
if (named) { st._jf.chapters = named; }
|
|
432
|
+
if (tp) { st._jf.tp = tp; }
|
|
433
|
+
var subs = all.filter(function (s) { return +s.streamType === 3 && s.key && SUB_CODECS.test('' + (s.codec || '')); }).slice(0, 30).map(function (s) {
|
|
434
|
+
return { id: 'px' + s.id, url: linkOf(srv, '' + s.key), lang: ('' + (s.languageCode || s.language || '')).slice(0, 12) };
|
|
435
|
+
});
|
|
436
|
+
if (subs.length) { st.subtitles = subs; }
|
|
437
|
+
return st;
|
|
438
|
+
}
|
|
439
|
+
// Where Plex last had it (any of its apps): pos seconds (0: finished or not started), at when.
|
|
440
|
+
function placeOf(jf, it) {
|
|
441
|
+
var at = +(it && it.lastViewedAt) || 0;
|
|
442
|
+
if (at > 0) { jf.at = at * 1000; jf.pos = Math.max(0, Math.round((+it.viewOffset || 0) / 1000)); }
|
|
443
|
+
return jf;
|
|
444
|
+
}
|
|
445
|
+
// Its chapters in Jellyfin's shape (Name, StartPositionTicks), for the shared readers.
|
|
446
|
+
function chaptersOf(it) {
|
|
447
|
+
return U.listOf(it && it.Chapter, 200, function (c) { return c && +c.startTimeOffset >= 0; }).map(function (c) {
|
|
448
|
+
return { Name: c.tag == null ? '' : '' + c.tag, StartPositionTicks: +c.startTimeOffset * 10000 };
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
// Its intro and credits markers: { intro: [{ start, end }], credits }, seconds; or null.
|
|
452
|
+
function markersOf(it) {
|
|
453
|
+
var out = null;
|
|
454
|
+
U.listOf(it && it.Marker, 20, function (k) { return k && (k.type === 'intro' || k.type === 'credits') && +k.endTimeOffset > +k.startTimeOffset && +k.startTimeOffset >= 0; }).forEach(function (k) {
|
|
455
|
+
out = out || {};
|
|
456
|
+
(out[k.type] = out[k.type] || []).push({ start: +k.startTimeOffset / 1000, end: +k.endTimeOffset / 1000 });
|
|
457
|
+
});
|
|
458
|
+
return out;
|
|
459
|
+
}
|
|
460
|
+
// Its seek pictures (video preview thumbnails, when the server made them: indexes="sd"): one
|
|
461
|
+
// picture a link, every PIC_EVERY (the server answers with the nearest).
|
|
462
|
+
function picturesOf(srv, part, dur, w, h) {
|
|
463
|
+
if (!/(^|,)sd(,|$)/.test('' + (part.indexes || '')) || !(dur > 0)) { return null; }
|
|
464
|
+
return { one: true, w: 320, h: w > 0 && h > 0 ? Math.round(320 * h / w) : 180, cols: 1, rows: 1, n: Math.ceil(dur * 1000 / PIC_EVERY), every: PIC_EVERY,
|
|
465
|
+
base: srv.url + '/library/parts/' + enc(part.id) + '/indexes/sd/', q: '?X-Plex-Token=' + enc(srv.token) };
|
|
466
|
+
}
|
|
467
|
+
function sourcesOf(srv, it) {
|
|
468
|
+
if (!it || it.ratingKey == null) { return []; }
|
|
469
|
+
var out = [];
|
|
470
|
+
U.listOf(it.Media, 8).forEach(function (media) {
|
|
471
|
+
U.listOf(media.Part, 4, function (p) { return p && p.key && p.id != null; }).slice(0, 1).forEach(function (part) { out.push(source(srv, it, media, part)); });
|
|
472
|
+
});
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
function episodeSources(srv, sid, season, episode) {
|
|
476
|
+
return episodes(srv, sid).then(function (eps) {
|
|
477
|
+
var e = eps.filter(function (x) { return x.season === season && x.episode === episode; })[0];
|
|
478
|
+
return e ? item(srv, e.it.ratingKey).then(function (it) { return sourcesOf(srv, it); }, none) : [];
|
|
479
|
+
}, none);
|
|
480
|
+
}
|
|
481
|
+
function streams(type, id) {
|
|
482
|
+
var x = parseId(id);
|
|
483
|
+
if (x) {
|
|
484
|
+
if (!x.srv) { return Promise.resolve([]); }
|
|
485
|
+
if (x.kind === 'm') { return item(x.srv, x.item).then(function (it) { return sourcesOf(x.srv, it); }, none); }
|
|
486
|
+
return x.season != null ? episodeSources(x.srv, x.item, x.season, x.episode) : Promise.resolve([]);
|
|
487
|
+
}
|
|
488
|
+
return copies(type, id);
|
|
489
|
+
}
|
|
490
|
+
function isPlexId(id) { return /^px[ms]\./.test('' + id); }
|
|
491
|
+
|
|
492
|
+
// ---- What you play, back to Plex (its timeline) ----
|
|
493
|
+
// From the player (through Jellyfin.onPlayer): 'progress', 'pause', 'stop', 'watched'. Nothing
|
|
494
|
+
// during private viewing, for a trailer, or another source.
|
|
495
|
+
var _play = null;
|
|
496
|
+
function report(p, state, cur) {
|
|
497
|
+
var srv = server(p.srv);
|
|
498
|
+
if (!srv) { return; }
|
|
499
|
+
tell(srv, '/:/timeline?ratingKey=' + enc(p.item) + '&key=' + enc('/library/metadata/' + p.item) + '&identifier=com.plexapp.plugins.library&state=' + state +
|
|
500
|
+
'&time=' + Math.max(0, Math.round((cur || 0) * 1000)) + '&duration=' + Math.max(0, Math.round((p.dur || 0) * 1000))).then(null, function (e) {
|
|
501
|
+
U.log('plex', '“' + srv.name + '” wasn’t told where you are (' + U.problem(e) + ')');
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
function stopNow(cur) {
|
|
505
|
+
var p = _play;
|
|
506
|
+
_play = null;
|
|
507
|
+
if (p && p.started) { report(p, 'stopped', cur != null ? cur : p.cur); }
|
|
508
|
+
}
|
|
509
|
+
function onPlayer(ev, ctx, cur, dur, paused) {
|
|
510
|
+
var jf = ctx && !ctx.private && !ctx.trailer && ctx.stream && ctx.stream._jf, srv = jf && jf.kind === 'plex' && server(jf.srv);
|
|
511
|
+
if (ev === 'watched') {
|
|
512
|
+
if (srv) { tell(srv, '/:/scrobble?identifier=com.plexapp.plugins.library&key=' + enc(jf.item)).then(null, function (e) { U.log('plex', '“' + srv.name + '”: not marked played (' + U.problem(e) + ')'); }); }
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (_play && (!srv || _play.ctx !== ctx || _play.item !== jf.item || _play.ms !== jf.ms)) { stopNow(); }
|
|
516
|
+
if (!srv || ev === 'stop') { if (ev === 'stop') { stopNow(cur); } return; }
|
|
517
|
+
if (!_play) { _play = { ctx: ctx, srv: srv.id, item: jf.item, ms: jf.ms, dur: dur || jf.dur, started: false, sent: 0, paused: false, cur: 0 }; }
|
|
518
|
+
var p = _play, now = Date.now(), pz = ev === 'pause' || !!paused;
|
|
519
|
+
if (dur > 0) { p.dur = dur; }
|
|
520
|
+
if (cur > 0) { p.cur = cur; }
|
|
521
|
+
if (!(cur > 0)) { return; }
|
|
522
|
+
if (!p.started || pz !== p.paused || now - p.sent >= REPORT_EVERY) { p.started = true; p.sent = now; p.paused = pz; report(p, pz ? 'paused' : 'playing', cur); }
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return {
|
|
526
|
+
servers: servers, server: server, isEnabled: isEnabled, onChange: onChange, link: link, add: add, remove: remove, reload: reload,
|
|
527
|
+
libraries: libsOf, synthAddon: synthAddon, synthAddons: synthAddons, catalog: catalog, meta: meta, streams: streams, isPlexId: isPlexId,
|
|
528
|
+
onPlayer: onPlayer, candidates: candidates
|
|
529
|
+
};
|
|
530
|
+
})();
|
package/js/stremio.js
CHANGED
|
@@ -162,6 +162,8 @@ var Stremio = (function () {
|
|
|
162
162
|
function getPrefs() {
|
|
163
163
|
var p = U.store.get(PREFS_KEY, {}) || {};
|
|
164
164
|
return { posterShape: p.posterShape || 'portrait', accent: p.accent || 'indigo', bg: p.bg || 'dark',
|
|
165
|
+
look: p.look === 'modern' ? 'modern' : 'classic', // Settings > Appearance: Classic, or Modern (a backdrop behind Home, the title's logo, rounder posters)
|
|
166
|
+
effects: p.effects === 'light' || p.effects === 'full' ? p.effects : 'auto', // ...Modern's blur and motion: by the TV (auto), off (light) or on (full)
|
|
165
167
|
zoom: [110, 120, 130, 140].indexOf(p.zoom) !== -1 ? p.zoom : 100, // Settings > Appearance: everything bigger (percent)
|
|
166
168
|
rowCards: p.rowCards === 'all' || [50, 100, 200].indexOf(p.rowCards) !== -1 ? p.rowCards : 30, // Settings > Home: titles in a Home row ('all': Unlimited)
|
|
167
169
|
formatsAuto: p.formatsAuto !== false, // Settings > Formats: mark "Not working" on its own
|
|
@@ -292,7 +294,7 @@ var Stremio = (function () {
|
|
|
292
294
|
var APP_FIELDS = {};
|
|
293
295
|
['_addon', '_addonPos', '_addonRank', '_also', '_cardImage', '_posterAlt', '_from', '_headers', '_keepStream', '_playlistId', '_reported', '_yt', '_file',
|
|
294
296
|
'_group', '_local', '_localSubs', '_tmdbWhere', '_trakt', '_dupes', '_restoreKey', '_current', '_autoFocus', '_epFocus', '_focusNp', '_focusPill',
|
|
295
|
-
'_focusSeason', '_focusTrailer', '_earlier', '_localFile', '_torrent', '_pickFile', 'stale', 'ytPage'].forEach(function (k) { APP_FIELDS[k] = 1; });
|
|
297
|
+
'_focusSeason', '_focusTrailer', '_earlier', '_localFile', '_torrent', '_pickFile', '_jf', '_openEp', 'stale', 'ytPage'].forEach(function (k) { APP_FIELDS[k] = 1; });
|
|
296
298
|
function fieldSet(list) { var o = {}; list.forEach(function (k) { o[k] = 1; }); return o; }
|
|
297
299
|
var STR_FIELDS = fieldSet(['id', 'type', 'name', 'title', 'description', 'poster', 'background', 'logo', 'thumbnail', 'banner', 'url', 'externalUrl', 'ytId',
|
|
298
300
|
'infoHash', 'releaseInfo', 'released', 'imdb_id', 'lang', 'filename', 'bingeGroup', 'posterShape', 'runtime']);
|
|
@@ -438,6 +440,8 @@ var Stremio = (function () {
|
|
|
438
440
|
else if (iptvOn) { iptvJoin(addons, rev); }
|
|
439
441
|
if (typeof XtVod !== 'undefined' && XtVod.isEnabled()) { addons.push(XtVod.synthAddon()); } // (your Xtream accounts' films and series: after your addons)
|
|
440
442
|
if (typeof StVod !== 'undefined' && StVod.isEnabled()) { addons.push(StVod.synthAddon()); } // (your Stalker portals' films and series)
|
|
443
|
+
if (typeof Jellyfin !== 'undefined') { Jellyfin.synthAddons().forEach(function (a) { addons.push(a); }); } // (your Jellyfin and Emby servers' libraries: one addon a kind)
|
|
444
|
+
if (typeof Plex !== 'undefined') { Plex.synthAddons().forEach(function (a) { addons.push(a); }); } // (your Plex servers')
|
|
441
445
|
if (hasYouTube()) { addons.push(YouTube.synthAddon()); } // (after your addons: its rows last on Home)
|
|
442
446
|
if (typeof Trakt !== 'undefined' && Trakt.isConnected()) { addons.push(Trakt.synthAddon()); } // (your Watchlist and Up next)
|
|
443
447
|
_loaded = addons;
|
|
@@ -524,6 +528,20 @@ var Stremio = (function () {
|
|
|
524
528
|
if (typeof XtVod !== 'undefined' && XtVod.onVodChange) { XtVod.onVodChange(iptvRebuild); }
|
|
525
529
|
if (typeof XtVod !== 'undefined' && XtVod.onChange) { XtVod.onChange(function () { sourcesChanged(); }); } // (its list read: its copies, on titles asked before)
|
|
526
530
|
if (typeof StVod !== 'undefined' && StVod.onChange) { StVod.onChange(function () { sourcesChanged(); }); } // (a portal's films and series: its copies too)
|
|
531
|
+
// A Jellyfin or Emby server added, removed or its libraries read: the addons made again when
|
|
532
|
+
// one of their kinds joins or leaves them, else its copies asked again.
|
|
533
|
+
if (typeof Jellyfin !== 'undefined' && Jellyfin.onChange) {
|
|
534
|
+
Jellyfin.onChange(function () {
|
|
535
|
+
var has = _loaded ? _loaded.filter(function (a) { return /^local:(jellyfin|emby)$/.test(a.url); }).map(function (a) { return a.url; }).join() : null;
|
|
536
|
+
if (has === Jellyfin.kindsOn().map(function (k) { return 'local:' + k; }).join()) { sourcesChanged(); } else { configChanged(); }
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
if (typeof Plex !== 'undefined' && Plex.onChange) { // (a Plex server: the same)
|
|
540
|
+
Plex.onChange(function () {
|
|
541
|
+
var has = _loaded ? _loaded.some(function (a) { return a.url === 'local:plex'; }) : null;
|
|
542
|
+
if (has === Plex.isEnabled()) { sourcesChanged(); } else { configChanged(); }
|
|
543
|
+
});
|
|
544
|
+
}
|
|
527
545
|
function iptvReload(id) {
|
|
528
546
|
configChanged();
|
|
529
547
|
return _hasIptv ? IPTV.reload(id) : Promise.resolve(null);
|
|
@@ -553,7 +571,7 @@ var Stremio = (function () {
|
|
|
553
571
|
var EXPORT_LINE = '#!stremiok ';
|
|
554
572
|
var EXPORT_STORE = ['stremiok.prefs', 'stremiok.feeds', 'stremiok.searchfeeds', 'stremiok.sourcefeeds', 'stremiok.ranking', 'stremiok.server', 'stremiok.formats',
|
|
555
573
|
'stremiok.resblock', 'stremiok.subcfg', 'stremiok.audiocfg', 'stremiok.playercfg', 'stremiok.private', 'stremiok.youtube', 'stremiok.appshortcuts',
|
|
556
|
-
'stremiok.appsallowed', 'stremiok.aiomanager', 'stremiok.iptv.stalkerall', 'stremiok.iptv.every', 'stremiok.local.matching', 'stremiok.local.hidden',
|
|
574
|
+
'stremiok.appsallowed', 'stremiok.aiomanager', 'stremiok.iptv.stalkerall', 'stremiok.iptv.stalkerkeep', 'stremiok.iptv.every', 'stremiok.local.matching', 'stremiok.local.hidden',
|
|
557
575
|
'stremiok.addonsoff', 'stremiok.integrations'];
|
|
558
576
|
function plural(n, one) { return n + ' ' + one + (n === 1 ? '' : 's'); }
|
|
559
577
|
function iptvLists() { return (_hasIptv && IPTV.getPlaylists) ? IPTV.getPlaylists() : []; }
|
|
@@ -1013,6 +1031,12 @@ var Stremio = (function () {
|
|
|
1013
1031
|
if (/^sv[ms]\./.test(id) && typeof StVod !== 'undefined') {
|
|
1014
1032
|
return StVod.meta(type, id).then(function (m) { if (!m) { throw new Error('Not found on the Stalker portal'); } return m; });
|
|
1015
1033
|
}
|
|
1034
|
+
if (/^jf[ms]\./.test(id) && typeof Jellyfin !== 'undefined') {
|
|
1035
|
+
return Jellyfin.meta(type, id).then(function (m) { if (!m) { throw new Error('Not found on the ' + Jellyfin.nameOfId(id) + ' server'); } return m; });
|
|
1036
|
+
}
|
|
1037
|
+
if (/^px[ms]\./.test(id) && typeof Plex !== 'undefined') {
|
|
1038
|
+
return Plex.meta(type, id).then(function (m) { if (!m) { throw new Error('Not found on the Plex server'); } return m; });
|
|
1039
|
+
}
|
|
1016
1040
|
if (/^iptv:/.test(id)) {
|
|
1017
1041
|
return IPTV.meta(id).then(function (m) {
|
|
1018
1042
|
if (!m) { throw new Error('IPTV channel not found'); }
|
|
@@ -1086,6 +1110,12 @@ var Stremio = (function () {
|
|
|
1086
1110
|
if (/^sv[ms]\./.test(id) && typeof StVod !== 'undefined') { // (a Stalker portal's own film or episode)
|
|
1087
1111
|
return StVod.streams(type, id).then(function (l) { l.forEach(function (s) { s._addon = 'Stalker'; }); if (onUpdate) { onUpdate(l, 0); } return l; });
|
|
1088
1112
|
}
|
|
1113
|
+
if (/^jf[ms]\./.test(id) && typeof Jellyfin !== 'undefined') { // (a Jellyfin or Emby server's own film or episode)
|
|
1114
|
+
return Jellyfin.streams(type, id).then(function (l) { var n = Jellyfin.nameOfId(id); l.forEach(function (s) { s._addon = n; }); if (onUpdate) { onUpdate(l, 0); } return l; });
|
|
1115
|
+
}
|
|
1116
|
+
if (/^px[ms]\./.test(id) && typeof Plex !== 'undefined') { // (a Plex server's own film or episode)
|
|
1117
|
+
return Plex.streams(type, id).then(function (l) { l.forEach(function (s) { s._addon = 'Plex'; }); if (onUpdate) { onUpdate(l, 0); } return l; });
|
|
1118
|
+
}
|
|
1089
1119
|
var key = type + ':' + id, e = _streamCache[key];
|
|
1090
1120
|
if (e && !force && (e.pending > 0 || Date.now() - e.at < STREAM_TTL)) {
|
|
1091
1121
|
syncLocal(e, type, id); // (the addons' answers kept; the USB drive's matches as they are now)
|
|
@@ -1884,11 +1914,20 @@ var Stremio = (function () {
|
|
|
1884
1914
|
// asked (optional): an array told how each source answered, for Diagnostics ("SkipDB:
|
|
1885
1915
|
// nothing", "IntroDB: credits"); out.from names the source of each kind it has.
|
|
1886
1916
|
// ids (optional): the title's own ids from its details ({ imdb, mal, season }), for anime.
|
|
1887
|
-
|
|
1917
|
+
// start: what the source's own server gave (Jellyfin's media segments), first; the services
|
|
1918
|
+
// fill what it lacks.
|
|
1919
|
+
function getIntroSegments(type, id, durationMs, asked, ids, start) {
|
|
1888
1920
|
var q = introIdParts(type, id);
|
|
1889
|
-
if (!q) { return Promise.resolve(null); }
|
|
1890
|
-
if (q.anime) { return animeSegments(type, q.anime, durationMs, asked, ids); }
|
|
1891
|
-
return segChain(q, durationMs, asked, null);
|
|
1921
|
+
if (!q || (start && SEG_KINDS.every(function (k) { return start[k] && start[k].length; }))) { return Promise.resolve(start || null); }
|
|
1922
|
+
if (q.anime) { return animeSegments(type, q.anime, durationMs, asked, ids).then(function (r) { return segMerge(start, r); }); }
|
|
1923
|
+
return segChain(q, durationMs, asked, start || null);
|
|
1924
|
+
}
|
|
1925
|
+
function segMerge(a, b) {
|
|
1926
|
+
if (!a || !b) { return a || b || null; }
|
|
1927
|
+
var out = { intro: a.intro, recap: a.recap, credits: a.credits, preview: a.preview, from: {} };
|
|
1928
|
+
Object.keys(a.from || {}).forEach(function (k) { out.from[k] = a.from[k]; });
|
|
1929
|
+
SEG_KINDS.forEach(function (k) { if (!(out[k] && out[k].length) && b[k] && b[k].length) { out[k] = b[k]; out.from[k] = (b.from || {})[k] || ''; } });
|
|
1930
|
+
return out;
|
|
1892
1931
|
}
|
|
1893
1932
|
// An anime: AniSkip first; what it doesn't give (on a Tizen 3 TV: everything, it can't be
|
|
1894
1933
|
// reached), from the IMDb-based sources by the show's IMDb id, season and episode.
|