stremiok 2.2.1 → 2.2.3
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 +41 -0
- package/README.md +15 -12
- package/config.xml +1 -1
- package/css/style.css +14 -9
- package/index.html +34 -33
- package/js/app.js +18 -19
- package/js/focus.js +30 -10
- package/js/iptv.js +107 -9
- package/js/player-core.js +80 -18
- package/js/player-store.js +3 -3
- package/js/player-subs.js +47 -7
- package/js/stremio.js +196 -28
- package/js/util.js +137 -16
- package/js/view-core.js +53 -13
- package/js/view-detail.js +35 -7
- package/js/view-discover.js +1 -1
- package/js/view-home.js +110 -20
- package/js/view-settings.js +114 -4
- package/js/views.js +1 -1
- package/js/xtvod.js +366 -0
- package/js/ytplay.js +28 -4
- package/package.json +2 -1
- package/service/index.js +553 -18
package/js/util.js
CHANGED
|
@@ -21,7 +21,7 @@ var U = (function () {
|
|
|
21
21
|
are read %-decoded (%70assword is password), and a #fragment is masked the same way
|
|
22
22
|
(name=value pairs, or one token). Scheme, host, port and the rest of the path stay
|
|
23
23
|
readable. */
|
|
24
|
-
var SECRET_PARAM = /^(pass(word)?|pwd|passwd|user(name)?|login|token|access_token|refresh_token|auth(orization)?|key|apikey|api_key|api-key|secret|client_secret|sig|signature|session|sid|hash)$/i;
|
|
24
|
+
var SECRET_PARAM = /^(pass(word)?|pwd|passwd|user(name)?|login|token|access_token|refresh_token|auth(orization)?|key|apikey|api_key|api-key|secret|client_secret|sig|signature|session|sid|hash|mac)$/i;
|
|
25
25
|
function looksLikeToken(seg) {
|
|
26
26
|
if (seg.length < 20 || !/^[A-Za-z0-9._~+=%-]+$/.test(seg)) { return false; }
|
|
27
27
|
if (/%3A%2F%2F/i.test(seg)) { return false; } // an encoded URL (a YouTube page for the service), not a token
|
|
@@ -33,14 +33,30 @@ var U = (function () {
|
|
|
33
33
|
try { d = decodeURIComponent(('' + k).replace(/\+/g, ' ')); } catch (e) {}
|
|
34
34
|
return SECRET_PARAM.test(d.trim());
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
// A link inside a link's value (a converted video's mediaURL=…): decoded (up to 3 times), masked
|
|
37
|
+
// the same way (a link in it too, 3 deep at most), and shown encoded as it was. Null: not one.
|
|
38
|
+
var LINK_START = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
39
|
+
function innerLink(v, depth) {
|
|
40
|
+
var d = v, n = 0;
|
|
41
|
+
while (n < 3 && !LINK_START.test(d) && /%[0-9a-f]{2}/i.test(d)) {
|
|
42
|
+
try { d = decodeURIComponent(d.replace(/\+/g, ' ')); } catch (e) { return null; }
|
|
43
|
+
n++;
|
|
44
|
+
}
|
|
45
|
+
if (!n || !LINK_START.test(d)) { return null; }
|
|
46
|
+
var r = depth < 3 ? redactUrl(d, depth + 1) : d.replace(/[?#].*$/, '?•••');
|
|
47
|
+
for (var i = 0; i < n; i++) { r = encodeURIComponent(r).replace(/%E2%80%A2/g, '•'); }
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
function maskParams(str, depth) {
|
|
37
51
|
return str.split('&').map(function (kv) {
|
|
38
52
|
var eq = kv.indexOf('='), k = eq === -1 ? kv : kv.slice(0, eq);
|
|
39
53
|
if (eq !== -1 && secretName(k)) { return k + '=•••'; }
|
|
54
|
+
var inner = eq !== -1 ? innerLink(kv.slice(eq + 1), depth || 0) : null;
|
|
55
|
+
if (inner !== null) { return k + '=' + inner; }
|
|
40
56
|
return (eq !== -1 && looksLikeToken(kv.slice(eq + 1))) ? k + '=•••' : kv;
|
|
41
57
|
}).join('&');
|
|
42
58
|
}
|
|
43
|
-
function redactUrl(url) {
|
|
59
|
+
function redactUrl(url, depth) {
|
|
44
60
|
var u = '' + (url || ''), m = u.match(/^([a-z][a-z0-9+.-]*:\/\/)([^\/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i);
|
|
45
61
|
if (!m) { return u; }
|
|
46
62
|
var auth = m[2].lastIndexOf('@');
|
|
@@ -52,9 +68,9 @@ var U = (function () {
|
|
|
52
68
|
if (xt !== -1 && (j === xt + 1 || j === xt + 2)) { return '•••'; }
|
|
53
69
|
return looksLikeToken(seg) ? '•••' : seg;
|
|
54
70
|
});
|
|
55
|
-
var query = m[4] ? '?' + maskParams(m[4].slice(1)) : '';
|
|
71
|
+
var query = m[4] ? '?' + maskParams(m[4].slice(1), depth) : '';
|
|
56
72
|
var frag = m[5] ? m[5].slice(1) : null;
|
|
57
|
-
if (frag !== null) { frag = '#' + (frag.indexOf('=') !== -1 ? maskParams(frag) : looksLikeToken(frag) ? '•••' : frag); }
|
|
73
|
+
if (frag !== null) { frag = '#' + (frag.indexOf('=') !== -1 ? maskParams(frag, depth) : looksLikeToken(frag) ? '•••' : frag); }
|
|
58
74
|
return m[1] + host + segs.join('/') + query + (frag || '');
|
|
59
75
|
}
|
|
60
76
|
|
|
@@ -398,11 +414,13 @@ var U = (function () {
|
|
|
398
414
|
var big = m.match(/^Too large \((over [^)]+)\)/);
|
|
399
415
|
if (big) { return 'too large (' + big[1] + ')'; }
|
|
400
416
|
if (/^Bad JSON/.test(m)) { return 'not valid JSON'; }
|
|
417
|
+
var late = m.match(/^Timed out after (\d+ s)/);
|
|
418
|
+
if (late) { return 'timed out after ' + late[1]; }
|
|
401
419
|
if (/^Timeout/.test(m)) { return 'timed out'; }
|
|
402
|
-
if (/^Network error/.test(m)) { return '
|
|
420
|
+
if (/^(No answer|Network error)/.test(m)) { return 'no answer (connection refused, blocked or certificate)'; }
|
|
403
421
|
if (/^Redirected into the home network/.test(m)) { return 'redirected into the home network'; }
|
|
404
422
|
var st = m.match(/^HTTP (\d+)/);
|
|
405
|
-
if (st) { return st[1] === '0' ? 'no answer (blocked
|
|
423
|
+
if (st) { return st[1] === '0' ? 'no answer (connection refused, blocked or certificate)' : 'HTTP ' + st[1]; }
|
|
406
424
|
return m.split(':')[0] || 'failed';
|
|
407
425
|
}
|
|
408
426
|
|
|
@@ -438,7 +456,7 @@ var U = (function () {
|
|
|
438
456
|
function logged(err, priv) {
|
|
439
457
|
var msg = '' + err.message;
|
|
440
458
|
if (priv || privateNow()) {
|
|
441
|
-
var kind = /^(HTTP \d+|Timeout|Network error|Too large|Bad JSON|Redirected into the home network)/.exec(msg), host = /(https?:\/\/[^\/\s?#]+)/.exec(msg);
|
|
459
|
+
var kind = /^(HTTP \d+|Timed out after \d+ s|Timeout|No answer|Network error|Too large|Bad JSON|Redirected into the home network)/.exec(msg), host = /(https?:\/\/[^\/\s?#]+)/.exec(msg);
|
|
442
460
|
msg = 'Private viewing: a download' + (host ? ' from ' + host[1] : '') + ' failed' + (kind ? ' (' + kind[1] + ')' : '');
|
|
443
461
|
}
|
|
444
462
|
log('network', msg); err.logged = true; return err;
|
|
@@ -513,6 +531,11 @@ var U = (function () {
|
|
|
513
531
|
reject(logged(new Error('Redirected into the home network: ' + redactUrl(url) + ' -> ' + redactUrl(landed))));
|
|
514
532
|
return;
|
|
515
533
|
}
|
|
534
|
+
if (xhr.status === 0) { // (no answer: the TV's browser says so first, then whether it timed out or failed)
|
|
535
|
+
done = false;
|
|
536
|
+
setTimeout(function () { if (!done) { done = true; reject(logged(noAnswer(url))); } }, 0);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
516
539
|
if (xhr.status >= 200 && xhr.status < 300) { resolve(body); }
|
|
517
540
|
else {
|
|
518
541
|
var err = new Error('HTTP ' + xhr.status + ' for ' + redactUrl(url));
|
|
@@ -521,12 +544,15 @@ var U = (function () {
|
|
|
521
544
|
reject(logged(err));
|
|
522
545
|
}
|
|
523
546
|
};
|
|
524
|
-
xhr.ontimeout = function () { if (!done) { done = true; reject(logged(new Error('
|
|
525
|
-
xhr.onerror = function () { if (!done) { done = true; reject(logged(
|
|
547
|
+
xhr.ontimeout = function () { if (!done) { done = true; reject(logged(new Error('Timed out after ' + Math.round(xhr.timeout / 1000) + ' s: ' + redactUrl(url)))); } };
|
|
548
|
+
xhr.onerror = function () { if (!done) { done = true; reject(logged(noAnswer(url))); } };
|
|
526
549
|
try { if (body == null) { xhr.send(); } else { xhr.send('' + body); } } catch (e3) { reject(e3); }
|
|
527
550
|
});
|
|
528
551
|
}
|
|
529
552
|
|
|
553
|
+
// No answer at all: the connection refused or dropped, blocked, a certificate the TV doesn't
|
|
554
|
+
// trust (its browser says only "status 0").
|
|
555
|
+
function noAnswer(url) { return new Error('No answer (connection refused, blocked or certificate): ' + redactUrl(url)); }
|
|
530
556
|
function cancelledError(url) { var e = new Error('Cancelled: ' + redactUrl(url)); e.cancelled = true; return e; }
|
|
531
557
|
// Downloads for one screen (or one job), stopped together: getText / getJSON(url, …, token).
|
|
532
558
|
function cancelToken() {
|
|
@@ -566,11 +592,12 @@ var U = (function () {
|
|
|
566
592
|
unless maxBytes says otherwise). cancel, headers: see getText. */
|
|
567
593
|
// A POST (body: text), its answer JSON.
|
|
568
594
|
function postJSON(url, body, timeoutMs, maxBytes, headers) { return getJSON(url, timeoutMs, maxBytes, null, headers, body); }
|
|
569
|
-
|
|
595
|
+
// quiet: not noted in Diagnostics (the caller says what came of it, e.g. a skip-times lookup).
|
|
596
|
+
function getJSON(url, timeoutMs, maxBytes, cancel, headers, body, quiet) {
|
|
570
597
|
var priv = privateNow(); // (asked during a private playback: its answer unreadable later is logged as one too)
|
|
571
|
-
return getText(url, timeoutMs, maxBytes || JSON_MAX, cancel,
|
|
598
|
+
return getText(url, timeoutMs, maxBytes || JSON_MAX, cancel, !!quiet, headers, body).then(function (text) {
|
|
572
599
|
try { return JSON.parse(text); }
|
|
573
|
-
catch (e) {
|
|
600
|
+
catch (e) { var bad = new Error('Bad JSON from ' + redactUrl(url)); throw quiet ? bad : logged(bad, priv); }
|
|
574
601
|
});
|
|
575
602
|
}
|
|
576
603
|
|
|
@@ -1001,12 +1028,14 @@ var U = (function () {
|
|
|
1001
1028
|
// settings, addons or playlists clears regenerable caches (in CACHES order) until it
|
|
1002
1029
|
// fits; if it still doesn't, it's logged and you're told (once a minute at most).
|
|
1003
1030
|
// A cache that doesn't fit simply isn't saved.
|
|
1004
|
-
|
|
1031
|
+
// keep: what was saved stays in memory as it is, so the next read needn't parse it again
|
|
1032
|
+
// (the playback progress, saved over and over).
|
|
1033
|
+
set: function (key, value, keep) {
|
|
1005
1034
|
delete _memo[key];
|
|
1006
1035
|
_writes++;
|
|
1007
1036
|
var text;
|
|
1008
1037
|
try { text = JSON.stringify(value); } catch (e0) { return false; }
|
|
1009
|
-
if (tryWrite(key, text)) { return true; }
|
|
1038
|
+
if (tryWrite(key, text)) { if (keep) { _memo[key] = { missing: false, val: value }; } return true; }
|
|
1010
1039
|
if (isCacheKey(key)) { return false; }
|
|
1011
1040
|
var freed = [];
|
|
1012
1041
|
for (var i = 0; i < CACHES.length; i++) {
|
|
@@ -1102,6 +1131,79 @@ var U = (function () {
|
|
|
1102
1131
|
l.cancel();
|
|
1103
1132
|
});
|
|
1104
1133
|
}
|
|
1134
|
+
// A sideways row's picture far off screen waits on its card (__parked), not costing a download
|
|
1135
|
+
// and a decode that compete with the remote, until focus comes near it (unparkNear). On a
|
|
1136
|
+
// hidden screen (nothing measures) it loads as before.
|
|
1137
|
+
var PARK_X = 600, PARK_Y = 450, SCREEN_W = 1920, SCREEN_H = 1080, UNPARK_CARDS = 10, UNPARK_ROWS = 2, CARD_GAP = 22;
|
|
1138
|
+
function parkIt(item) {
|
|
1139
|
+
if (item.bg || item.wanted) { return false; }
|
|
1140
|
+
var card = item.img.parentNode, sc = card && card.parentNode;
|
|
1141
|
+
if (!sc || (' ' + (sc.className || '') + ' ').indexOf(' row-scroller ') === -1) { return false; }
|
|
1142
|
+
var r = item.img.getBoundingClientRect();
|
|
1143
|
+
if (!(r.width > 0)) { return false; }
|
|
1144
|
+
if (r.right > -PARK_X && r.left < SCREEN_W + PARK_X && r.bottom > -PARK_Y && r.top < SCREEN_H + PARK_Y) { return false; }
|
|
1145
|
+
card.__parked = item;
|
|
1146
|
+
_parkedItems.push(item);
|
|
1147
|
+
if (!_lastMove) { _lastMove = Date.now(); }
|
|
1148
|
+
scheduleIdle(IDLE_WAIT_MS);
|
|
1149
|
+
return true;
|
|
1150
|
+
}
|
|
1151
|
+
// Parked pictures, while nothing is going on: no key for IDLE_WAIT_MS and nothing else to load,
|
|
1152
|
+
// one at a time, nearest to focus first (an image's decode competes with the remote). A key
|
|
1153
|
+
// puts it off again; nothing while something plays or on a hidden screen.
|
|
1154
|
+
var _parkedItems = [], _idleTimer = null, _lastMove = 0, _lastCard = null, IDLE_WAIT_MS = 3000, IDLE_GAP_MS = 300, IDLE_BUSY_MS = 1500;
|
|
1155
|
+
function scheduleIdle(ms) { if (_idleTimer === null) { _idleTimer = setTimeout(idleStep, ms); } }
|
|
1156
|
+
function idleStep() {
|
|
1157
|
+
_idleTimer = null;
|
|
1158
|
+
_parkedItems = _parkedItems.filter(function (it) { return it.img.parentNode && it.img.parentNode.__parked === it && onPage(it.img); });
|
|
1159
|
+
if (!_parkedItems.length) { return; }
|
|
1160
|
+
var wait = _lastMove + IDLE_WAIT_MS - Date.now();
|
|
1161
|
+
if (wait > 0) { scheduleIdle(wait); return; }
|
|
1162
|
+
if (isHidden() || _imageActive > 0 || _imageQueue.length || (typeof Player !== 'undefined' && Player.isActive && Player.isActive())) { scheduleIdle(IDLE_BUSY_MS); return; }
|
|
1163
|
+
var f = _lastCard && onPage(_lastCard) ? _lastCard.getBoundingClientRect() : { left: 0, top: 0 }, best = null, bestD = Infinity;
|
|
1164
|
+
_parkedItems.forEach(function (it) {
|
|
1165
|
+
var r = it.img.getBoundingClientRect();
|
|
1166
|
+
if (!(r.width > 0)) { return; }
|
|
1167
|
+
var d = Math.abs(r.top - f.top) * 4 + Math.abs(r.left - f.left); // (its own row first)
|
|
1168
|
+
if (d < bestD) { bestD = d; best = it; }
|
|
1169
|
+
});
|
|
1170
|
+
if (!best) { scheduleIdle(IDLE_BUSY_MS); return; }
|
|
1171
|
+
best.img.parentNode.__parked = null;
|
|
1172
|
+
best.wanted = true;
|
|
1173
|
+
_imageQueue.unshift(best);
|
|
1174
|
+
scheduleImagePump(0);
|
|
1175
|
+
scheduleIdle(IDLE_GAP_MS);
|
|
1176
|
+
}
|
|
1177
|
+
function unparkRange(sc, from, to) {
|
|
1178
|
+
var kids = sc.children, any = false;
|
|
1179
|
+
for (var i = Math.max(0, from); i <= to && i < kids.length; i++) {
|
|
1180
|
+
var it = kids[i].__parked;
|
|
1181
|
+
if (!it) { continue; }
|
|
1182
|
+
kids[i].__parked = null;
|
|
1183
|
+
it.wanted = true;
|
|
1184
|
+
_imageQueue.unshift(it);
|
|
1185
|
+
any = true;
|
|
1186
|
+
}
|
|
1187
|
+
return any;
|
|
1188
|
+
}
|
|
1189
|
+
// Focus on this card: its row's pictures around it, and the rows just above and below, around
|
|
1190
|
+
// where each is scrolled to.
|
|
1191
|
+
function unparkNear(card) {
|
|
1192
|
+
var sc = card.parentNode, row = sc && sc.parentNode;
|
|
1193
|
+
if (!row || (' ' + (sc.className || '') + ' ').indexOf(' row-scroller ') === -1) { return; }
|
|
1194
|
+
var at = Array.prototype.indexOf.call(sc.children, card);
|
|
1195
|
+
unparkRange(sc, at - UNPARK_CARDS, at + UNPARK_CARDS);
|
|
1196
|
+
['previousElementSibling', 'nextElementSibling'].forEach(function (dir) {
|
|
1197
|
+
var r = row;
|
|
1198
|
+
for (var n = 0; n < UNPARK_ROWS && r; n++) {
|
|
1199
|
+
r = r[dir];
|
|
1200
|
+
var osc = r && r.querySelector ? r.querySelector('.row-scroller') : null, first = osc && osc.children[0];
|
|
1201
|
+
if (!first) { continue; }
|
|
1202
|
+
var from = Math.floor((osc.scrollLeft || 0) / ((first.offsetWidth || 200) + CARD_GAP));
|
|
1203
|
+
unparkRange(osc, from - UNPARK_CARDS, from + UNPARK_CARDS);
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1105
1207
|
function pumpImages() {
|
|
1106
1208
|
dropUnwanted();
|
|
1107
1209
|
if (isHidden()) { return; } // (in the background: nothing new until StremioK is back)
|
|
@@ -1112,6 +1214,7 @@ var U = (function () {
|
|
|
1112
1214
|
if (!onPage(img) || img.__queuedImage !== item) {
|
|
1113
1215
|
continue;
|
|
1114
1216
|
}
|
|
1217
|
+
if (parkIt(item)) { continue; }
|
|
1115
1218
|
img.__queuedImage = null;
|
|
1116
1219
|
if (_inflight[item.src]) { _inflight[item.src].push(item); continue; } // already loading
|
|
1117
1220
|
_imageActive++;
|
|
@@ -1250,7 +1353,10 @@ var U = (function () {
|
|
|
1250
1353
|
// Called after focus/scroll changes. Load the focused card first, then its
|
|
1251
1354
|
// closest horizontal neighbors, while the rest continue in the background.
|
|
1252
1355
|
function prioritizeImages(node) {
|
|
1356
|
+
_lastMove = Date.now();
|
|
1253
1357
|
if (!node || !node.querySelector || !node.classList.contains('card')) { return; }
|
|
1358
|
+
_lastCard = node;
|
|
1359
|
+
unparkNear(node);
|
|
1254
1360
|
var nearby = [node];
|
|
1255
1361
|
var prev = node.previousElementSibling;
|
|
1256
1362
|
var next = node.nextElementSibling;
|
|
@@ -1309,6 +1415,21 @@ var U = (function () {
|
|
|
1309
1415
|
'filter: drop-shadow(0 0 2px rgba(0,0,0,0.85)) drop-shadow(0 0 6px rgba(0,0,0,0.45)) }\n' +
|
|
1310
1416
|
'#player-osd, #sub-menu, #player-bar, #skip-prompt, #stream-info, #cast-strip, #yt-links, #yt-card, #toast, #hold-hint, #spinner { color: #e6e9ef }';
|
|
1311
1417
|
|
|
1418
|
+
// Zoom (Settings › Appearance), 1 to 1.4: the page laid out on 1920×1080 divided by it and
|
|
1419
|
+
// scaled up from the top left to fill the screen (a transform: what's measured on screen,
|
|
1420
|
+
// getBoundingClientRect, is scaled; scrolling, offsets and styles aren't: divide by zoom()).
|
|
1421
|
+
var _zoom = 1;
|
|
1422
|
+
function zoom() { return _zoom; }
|
|
1423
|
+
function setZoom(z) {
|
|
1424
|
+
_zoom = (z > 1 && z <= 1.4) ? z : 1;
|
|
1425
|
+
var s = document.body && document.body.style, on = _zoom !== 1;
|
|
1426
|
+
if (!s) { return; }
|
|
1427
|
+
s.width = on ? Math.ceil(1920 / _zoom) + 'px' : '';
|
|
1428
|
+
s.height = on ? Math.ceil(1080 / _zoom) + 'px' : '';
|
|
1429
|
+
s.webkitTransform = s.transform = on ? 'scale(' + _zoom + ')' : '';
|
|
1430
|
+
s.webkitTransformOrigin = s.transformOrigin = on ? '0 0' : '';
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1312
1433
|
// bg: 'dark' (the stylesheet's own), 'black', 'gray' or 'white' (the last two with dark text)
|
|
1313
1434
|
function applyTheme(accent, bg) {
|
|
1314
1435
|
if (bg === true) { bg = 'black'; }
|
|
@@ -1509,6 +1630,6 @@ var U = (function () {
|
|
|
1509
1630
|
store: store, toast: toast, spinner: spinner,
|
|
1510
1631
|
deferImage: deferImage, deferBg: deferBg, cardImage: cardImage, prioritizeImages: prioritizeImages, requeueImages: requeueImages,
|
|
1511
1632
|
fmtTime: fmtTime, dayLabel: dayLabel, settleAll: settleAll, cancelToken: cancelToken, isHidden: isHidden, whenVisible: whenVisible, crumb: crumb, sessionStart: sessionStart, sessionState: sessionState, mark: mark, startupMarks: startupMarks, loadScript: loadScript, qrModules: qrModules, qrCanvas: qrCanvas, qrScale: qrScale,
|
|
1512
|
-
applyTheme: applyTheme, accentColor: accentColor, ACCENT_KEYS: Object.keys(ACCENTS)
|
|
1633
|
+
applyTheme: applyTheme, zoom: zoom, setZoom: setZoom, accentColor: accentColor, ACCENT_KEYS: Object.keys(ACCENTS)
|
|
1513
1634
|
};
|
|
1514
1635
|
})();
|
package/js/view-core.js
CHANGED
|
@@ -24,8 +24,9 @@ var ViewParts = {};
|
|
|
24
24
|
var _modalPrevFocus = null;
|
|
25
25
|
var _modalScope = null;
|
|
26
26
|
|
|
27
|
-
// opts (optional): { noLabel, onNo, plain } — another label and an action for the
|
|
28
|
-
// button; plain: the confirm button not marked as destructive
|
|
27
|
+
// opts (optional): { noLabel, onNo, plain, focusYes } — another label and an action for the
|
|
28
|
+
// other button; plain: the confirm button not marked as destructive; focusYes: focus starts on
|
|
29
|
+
// it (not on Cancel).
|
|
29
30
|
function confirm(message, confirmLabel, onYes, opts) {
|
|
30
31
|
opts = opts || {};
|
|
31
32
|
// defensive: never stack modals
|
|
@@ -45,7 +46,7 @@ var ViewParts = {};
|
|
|
45
46
|
overlay.appendChild(box);
|
|
46
47
|
document.body.appendChild(overlay);
|
|
47
48
|
|
|
48
|
-
showModal(overlay, no); // default to Cancel (safe)
|
|
49
|
+
showModal(overlay, opts.focusYes ? yes : no); // default to Cancel (safe)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
// A QR code for the phone (an addon's link or setup page): the code holds the whole link;
|
|
@@ -340,6 +341,7 @@ var ViewParts = {};
|
|
|
340
341
|
reload.__onselect = function () {
|
|
341
342
|
closeModal();
|
|
342
343
|
U.toast('Reloading playlist…', 4000);
|
|
344
|
+
if (typeof XtVod !== 'undefined' && XtVod.reload) { XtVod.reload(playlist.id); } // (an Xtream account: its films and series too)
|
|
343
345
|
Stremio.iptvReload(playlist.id).then(function () {
|
|
344
346
|
refreshAddonRows('local:iptv');
|
|
345
347
|
var st = Stremio.iptvStatus(playlist.id);
|
|
@@ -511,10 +513,13 @@ var ViewParts = {};
|
|
|
511
513
|
else if (m.key === 'discover') { item('tab-pill', 'discover', 'Discover', '🔭', function () { App.openDiscover(); }, tabbar); }
|
|
512
514
|
else if (m.key === 'search') { item('hchip', 'search', 'Search', '🔍', function () { App.openSearch(); }, tabbar); }
|
|
513
515
|
});
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
516
|
+
// The items in one strip that scrolls sideways when they don't all fit (Focus keeps the
|
|
517
|
+
// focused one in view); the StremioK name outside it, at the right.
|
|
518
|
+
var strip = U.el('div', 'menu-scroll');
|
|
519
|
+
strip.appendChild(tabbar);
|
|
520
|
+
item('hchip', 'settings', 'Settings', '⚙', function () { App.openSettings(); }, strip);
|
|
521
|
+
head.appendChild(strip);
|
|
522
|
+
setTimeout(function () { showActiveItem(strip); }, 0); // (once it's on screen)
|
|
518
523
|
var brand = U.el('div', 'brand');
|
|
519
524
|
brand.innerHTML = 'Stremio<span class="dot">K</span>';
|
|
520
525
|
if (Player.isPrivate && Player.isPrivate()) { brand.className += ' private'; } // (private viewing on: drawn as an outline)
|
|
@@ -522,6 +527,15 @@ var ViewParts = {};
|
|
|
522
527
|
return head;
|
|
523
528
|
}
|
|
524
529
|
|
|
530
|
+
// The page's own item scrolled into view (one picked by number, far to the right), with
|
|
531
|
+
// room for a neighbour on either side; focus may be on the page below.
|
|
532
|
+
function showActiveItem(strip) {
|
|
533
|
+
var a = strip.querySelector('.active'), w = strip.clientWidth, mx = 90;
|
|
534
|
+
if (!a || !w) { return; }
|
|
535
|
+
if (a.offsetLeft < strip.scrollLeft + mx) { strip.scrollLeft = Math.max(0, a.offsetLeft - mx); }
|
|
536
|
+
else if (a.offsetLeft + a.offsetWidth > strip.scrollLeft + w - mx) { strip.scrollLeft = a.offsetLeft + a.offsetWidth - w + mx; }
|
|
537
|
+
}
|
|
538
|
+
|
|
525
539
|
// DOWN from the top menu returns to where focus was before going UP (if it's still
|
|
526
540
|
// on screen), else the first focusable in the content area below the menu.
|
|
527
541
|
function focusBelowTop(head) {
|
|
@@ -534,7 +548,7 @@ var ViewParts = {};
|
|
|
534
548
|
var all = s.querySelectorAll('.focusable');
|
|
535
549
|
for (var i = 0; i < all.length; i++) {
|
|
536
550
|
var r = all[i].getBoundingClientRect();
|
|
537
|
-
if (r.height > 0 && r.top > 80) { Focus.setFocus(all[i]); return true; }
|
|
551
|
+
if (r.height > 0 && r.top > 80 * U.zoom()) { Focus.setFocus(all[i]); return true; } // (below the menu: on screen, zoomed)
|
|
538
552
|
}
|
|
539
553
|
return false;
|
|
540
554
|
}
|
|
@@ -639,17 +653,32 @@ var ViewParts = {};
|
|
|
639
653
|
redrawGuideCards();
|
|
640
654
|
}, 60000);
|
|
641
655
|
}
|
|
656
|
+
// A hold-OK menu that waits for something first (a channel's schedule, a title's details):
|
|
657
|
+
// shown only if, when it comes, you're still where you held it: the card in the page, its
|
|
658
|
+
// screen not hidden (Settings or a title opened meanwhile; Home stays in the page, hidden),
|
|
659
|
+
// no player, no other menu up, and no hold since (that one's). -> { still(), latest() }
|
|
660
|
+
var _holdGen = 0;
|
|
661
|
+
function holdNow(card) {
|
|
662
|
+
var gen = ++_holdGen, screen = null;
|
|
663
|
+
for (var n = card; n && !screen; n = n.parentNode) { if (/\bscreen\b/.test(n.className || '')) { screen = n; } }
|
|
664
|
+
return {
|
|
665
|
+
latest: function () { return gen === _holdGen; },
|
|
666
|
+
still: function () {
|
|
667
|
+
return gen === _holdGen && !!card && document.documentElement.contains(card) && (!screen || !/\bhidden\b/.test(screen.className)) &&
|
|
668
|
+
!(typeof Player !== 'undefined' && Player.isActive()) && !isModalOpen();
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
}
|
|
642
672
|
// Hold OK on a channel card: ▶ Watch now, ★ Add to / Remove from favorites, and its schedule
|
|
643
673
|
// from 2 hours ago to tomorrow (what's on now marked, and picked); OK on a program says
|
|
644
674
|
// what it is. A channel without a guide: the first two.
|
|
645
|
-
var _schedGen = 0;
|
|
646
675
|
function liveSchedule(meta, card) {
|
|
647
|
-
var
|
|
676
|
+
var hold = holdNow(card);
|
|
648
677
|
U.spinner(true);
|
|
649
678
|
EPG.schedule(meta.id).then(null, function () { return []; }).then(function (list) {
|
|
650
|
-
if (
|
|
679
|
+
if (!hold.latest()) { return; } // (held on another card since: its own)
|
|
651
680
|
U.spinner(false);
|
|
652
|
-
if (!
|
|
681
|
+
if (!hold.still()) { return; } // (left meanwhile)
|
|
653
682
|
var fav = IPTV.isFavorite(meta.id), t = Date.now() / 1000, at = 'play';
|
|
654
683
|
var items = [['play', '▶ Watch now'], ['fav', fav ? '★ Remove from favorites' : '★ Add to favorites']];
|
|
655
684
|
list.forEach(function (p, i) {
|
|
@@ -679,6 +708,15 @@ var ViewParts = {};
|
|
|
679
708
|
if (sib[i] === card) { idx = list.length; }
|
|
680
709
|
list.push({ meta: sib[i].__meta, card: sib[i] });
|
|
681
710
|
}
|
|
711
|
+
// (a long row: the channels whose cards aren't built yet too; a card made when it's asked for)
|
|
712
|
+
var row = card.parentNode && card.parentNode.parentNode;
|
|
713
|
+
if (row && row.__rest && row.__more) {
|
|
714
|
+
row.__rest().forEach(function (m) {
|
|
715
|
+
var e = { meta: m };
|
|
716
|
+
Object.defineProperty(e, 'card', { get: function () { return row.__cardOf(m); } });
|
|
717
|
+
list.push(e);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
682
720
|
return { list: list, idx: idx };
|
|
683
721
|
}
|
|
684
722
|
|
|
@@ -686,10 +724,12 @@ var ViewParts = {};
|
|
|
686
724
|
// Playing, or mark it watched / unwatched (a series as a whole). The title's details
|
|
687
725
|
// are fetched first (usually cached) so the choices match its current state.
|
|
688
726
|
function posterActions(meta, type, card) {
|
|
727
|
+
var hold = holdNow(card);
|
|
689
728
|
U.spinner(true);
|
|
690
729
|
titleActions(meta, type).then(function (a) {
|
|
730
|
+
if (!hold.latest()) { return; } // (held on another card since: its own)
|
|
691
731
|
U.spinner(false);
|
|
692
|
-
pickList(a.name, a.items, null, a.run);
|
|
732
|
+
if (hold.still()) { pickList(a.name, a.items, null, a.run); } // (not over a screen opened meanwhile)
|
|
693
733
|
});
|
|
694
734
|
}
|
|
695
735
|
// What a title's hold-OK menu offers, wherever it's held (a poster; the player's Cast & more,
|
package/js/view-detail.js
CHANGED
|
@@ -203,6 +203,10 @@
|
|
|
203
203
|
if (local) { resumeSources(startPlayback(local, p.id, p.name, how), p.id); return; }
|
|
204
204
|
var st = { url: p.url, name: p.name, _headers: U.sanitizeHeaders(p.headers) || undefined,
|
|
205
205
|
behaviorHints: (p.fileHints && typeof p.fileHints === 'object') ? p.fileHints : undefined }; // (its file: for subtitles made for it)
|
|
206
|
+
if (p.torrent && typeof p.torrent.infoHash === 'string') { // (a torrent: its link from the streaming server set now)
|
|
207
|
+
st = Stremio.torrentSource({ infoHash: p.torrent.infoHash, fileIdx: p.torrent.fileIdx, sources: p.torrent.sources, name: p.name, behaviorHints: st.behaviorHints });
|
|
208
|
+
if (!st.url) { U.toast('This one plays through a streaming server: Settings › Content › Streaming server', 6000); return; }
|
|
209
|
+
}
|
|
206
210
|
if (/^https:\/\/www\.youtube\.com\/watch\?v=[A-Za-z0-9_-]{11}$/.test(p.url || '')) { st._yt = true; st.ytPage = p.url; } // (a YouTube video: through the service again)
|
|
207
211
|
resumeSources(startPlayback(st, p.id, p.name, how), p.id);
|
|
208
212
|
}
|
|
@@ -321,7 +325,7 @@
|
|
|
321
325
|
if (!panel || (' ' + body.className + ' ').indexOf(' series-body ') === -1) { return; }
|
|
322
326
|
var sr = s.getBoundingClientRect(), br = body.getBoundingClientRect();
|
|
323
327
|
if (!(br.height > 0)) { return; }
|
|
324
|
-
var top = Math.round(br.bottom - sr.top) + PANEL_GAP;
|
|
328
|
+
var top = Math.round((br.bottom - sr.top) / U.zoom()) + PANEL_GAP; // (measured on screen, zoomed)
|
|
325
329
|
panel.style.top = Math.max(PANEL_MIN, Math.min(PANEL_MAX, top)) + 'px';
|
|
326
330
|
}
|
|
327
331
|
|
|
@@ -724,7 +728,7 @@
|
|
|
724
728
|
function fileStreams(v) {
|
|
725
729
|
return v.streams.map(function (st) {
|
|
726
730
|
var s = Object.assign({ name: fileLabel(v) }, st);
|
|
727
|
-
return Stremio.
|
|
731
|
+
return Stremio.torrentSource(Stremio.youTubeSource(s));
|
|
728
732
|
});
|
|
729
733
|
}
|
|
730
734
|
|
|
@@ -1395,6 +1399,8 @@
|
|
|
1395
1399
|
uncached: function (a, b) { return (a.info.cache === -1 ? 1 : 0) - (b.info.cache === -1 ? 1 : 0); },
|
|
1396
1400
|
kind: function (a, b) { return (KIND_SCORE[b.info.kind] || 0) - (KIND_SCORE[a.info.kind] || 0); },
|
|
1397
1401
|
hdr: function (a, b) { return (b.info.hdr ? 1 : 0) - (a.info.hdr ? 1 : 0); },
|
|
1402
|
+
// (only two sources that both state theirs: the others keep their order)
|
|
1403
|
+
seeds: function (a, b) { return (a.info.seeds >= 0 && b.info.seeds >= 0) ? b.info.seeds - a.info.seeds : 0; },
|
|
1398
1404
|
addon: function (a, b) { return (a.st._addonRank || 0) - (b.st._addonRank || 0); },
|
|
1399
1405
|
// each source's place in its addon's own list (an addon's first ties with another's
|
|
1400
1406
|
// first): a plain key, so it orders consistently wherever it sits among the criteria
|
|
@@ -1464,7 +1470,13 @@
|
|
|
1464
1470
|
// again), as the player takes a source, or null. total: how many it could try in all.
|
|
1465
1471
|
// avoid: [{ addon, tag }] — an addon's links through a debrid service that sent an account's
|
|
1466
1472
|
// notice (access refused, a limit: the player's noticeOf): they'd say the same.
|
|
1473
|
+
// Torrent sources' links from the streaming server set now (Settings may have changed it since
|
|
1474
|
+
// they came: none when it's off).
|
|
1475
|
+
function serverNow(list) {
|
|
1476
|
+
(list || []).forEach(function (st) { if (st && st.infoHash) { Stremio.torrentSource(st); } });
|
|
1477
|
+
}
|
|
1467
1478
|
function nextSourceFor(tried, avoid) {
|
|
1479
|
+
serverNow(_d && _d.streams);
|
|
1468
1480
|
var rows = (_d && _d.streams) ? filterRows(rankRowsFor(_d.streams)) : [], seen = {}, all = []; // (within the filter: Addon ▾ / Resolution ▾)
|
|
1469
1481
|
rows.forEach(function (r) {
|
|
1470
1482
|
var st = r.st, id = Stremio.sourceId(st), dt = Stremio.debridOf ? Stremio.debridOf(st) : null;
|
|
@@ -1847,6 +1859,7 @@
|
|
|
1847
1859
|
// before, 4K, 1080p, …) starts with its heading.
|
|
1848
1860
|
var heading = streamsHeading();
|
|
1849
1861
|
if (heading) { listScroll.appendChild(U.el('div', 'stream-for', heading)); }
|
|
1862
|
+
serverNow(_d.streams); // (a page kept from before: its torrents follow the streaming server set now)
|
|
1850
1863
|
var list = _d.streams, keepAt = -1, rows = rankRowsFor(list), lastGroup = null;
|
|
1851
1864
|
// Direct links only (Settings › Source ranking): the sources the TV can't play left out
|
|
1852
1865
|
// (torrents, links it can't open); where-to-watch apps stay (they open)
|
|
@@ -1915,10 +1928,11 @@
|
|
|
1915
1928
|
if (row && row.sized) { lines.push('📏 Outside your size limits: ' + row.sized + ' (Settings › Playback › Source ranking)'); }
|
|
1916
1929
|
if (row && row.blocked) { lines.push('⚠ ' + row.blocked + ' isn’t allowed (Settings › Playback › Formats)'); }
|
|
1917
1930
|
if (row && row.bad.length) { lines.push('⚠ Marked “Not working” on this TV: ' + row.bad.join(', ') + ' (Settings › Playback › Formats)'); }
|
|
1931
|
+
if (stream._torrent) { lines.push('🧲 A torrent, through your streaming server (Settings › Content › Streaming server)'); }
|
|
1918
1932
|
if (opens) {
|
|
1919
1933
|
lines.push('▶ OK opens ' + (opens.data ? 'it in ' : '') + opens.app.name);
|
|
1920
1934
|
} else if (!playable) {
|
|
1921
|
-
if (stream.infoHash) { lines.push('— torrent
|
|
1935
|
+
if (stream.infoHash) { lines.push('— torrent: plays through a streaming server (Settings › Content › Streaming server)'); }
|
|
1922
1936
|
else if (stream.externalUrl) {
|
|
1923
1937
|
lines.push('— another app' + ((typeof TVApps !== 'undefined' && TVApps.available())
|
|
1924
1938
|
? ': add it in Settings › Content › Streaming apps to open it from here' : ' (not playable here)'));
|
|
@@ -1936,7 +1950,7 @@
|
|
|
1936
1950
|
}
|
|
1937
1951
|
node.__onselect = function () {
|
|
1938
1952
|
if (opens) { openWhere(opens); return; }
|
|
1939
|
-
if (!playable) { U.toast('This source can’t play directly on the TV.'); return; }
|
|
1953
|
+
if (!playable) { U.toast(stream.infoHash ? 'Torrents play through a streaming server: Settings › Content › Streaming server' : 'This source can’t play directly on the TV.', stream.infoHash ? 6000 : undefined); return; }
|
|
1940
1954
|
startPlayback(stream, _d.streamId, _d.streamLabel || _d.meta.name, howHere());
|
|
1941
1955
|
};
|
|
1942
1956
|
return node;
|
|
@@ -1985,6 +1999,7 @@
|
|
|
1985
1999
|
// The player's "Select source" list: each source with the request headers it needs
|
|
1986
2000
|
// (IPTV), so switching to it sends its own (or none).
|
|
1987
2001
|
function playableSources(list) {
|
|
2002
|
+
serverNow(list || _d.streams);
|
|
1988
2003
|
return (list || _d.streams || []).filter(Stremio.isPlayable).map(function (st) {
|
|
1989
2004
|
var sz = Stremio.streamSize(st);
|
|
1990
2005
|
var desc = Stremio.streamDescription(st).replace(/\n/g, ' ');
|
|
@@ -2001,6 +2016,10 @@
|
|
|
2001
2016
|
|
|
2002
2017
|
// how (optional): { fromStart } — Play from start (Continue Watching): from 0:00.
|
|
2003
2018
|
function startPlayback(stream, videoId, label, how) {
|
|
2019
|
+
if (stream && stream.infoHash) { // (a torrent: its link from the streaming server set now)
|
|
2020
|
+
Stremio.torrentSource(stream);
|
|
2021
|
+
if (!stream.url) { U.toast('Torrents play through a streaming server: Settings › Content › Streaming server', 6000); return null; }
|
|
2022
|
+
}
|
|
2004
2023
|
// VOD changes progress/watched state. Live playback does not, and keeping Home
|
|
2005
2024
|
// untouched lets us restore the exact originating card and scroll position.
|
|
2006
2025
|
if (!(_d && _d.exitToBack)) { markHomeDirty(); }
|
|
@@ -2015,8 +2034,10 @@
|
|
|
2015
2034
|
var titleId = _d && _d.id, series = _d && _d.type === 'series', vtype = _d && _d.type;
|
|
2016
2035
|
var remembers = !!(_d && !_d.live);
|
|
2017
2036
|
// (also for another source picked in the player: what's learned is that one's)
|
|
2018
|
-
|
|
2019
|
-
|
|
2037
|
+
// how.converted: played converted by the streaming server, so its formats aren't learned
|
|
2038
|
+
// (they didn't play on the TV); Played before and the kept source still are.
|
|
2039
|
+
function learnFor(st, how) {
|
|
2040
|
+
var info = Stremio.streamInfo(st), fkeys = (how && how.converted) ? [] : Stremio.formatKeys(info);
|
|
2020
2041
|
return {
|
|
2021
2042
|
// (private viewing: nothing about this playback remembered or forgotten — its own
|
|
2022
2043
|
// flag, set when it started, see player-store; what plays on this TV is still learned)
|
|
@@ -2199,13 +2220,20 @@
|
|
|
2199
2220
|
}
|
|
2200
2221
|
|
|
2201
2222
|
// Load a specific episode's sources and auto-play the first playable one.
|
|
2223
|
+
// The next / previous episode (from the player): its sources asked for, the best like the
|
|
2224
|
+
// last one played. An answer once you've left the page, or asked for another episode since
|
|
2225
|
+
// (_epGen), does nothing: no playback, no page drawn, no spinner change, no note.
|
|
2226
|
+
var _epGen = 0;
|
|
2202
2227
|
function playEpisode(v) {
|
|
2228
|
+
var still = pageNow(), gen = ++_epGen;
|
|
2229
|
+
function current() { return still() && gen === _epGen; }
|
|
2203
2230
|
_d.mode = 'streams';
|
|
2204
2231
|
_d.streamId = v.id;
|
|
2205
2232
|
_d.season = (v.season === undefined ? 1 : v.season);
|
|
2206
2233
|
_d.streamLabel = epName(v);
|
|
2207
2234
|
U.spinner(true);
|
|
2208
2235
|
Stremio.getStreams(addonType(), v.id).then(function (list) {
|
|
2236
|
+
if (!current()) { return; }
|
|
2209
2237
|
_d.streams = sortStreams(Stremio.dedupeStreams(list));
|
|
2210
2238
|
U.spinner(false);
|
|
2211
2239
|
var pick = pickLikeLast(_d.id, _d.streams);
|
|
@@ -2215,7 +2243,7 @@
|
|
|
2215
2243
|
return;
|
|
2216
2244
|
}
|
|
2217
2245
|
startPlayback(pick, v.id, _d.streamLabel);
|
|
2218
|
-
}, function () { U.spinner(false); U.toast('Failed to load that episode'); });
|
|
2246
|
+
}, function () { if (!current()) { return; } U.spinner(false); U.toast('Failed to load that episode'); });
|
|
2219
2247
|
}
|
|
2220
2248
|
|
|
2221
2249
|
// ----- binge: the next episode plays a source like the one you've been watching -----
|
package/js/view-discover.js
CHANGED
|
@@ -334,7 +334,7 @@
|
|
|
334
334
|
}
|
|
335
335
|
function rowHeight() {
|
|
336
336
|
var els = _dv.cardEls, c = cols();
|
|
337
|
-
return (els.length > c) ? (els[c].getBoundingClientRect().top - els[0].getBoundingClientRect().top) : 0;
|
|
337
|
+
return (els.length > c) ? (els[c].getBoundingClientRect().top - els[0].getBoundingClientRect().top) / U.zoom() : 0; // (in the grid's own pixels)
|
|
338
338
|
}
|
|
339
339
|
function drawGrid() {
|
|
340
340
|
var grid = gridEl();
|