stremiok 2.2.2 → 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/js/stremio.js CHANGED
@@ -163,6 +163,7 @@ var Stremio = (function () {
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
165
  zoom: [110, 120, 130, 140].indexOf(p.zoom) !== -1 ? p.zoom : 100, // Settings > Appearance: everything bigger (percent)
166
+ rowCards: [50, 100, 200].indexOf(p.rowCards) !== -1 ? p.rowCards : 30, // Settings > Appearance: titles in a Home row
166
167
  formatsAuto: p.formatsAuto !== false, // Settings > Formats: mark "Not working" on its own
167
168
  allowLocal: p.allowLocal === true, // Settings > Addons: home-network links from internet addons
168
169
  addonWait: ADDON_WAITS.indexOf(p.addonWait) !== -1 ? p.addonWait : 0, // Settings > Addons: seconds to wait for an addon (0: Normal)
@@ -434,6 +435,7 @@ var Stremio = (function () {
434
435
  // Appearance > Home feeds; there's no cap on how many rows or feeds).
435
436
  if (iptvNow) { addons.unshift(IPTV.synthAddon()); }
436
437
  else if (iptvOn) { iptvJoin(addons, rev); }
438
+ if (typeof XtVod !== 'undefined' && XtVod.isEnabled()) { addons.push(XtVod.synthAddon()); } // (your Xtream accounts' films and series: after your addons)
437
439
  if (hasYouTube()) { addons.push(YouTube.synthAddon()); } // (after your addons: its rows last on Home)
438
440
  if (typeof Trakt !== 'undefined' && Trakt.isConnected()) { addons.push(Trakt.synthAddon()); } // (your Watchlist and Up next)
439
441
  _loaded = addons;
@@ -488,6 +490,11 @@ var Stremio = (function () {
488
490
  configChanged();
489
491
  return id;
490
492
  }
493
+ function iptvAddStalker(portal, mac) { // (as an Xtream account)
494
+ var id = _hasIptv ? IPTV.addStalker(portal, mac) : false;
495
+ configChanged();
496
+ return id;
497
+ }
491
498
  function iptvSetXtreamFormat(id, fmt) {
492
499
  var changed = _hasIptv ? IPTV.setXtreamFormat(id, fmt) : false;
493
500
  configChanged();
@@ -504,6 +511,16 @@ var Stremio = (function () {
504
511
  function iptvReadAt() { return _hasIptv && IPTV.readAt ? IPTV.readAt() : Infinity; }
505
512
  function iptvStatus(id) { return _hasIptv ? IPTV.status(id) : { error: 'IPTV unavailable' }; }
506
513
  // Force a re-fetch of one playlist (Settings → Reload) and rebuild the addon list.
514
+ // An Xtream account turned out to have films and series, or none (XtVod.onVodChange): the IPTV
515
+ // rows made again from the saved copies (its film and episode lines in or out), not downloaded.
516
+ function iptvRebuild() {
517
+ if (!_hasIptv) { return; }
518
+ IPTV.reset();
519
+ configChanged();
520
+ loadAddons().then(null, function () {});
521
+ }
522
+ if (typeof XtVod !== 'undefined' && XtVod.onVodChange) { XtVod.onVodChange(iptvRebuild); }
523
+ if (typeof XtVod !== 'undefined' && XtVod.onChange) { XtVod.onChange(function () { sourcesChanged(); }); } // (its list read: its copies, on titles asked before)
507
524
  function iptvReload(id) {
508
525
  configChanged();
509
526
  return _hasIptv ? IPTV.reload(id) : Promise.resolve(null);
@@ -761,14 +778,14 @@ var Stremio = (function () {
761
778
  function addonKey(a) { return (a.manifest && a.manifest.id) || a.url; }
762
779
  function streamAddons() {
763
780
  return loadAddons().then(function (addons) {
764
- return addons.filter(function (a) { return !a.__local && supports(a, 'stream'); }).map(function (a) {
781
+ return addons.filter(function (a) { return (!a.__local || a.__sources) && supports(a, 'stream'); }).map(function (a) {
765
782
  return { key: addonKey(a), name: (a.manifest && a.manifest.name) || a.url, addon: a };
766
783
  });
767
784
  });
768
785
  }
769
786
  var sourceFeeds = feedList(SOURCE_FEEDS_KEY, streamAddons, function (x) { return x.key; });
770
787
  // Whether any addon you have provides sources (true while the addons aren't loaded yet)
771
- function hasStreamAddons() { return !_loaded || _loaded.some(function (a) { return !a.__local && supports(a, 'stream'); }); }
788
+ function hasStreamAddons() { return !_loaded || _loaded.some(function (a) { return (!a.__local || a.__sources) && supports(a, 'stream'); }); }
772
789
  function sourcesChanged() { _streamCache = {}; _streamOrder = []; } // (cached lists came from the old set)
773
790
 
774
791
  // ---- Source ranking (Settings > Source ranking) ----
@@ -781,7 +798,7 @@ var Stremio = (function () {
781
798
  ['uncached', 'Not yet cached last', 'sources an addon marks as not cached on your debrid service yet (they can’t start right away)'],
782
799
  ['kind', 'Release type', 'remux > Blu-ray > web > unknown > TV rip, CAM rips far below'],
783
800
  ['hdr', 'HDR before SDR', 'HDR10 / HDR10+ / Dolby Vision first'],
784
- ['seeds', 'Seeders (high to low)', 'torrent sources with more people sharing them first, by the count they state (Torrentio’s 👤 123); the others keep their order'],
801
+ ['seeds', 'Seeders (high to low)', 'torrent sources with more people sharing them first, by the count they state (👤 123, or Seeders: 123); the others keep their order'],
785
802
  ['addon', 'Feed sources order', 'your order of the addons (at the bottom of this page)'],
786
803
  ['within', 'Each addon\'s own order', 'the order an addon lists its sources in (its first, then its second…); right after Feed sources order: each addon\'s list as it gives it'],
787
804
  ['cached', 'Cached before unknown', 'sources an addon marks as cached ahead of ones with no mark']
@@ -872,6 +889,9 @@ var Stremio = (function () {
872
889
  if (/^ytk:/.test(id) && typeof YouTube !== 'undefined') {
873
890
  return YouTube.meta(id).then(function (m) { if (!m) { throw new Error('Not found on YouTube'); } return m; });
874
891
  }
892
+ if (/^xv[ms]\./.test(id) && typeof XtVod !== 'undefined') {
893
+ return XtVod.meta(type, id).then(function (m) { if (!m) { throw new Error('Not found on the Xtream server'); } return m; });
894
+ }
875
895
  if (/^iptv:/.test(id)) {
876
896
  return IPTV.meta(id).then(function (m) {
877
897
  if (!m) { throw new Error('IPTV channel not found'); }
@@ -939,6 +959,9 @@ var Stremio = (function () {
939
959
  if (/^iptv:/.test(id)) {
940
960
  return IPTV.streams(id).then(function (l) { if (onUpdate) { onUpdate(l, 0); } return l; });
941
961
  }
962
+ if (/^xv[ms]\./.test(id) && typeof XtVod !== 'undefined') { // (an Xtream account's own film or episode)
963
+ return XtVod.streams(type, id).then(function (l) { l.forEach(function (s) { s._addon = 'Xtream'; }); if (onUpdate) { onUpdate(l, 0); } return l; });
964
+ }
942
965
  var key = type + ':' + id, e = _streamCache[key];
943
966
  if (e && !force && (e.pending > 0 || Date.now() - e.at < STREAM_TTL)) {
944
967
  syncLocal(e, type, id); // (the addons' answers kept; the USB drive's matches as they are now)
@@ -972,8 +995,10 @@ var Stremio = (function () {
972
995
  return U.settleAll(providers.map(function (a, i) {
973
996
  return function () {
974
997
  var url = a.base + '/stream/' + encodeURIComponent(type) + '/' + encodeURIComponent(id) + '.json';
975
- return U.getJSON(url, addonMs(15000)).then(function (res) {
976
- var arr = U.listOf(fromAddon(a, res, 'sources').streams, MAX_STREAMS).map(youTubeSource).map(torrentSource), said = notes.length;
998
+ // (StremioK's own source, your Xtream accounts' copies: asked here, with the title's details)
999
+ var asked = a.__impl ? metaFirst(type, id).then(function (m) { return a.__impl.streams(type, id, m); }).then(function (l) { return { streams: l }; }) : U.getJSON(url, addonMs(15000));
1000
+ return asked.then(function (res) {
1001
+ var arr = U.listOf(a.__impl ? res.streams : fromAddon(a, res, 'sources').streams, MAX_STREAMS).map(youTubeSource).map(torrentSource), said = notes.length;
977
1002
  arr = arr.filter(function (s) { // (an addon's notices: what it removed and why, its errors; not sources)
978
1003
  if (!isNotice(s)) { return true; }
979
1004
  notes.push({ addon: a.manifest.name || 'Addon', title: ('' + (s.name || '')).replace(/\s+/g, ' ').trim().slice(0, 120),
@@ -1030,6 +1055,15 @@ var Stremio = (function () {
1030
1055
  return e.promise;
1031
1056
  }
1032
1057
 
1058
+ // A title's details, if its page has them (a series': its show's): for StremioK's own sources.
1059
+ function metaKept(type, id) { return _metaCache[type + ':' + (type === 'series' ? ('' + id).split(':')[0] : id)] || null; }
1060
+ // ...asked for when it doesn't yet (a film's sources are asked for alongside its details): the
1061
+ // others' sources don't wait for this one's.
1062
+ function metaFirst(type, id) {
1063
+ var m = metaKept(type, id);
1064
+ if (m) { return Promise.resolve(m); }
1065
+ return getMeta(type, type === 'series' ? ('' + id).split(':')[0] : id).then(null, function () { return null; });
1066
+ }
1033
1067
  function isTimeout(err) { return /^(Timeout|Timed out)/.test((err && err.message) || ''); }
1034
1068
  // Why an addon's sources didn't come, in a few words (its link, and any token in it, left out):
1035
1069
  // "refused (HTTP 429 · rate_limited)", "didn't answer in time", "couldn't be reached"…
@@ -1171,10 +1205,13 @@ var Stremio = (function () {
1171
1205
  r.value.forEach(function (s) {
1172
1206
  if (!s || !s.url || seen[s.url]) { return; }
1173
1207
  seen[s.url] = 1;
1208
+ s._at = out.length; // (your addon order, then each addon's own: the order within a language)
1174
1209
  out.push(s);
1175
1210
  });
1176
1211
  });
1177
- out.sort(function (a, b) { return ('' + (a.lang || '')).localeCompare('' + (b.lang || '')); });
1212
+ // By language, and within one as they came (the TV's sort doesn't keep the order of
1213
+ // equal items: an addon's best match could end up anywhere among its language's).
1214
+ out.sort(function (a, b) { return ('' + (a.lang || '')).localeCompare('' + (b.lang || '')) || a._at - b._at; });
1178
1215
  return out;
1179
1216
  });
1180
1217
  });
@@ -1822,7 +1859,7 @@ var Stremio = (function () {
1822
1859
  return getSearchCatalogs().then(function (cats) {
1823
1860
  var out = [], local = {};
1824
1861
  cats.forEach(function (c) {
1825
- if (c.addon && c.addon.__impl) { // StremioK's own YouTube: "YouTube · Videos"
1862
+ if (c.addon && c.addon.__impl) { // StremioK's own YouTube and Xtream: "YouTube · Videos"
1826
1863
  var nm = prettyType(c.type) + ' · ' + ((c.def && c.def.name) || c.id);
1827
1864
  out.push({ key: catalogKey(c), cats: [c], title: nm, name: nm.replace(/ · /g, ' · '), pages: true });
1828
1865
  return;
@@ -2237,7 +2274,7 @@ var Stremio = (function () {
2237
2274
  importSetupList: importSetupList, savedManifest: savedManifest, isAddonOff: isAddonOff, setAddonOff: setAddonOff, onIptvReady: onIptvReady, streamListenerCount: function (type, id) { var e = _streamCache[type + ':' + id]; return e ? e.listeners.length : 0; },
2238
2275
  iptvGetPlaylists: iptvGetPlaylists, iptvAddPlaylist: iptvAddPlaylist,
2239
2276
  iptvUpdatePlaylist: iptvUpdatePlaylist, iptvRemovePlaylist: iptvRemovePlaylist,
2240
- iptvRenamePlaylist: iptvRenamePlaylist, iptvSetPlaylistGuide: iptvSetPlaylistGuide, iptvAddXtream: iptvAddXtream, iptvSetXtreamFormat: iptvSetXtreamFormat, iptvRefreshEvery: iptvRefreshEvery, iptvSetRefreshEvery: iptvSetRefreshEvery, iptvReadAt: iptvReadAt, iptvSetPlaylistOff: iptvSetPlaylistOff, iptvMovePlaylist: iptvMovePlaylist, iptvLabel: iptvLabel,
2277
+ iptvRenamePlaylist: iptvRenamePlaylist, iptvSetPlaylistGuide: iptvSetPlaylistGuide, iptvAddXtream: iptvAddXtream, iptvAddStalker: iptvAddStalker, iptvSetXtreamFormat: iptvSetXtreamFormat, iptvRefreshEvery: iptvRefreshEvery, iptvSetRefreshEvery: iptvSetRefreshEvery, iptvReadAt: iptvReadAt, iptvSetPlaylistOff: iptvSetPlaylistOff, iptvMovePlaylist: iptvMovePlaylist, iptvLabel: iptvLabel,
2241
2278
  iptvLoad: iptvLoad, iptvStatus: iptvStatus, iptvReload: iptvReload
2242
2279
  };
2243
2280
  })();
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
@@ -1028,12 +1028,14 @@ var U = (function () {
1028
1028
  // settings, addons or playlists clears regenerable caches (in CACHES order) until it
1029
1029
  // fits; if it still doesn't, it's logged and you're told (once a minute at most).
1030
1030
  // A cache that doesn't fit simply isn't saved.
1031
- set: function (key, value) {
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) {
1032
1034
  delete _memo[key];
1033
1035
  _writes++;
1034
1036
  var text;
1035
1037
  try { text = JSON.stringify(value); } catch (e0) { return false; }
1036
- if (tryWrite(key, text)) { return true; }
1038
+ if (tryWrite(key, text)) { if (keep) { _memo[key] = { missing: false, val: value }; } return true; }
1037
1039
  if (isCacheKey(key)) { return false; }
1038
1040
  var freed = [];
1039
1041
  for (var i = 0; i < CACHES.length; i++) {
@@ -1129,6 +1131,79 @@ var U = (function () {
1129
1131
  l.cancel();
1130
1132
  });
1131
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
+ }
1132
1207
  function pumpImages() {
1133
1208
  dropUnwanted();
1134
1209
  if (isHidden()) { return; } // (in the background: nothing new until StremioK is back)
@@ -1139,6 +1214,7 @@ var U = (function () {
1139
1214
  if (!onPage(img) || img.__queuedImage !== item) {
1140
1215
  continue;
1141
1216
  }
1217
+ if (parkIt(item)) { continue; }
1142
1218
  img.__queuedImage = null;
1143
1219
  if (_inflight[item.src]) { _inflight[item.src].push(item); continue; } // already loading
1144
1220
  _imageActive++;
@@ -1277,7 +1353,10 @@ var U = (function () {
1277
1353
  // Called after focus/scroll changes. Load the focused card first, then its
1278
1354
  // closest horizontal neighbors, while the rest continue in the background.
1279
1355
  function prioritizeImages(node) {
1356
+ _lastMove = Date.now();
1280
1357
  if (!node || !node.querySelector || !node.classList.contains('card')) { return; }
1358
+ _lastCard = node;
1359
+ unparkNear(node);
1281
1360
  var nearby = [node];
1282
1361
  var prev = node.previousElementSibling;
1283
1362
  var next = node.nextElementSibling;
package/js/view-core.js CHANGED
@@ -341,6 +341,7 @@ var ViewParts = {};
341
341
  reload.__onselect = function () {
342
342
  closeModal();
343
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)
344
345
  Stremio.iptvReload(playlist.id).then(function () {
345
346
  refreshAddonRows('local:iptv');
346
347
  var st = Stremio.iptvStatus(playlist.id);
@@ -707,6 +708,15 @@ var ViewParts = {};
707
708
  if (sib[i] === card) { idx = list.length; }
708
709
  list.push({ meta: sib[i].__meta, card: sib[i] });
709
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
+ }
710
720
  return { list: list, idx: idx };
711
721
  }
712
722
 
package/js/view-home.js CHANGED
@@ -229,7 +229,7 @@
229
229
  if (what === _savedHomeSig) { return; }
230
230
  _savedHomeSig = what;
231
231
  (_homeCatalogs || []).slice(0, HOME_ROWS_MAX).forEach(function (c) {
232
- if (bytes > _homeBytesMax) { return; }
232
+ if (bytes > _homeBytesMax || c.loading) { return; }
233
233
  var metas = c.metas.map(trimMeta);
234
234
  metas.forEach(function (m) { bytes += sizeOf(m); });
235
235
  if (bytes <= _homeBytesMax) { cats.push(copyCat(c, metas)); }
@@ -1359,6 +1359,12 @@
1359
1359
  if (!node || !scr('home').contains(node)) { return; }
1360
1360
  if (_homeInfoTimer) { clearTimeout(_homeInfoTimer); }
1361
1361
  _homeInfoTimer = setTimeout(function () { _homeInfoTimer = null; fillHomeInfo(node.__meta); }, 120);
1362
+ var row = node.parentNode && node.parentNode.parentNode;
1363
+ if (row && row.__more) { // (a long row: its next cards, as focus nears the end)
1364
+ var left = 0, n = node;
1365
+ while (left < ROW_NEAR && n.nextElementSibling) { n = n.nextElementSibling; left++; }
1366
+ if (left < ROW_NEAR) { row.__more(); }
1367
+ }
1362
1368
  });
1363
1369
 
1364
1370
  // Identify a Home card by its row title + content id, to find it again after a rebuild.
@@ -1375,6 +1381,10 @@
1375
1381
  if (!title || title.textContent !== key.row) { continue; }
1376
1382
  var cards = rows[i].querySelectorAll('.card');
1377
1383
  for (var j = 0; j < cards.length; j++) { if (cards[j].getAttribute('data-id') === key.id) { return cards[j]; } }
1384
+ if (rows[i].__more) { // (a long row: it may be among those not built yet)
1385
+ while (rows[i].__more) { rows[i].__more(); }
1386
+ i--;
1387
+ }
1378
1388
  }
1379
1389
  return null;
1380
1390
  }
@@ -1412,6 +1422,7 @@
1412
1422
  }
1413
1423
  // The IPTV playlists read after your addons loaded (they aren't waited for): their rows join.
1414
1424
  if (typeof Stremio !== 'undefined' && Stremio.onIptvReady) { Stremio.onIptvReady(function () { refreshAddonRows('local:iptv'); }); }
1425
+ if (typeof XtVod !== 'undefined' && XtVod.onChange) { XtVod.onChange(function () { refreshAddonRows('local:xtvod'); }); } // (an Xtream account's films and series, once its categories came)
1415
1426
  var PARTIAL_DELAY = 150; // coalesces catalogs that arrive together into one redraw
1416
1427
  function loadHomeCatalogs() {
1417
1428
  if (_homeLoading) { return; }
@@ -1420,8 +1431,8 @@
1420
1431
  var only = first ? null : _reloadOnly; // a partial reload: just these addons' rows
1421
1432
  _reloadOnly = null;
1422
1433
  _homeFirstLoad = first;
1423
- var old = {};
1424
- (_homeCatalogs || []).forEach(function (c) { old[c.type + '|' + c.name] = c.metas; });
1434
+ var old = {}, oldLoading = {};
1435
+ (_homeCatalogs || []).forEach(function (c) { old[c.type + '|' + c.name] = c.metas; if (c.loading) { oldLoading[c.type + '|' + c.name] = true; } });
1425
1436
  function oldFor(cat) {
1426
1437
  return cat.type === 'other'
1427
1438
  ? (old['movie|' + otherRowName('Movies', cat.name)] || []).concat(old['series|' + otherRowName('Series', cat.name)] || [])
@@ -1441,7 +1452,7 @@
1441
1452
  }
1442
1453
  function onHome() { return _current() === s && !isModalOpen() && !Player.isActive(); }
1443
1454
  Stremio.catalogsForHome().then(function (cats) {
1444
- var acc = cats.map(function (cat) { return copyCat({ name: cat.name, type: cat.type, yt: isYouTubeCat(cat) }, []); });
1455
+ var acc = cats.map(function (cat) { return copyCat({ name: cat.name, type: cat.type, yt: isYouTubeCat(cat) }, [], cat.def && cat.def._favs ? { all: true } : null); }); // (all: IPTV's ★ Favorites, every one)
1445
1456
  var arrived = cats.map(function () { return false; }), shown = 0, partialTimer = null;
1446
1457
  // First load: publish each row as soon as it arrives, in its own place (a slower one above
1447
1458
  // it held by a "Loading…" placeholder, so nothing jumps when it comes), and redraw when
@@ -1467,15 +1478,16 @@
1467
1478
  return function () {
1468
1479
  if (only && !only[cat.addon.url]) { // not the addon that changed: keep its rows
1469
1480
  acc[i].metas = oldFor(cat); arrived[i] = true;
1481
+ if (oldLoading[cat.type + '|' + cat.name]) { acc[i].loading = true; } // (its Loading… stays: an Xtream list still being read)
1470
1482
  return Promise.resolve();
1471
1483
  }
1472
- return Stremio.getCatalog(cat).then(function (metas) { acc[i].metas = metas; }, function () {
1484
+ return catalogUpTo(cat, rowCards()).then(function (metas) { acc[i].metas = metas; if (metas.pending) { acc[i].loading = true; } }, function () {
1473
1485
  acc[i].metas = oldFor(cat);
1474
1486
  }).then(function () { arrived[i] = true; partial(); });
1475
1487
  };
1476
1488
  });
1477
1489
  U.settleAll(tasks, 3).then(function () {
1478
- _homeCatalogs = splitOtherCatalogs(acc).filter(function (c) { return c.metas && c.metas.length; });
1490
+ _homeCatalogs = splitOtherCatalogs(acc).filter(function (c) { return c.loading || (c.metas && c.metas.length); });
1479
1491
  done();
1480
1492
  var want = _wantTab;
1481
1493
  _wantTab = null;
@@ -1504,25 +1516,77 @@
1504
1516
 
1505
1517
  // Catalogs of type "other" (e.g. Torrentio's RealDebrid downloads) aren't live TV:
1506
1518
  // their items go to a Movies row and a Series row, split by the release name.
1507
- // Everything is capped to the ROW_CARDS cards a Home row shows.
1519
+ // Everything is capped to the cards a Home row shows (Settings › Appearance › Titles in a Home
1520
+ // row), but for IPTV's ★ Favorites (all: every one you picked, up to the 300 kept).
1508
1521
  var ROW_CARDS = 30;
1522
+ function rowCards() { return Stremio.getPrefs().rowCards || ROW_CARDS; }
1523
+ // A row's titles, up to n: a catalog that pages (skip) is asked for its next pages (skip =
1524
+ // titles so far, as Discover does) until there are n, a page brings nothing new or fails (what
1525
+ // came is kept), or HOME_PAGES pages. IPTV's and YouTube's own: as they come.
1526
+ var HOME_PAGES = 10;
1527
+ function catalogPages(cat) {
1528
+ var def = cat.def || {};
1529
+ return (def.extra || []).some(function (e) { return e && e.name === 'skip'; }) || (def.extraSupported || []).indexOf('skip') !== -1;
1530
+ }
1531
+ function catalogUpTo(cat, n) {
1532
+ return Stremio.getCatalog(cat).then(function (first) {
1533
+ if ((cat.addon && cat.addon.__local) || first.stale || !first.length || first.length >= n || !catalogPages(cat)) { return first; }
1534
+ var out = first.slice(), seen = {};
1535
+ out.forEach(function (m) { seen[m.id] = 1; });
1536
+ function next(page) {
1537
+ if (out.length >= n || page > HOME_PAGES) { return out; }
1538
+ return Stremio.getCatalog(cat, { skip: out.length }).then(function (more) {
1539
+ var added = 0;
1540
+ more.forEach(function (m) { if (!seen[m.id]) { seen[m.id] = 1; out.push(m); added++; } });
1541
+ return added ? next(page + 1) : out;
1542
+ }, function () { return out; });
1543
+ }
1544
+ return next(2);
1545
+ });
1546
+ }
1509
1547
  var SERIES_NAME = /(^|[^a-z0-9])(s\d{1,2}(e\d{1,3})?|\d{1,2}x\d{2}|season[\s._-]*\d+|temporada[\s._-]*\d+|complete[\s._-]*series)([^a-z0-9]|$)/i;
1510
1548
  function otherRowName(kind, name) { return kind + ' · ' + ('' + name).replace(/^Other · /, ''); }
1511
1549
  function splitOtherCatalogs(list) {
1512
1550
  var out = [];
1513
1551
  list.forEach(function (c) {
1514
1552
  if (c.loading) { if (c.type !== 'other' || c.yt) { out.push(copyCat(c, [], { loading: true })); } return; } // (a placeholder: still loading)
1515
- if (c.type !== 'other' || c.yt) { out.push(copyCat(c, c.metas.slice(0, ROW_CARDS))); return; } // (a YouTube one as it is, whatever its type)
1553
+ if (c.type !== 'other' || c.yt) { out.push(copyCat(c, c.all ? c.metas.slice() : c.metas.slice(0, rowCards()))); return; } // (a YouTube one as it is, whatever its type)
1516
1554
  var movies = [], series = [];
1517
1555
  c.metas.forEach(function (m) { (SERIES_NAME.test(m.name || '') ? series : movies).push(m); });
1518
- out.push({ name: otherRowName('Movies', c.name), type: 'movie', metas: movies.slice(0, ROW_CARDS) });
1519
- out.push({ name: otherRowName('Series', c.name), type: 'series', metas: series.slice(0, ROW_CARDS) });
1556
+ out.push({ name: otherRowName('Movies', c.name), type: 'movie', metas: movies.slice(0, rowCards()) });
1557
+ out.push({ name: otherRowName('Series', c.name), type: 'series', metas: series.slice(0, rowCards()) });
1520
1558
  });
1521
1559
  return out;
1522
1560
  }
1523
1561
 
1562
+ // A long row (up to 200 titles, ★ Favorites up to 300) builds ROW_FIRST cards, not all of them
1563
+ // in one go with the remote waiting, then ROW_MORE at a time when focus is within ROW_NEAR of
1564
+ // the end (Home's Focus.onFocus). row.__rest(): the titles not built yet (CH+ / CH− go through
1565
+ // them); row.__cardOf(meta): its card, built if it wasn't.
1566
+ var ROW_FIRST = 30, ROW_MORE = 30, ROW_NEAR = 8;
1567
+ function lateCards(row, c) {
1568
+ var at = ROW_FIRST, scroller = row.querySelector('.row-scroller');
1569
+ function add(n) {
1570
+ var end = Math.min(c.metas.length, at + n), first = scroller.firstChild, nav = first && first.__navDOWN;
1571
+ for (; at < end; at++) {
1572
+ var card = posterCard(c.metas[at], c.type);
1573
+ if (nav) { card.__navDOWN = nav; } // (the rows below it, as its neighbors)
1574
+ scroller.appendChild(card);
1575
+ }
1576
+ if (at >= c.metas.length) { row.__more = null; }
1577
+ }
1578
+ row.__more = function () { add(ROW_MORE); };
1579
+ row.__rest = function () { return c.metas.slice(at); };
1580
+ row.__cardOf = function (m) {
1581
+ var want = c.metas.indexOf(m), kids = scroller.children;
1582
+ if (want === -1) { return null; }
1583
+ add(want + 1 - at);
1584
+ return kids[want] || null;
1585
+ };
1586
+ }
1587
+
1524
1588
  // Render cats[from .. from+ROW_BATCH) into `rows`. A large IPTV list can have 50+
1525
- // groups x ROW_CARDS cards; building them all up front bloats the DOM, the poster queue
1589
+ // groups x rowCards() cards; building them all up front bloats the DOM, the poster queue
1526
1590
  // and every D-pad scan. While more remain, DOWN on either of the last two rendered
1527
1591
  // rows renders the next batch first, then the normal DOWN move continues into it.
1528
1592
  function appendRows(rows, cats, from, atLeast) {
@@ -1530,7 +1594,8 @@
1530
1594
  var built = [];
1531
1595
  for (var i = from; i < to; i++) {
1532
1596
  var c = cats[i];
1533
- var row = buildRow(c.name, c.metas.map(function (m) { return posterCard(m, c.type); }));
1597
+ var row = buildRow(c.name, c.metas.slice(0, ROW_FIRST).map(function (m) { return posterCard(m, c.type); }));
1598
+ if (c.metas.length > ROW_FIRST) { lateCards(row, c); }
1534
1599
  if (c.loading) { row.className += ' row-loading'; row.appendChild(U.el('div', 'row-empty', 'Loading…')); } // (its place kept: nothing to focus)
1535
1600
  rows.appendChild(row);
1536
1601
  built.push(row);
@@ -215,6 +215,10 @@
215
215
  get: function () { return { zoom: '' + zoomPct() }; },
216
216
  set: function (cfg) { Stremio.setPref('zoom', +cfg.zoom); applyAppearance(); }
217
217
  }));
218
+ wrap.appendChild(subPickRow('Titles in a Home row', [['30', '30'], ['50', '50'], ['100', '100'], ['200', '200']], 'rowCards', {
219
+ get: function () { return { rowCards: '' + Stremio.getPrefs().rowCards }; },
220
+ set: function (cfg) { Stremio.setPref('rowCards', +cfg.rowCards); clearCatalogCache(); } // (the rows read again, with more pages or fewer)
221
+ }));
218
222
  wrap.appendChild(subPickRow('Poster orientation', POSTER_SHAPES, 'posterShape', {
219
223
  get: function () { return { posterShape: Stremio.getPrefs().posterShape }; },
220
224
  set: function (cfg) { Stremio.setPref('posterShape', cfg.posterShape); markHomeDirty(); } // Home redraws on return
@@ -982,6 +986,38 @@
982
986
  }
983
987
  });
984
988
  }
989
+ // + Add Stalker portal: its address, then its MAC address; checked (its channels read through
990
+ // the service), then added (Stremio.iptvAddStalker).
991
+ function addStalker() {
992
+ function done(portal, mac) {
993
+ U.toast('Checking the portal…', 60000);
994
+ IPTV.stalkerCheck(portal, mac).then(function (r) {
995
+ if (r.noService) { U.toast('Stalker portals are read by StremioK’s service, which a desktop browser doesn’t have (nothing was saved)', 5000); return; }
996
+ if (r.unreachable) { U.toast('Couldn’t read the portal' + (r.why ? ' (' + r.why + ')' : '') + ': nothing was saved', 6000); return; }
997
+ if (r.refused) { U.toast('The portal refused that MAC address' + (r.why ? ' (' + r.why + ')' : '') + ': nothing was saved', 6000); return; }
998
+ Stremio.iptvAddStalker(portal, mac);
999
+ refreshAddonRows('local:iptv');
1000
+ U.toast('Stalker portal added: ' + r.count + ' channels', 4000);
1001
+ renderSettings();
1002
+ });
1003
+ }
1004
+ App.openEntry({
1005
+ title: 'Stalker portal: address', phone: 'playlist',
1006
+ hint: 'The portal address your provider gave you (http://portal.example.com/c/). RETURN cancels.',
1007
+ value: 'http://', placeholder: 'http://portal.example.com/c/',
1008
+ validate: function (v) { return IPTV.stalkerPortal(v) ? null : 'That isn’t a portal address'; },
1009
+ onConfirm: function (v) {
1010
+ var portal = IPTV.stalkerPortal(v);
1011
+ App.back();
1012
+ App.openEntry({
1013
+ title: 'Stalker portal: MAC address', phone: 'mac',
1014
+ hint: 'The MAC address your provider registered for you (00:1A:79:…), kept on the TV. RETURN cancels.', value: '00:1A:79:', placeholder: '00:1A:79:00:00:00',
1015
+ validate: function (m) { return IPTV.macOf(m) ? null : 'A MAC address is six pairs, like 00:1A:79:12:34:56'; },
1016
+ onConfirm: function (m) { App.back(); done(portal, IPTV.macOf(m)); }
1017
+ });
1018
+ }
1019
+ });
1020
+ }
985
1021
  // Streaming server: Stremio's or TorrServer, on your network (see Stremio.server). Picking one
986
1022
  // asks for its address; Test says whether it answers.
987
1023
  var SERVERS = [['', 'Off'], ['stremio', 'Stremio server'], ['torrserver', 'TorrServer']];
@@ -1064,7 +1100,7 @@
1064
1100
  var btns = orderButtons(function (dir, name) { move(dir, name)(); }, ctl);
1065
1101
  var item = ctl(U.el('div', 'addon-item focusable playlist-item'), 'item');
1066
1102
  item.appendChild(U.el('div', 'a-name', label + (playlist.off ? ' (off)' : '')));
1067
- item.appendChild(U.el('div', 'a-url', U.redactUrl(playlist.url))); // (credentials masked)
1103
+ item.appendChild(U.el('div', 'a-url', U.redactUrl(playlist.url) + (playlist.mac ? ' · MAC ' + playlist.mac.slice(0, 8) + ':••:••:••' : ''))); // (credentials masked; a Stalker portal's MAC too)
1068
1104
  var info = U.el('div', 'a-url playlist-info', playlistInfo(playlist));
1069
1105
  var problem = U.el('div', 'a-url addon-said', playlistProblem(playlist));
1070
1106
  item.appendChild(info);
@@ -1122,6 +1158,11 @@
1122
1158
  xt.appendChild(U.el('div', 'a-url', 'Its server, username and password: its channels and TV guide added'));
1123
1159
  xt.__onselect = addXtream;
1124
1160
  wrap.appendChild(xt);
1161
+ var sk = U.el('div', 'addon-item focusable add-row');
1162
+ sk.appendChild(U.el('div', 'a-name', '+ Add Stalker portal'));
1163
+ sk.appendChild(U.el('div', 'a-url', 'Its address and MAC address: its channels added'));
1164
+ sk.__onselect = addStalker;
1165
+ wrap.appendChild(sk);
1125
1166
  if (playlists.length && Stremio.iptvRefreshEvery) { // (all of them, with their guides, as Reload does)
1126
1167
  wrap.appendChild(subPickRow('Auto-refresh', IPTV_EVERY, 'every',
1127
1168
  { get: function () { return { every: String(Stremio.iptvRefreshEvery()) }; }, set: function (c) { Stremio.iptvSetRefreshEvery(+c.every); } }));
@@ -1775,6 +1816,7 @@
1775
1816
  line('Settings storage: ' + fmtBytes(inf.ls) + ' (progress, watched marks, settings…)' + (inf.lsTop.length ? '; the largest:' : ''));
1776
1817
  inf.lsTop.forEach(function (e) { line(' ' + fmtBytes(e.bytes) + ' ' + e.key); });
1777
1818
  if (inf.guides && inf.guides.count) { line('Saved TV guides (in StremioK’s folder): ' + fmtBytes(inf.guides.bytes) + ' in ' + inf.guides.count + (inf.guides.count === 1 ? ' file' : ' files')); }
1819
+ if (inf.guides && inf.guides.xtv && inf.guides.xtv.count) { line('Saved Xtream film and series lists (in StremioK’s folder): ' + fmtBytes(inf.guides.xtv.bytes) + ' in ' + inf.guides.xtv.count + (inf.guides.xtv.count === 1 ? ' file' : ' files')); }
1778
1820
  if (inf.disk) { line('The TV’s own disk: ' + fmtBytes(inf.disk.free) + ' free of ' + fmtBytes(inf.disk.total) + ' (what the TV allows StremioK follows it: freeing space, unused apps for one, raises it)'); }
1779
1821
  }
1780
1822
  r.__onselect = function () {
@@ -1816,9 +1858,9 @@
1816
1858
  }
1817
1859
  var clr = U.el('div', 'addon-item focusable');
1818
1860
  clr.appendChild(U.el('div', 'a-name', 'Clear saved copies'));
1819
- clr.appendChild(U.el('div', 'a-url', 'Home’s saved rows, IPTV playlist copies, saved TV guides, the USB index: made again when needed (playlists and guides download again)'));
1861
+ clr.appendChild(U.el('div', 'a-url', 'Home’s saved rows, IPTV playlist copies, saved TV guides and Xtream lists, the USB index: made again when needed (playlists, guides and lists download again)'));
1820
1862
  clr.__onselect = function () {
1821
- confirm('Clear the copies StremioK can make again (Home rows, playlist copies, TV guides, USB index)?', 'Clear', function () {
1863
+ confirm('Clear the copies StremioK can make again (Home rows, playlist copies, TV guides, Xtream lists, USB index)?', 'Clear', function () {
1822
1864
  U.bigStore.keys().then(function (ks) {
1823
1865
  return Promise.all(ks.filter(function (k) { return /^stremiok\.(homecache|local\.index|iptv\.cache\.)/.test(k); }).map(function (k) { return U.bigStore.remove(k); }));
1824
1866
  }).then(function () {