stremiok 2.2.2 → 2.2.4

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: p.rowCards === 'all' || [50, 100, 200].indexOf(p.rowCards) !== -1 ? p.rowCards : 30, // Settings > Appearance: titles in a Home row ('all': Unlimited)
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);
@@ -586,6 +587,11 @@ var ViewParts = {};
586
587
  guideOnCard(c, meta.id);
587
588
  c.__onlongpress = function () { liveSchedule(meta, c); };
588
589
  }
590
+ function isLive() {
591
+ var t = titleType(meta.type || fallbackType);
592
+ var isTitle = t === 'movie' || t === 'series' || TITLE_ID.test(meta.id || '');
593
+ return !!fallbackType && fallbackType !== 'movie' && fallbackType !== 'series' && !isTitle && !/^(youtube|channel)$/i.test(fallbackType) && !/^(ytk|yt_id):/.test(meta.id || '');
594
+ }
589
595
  c.__onselect = function () {
590
596
  var t = titleType(meta.type || fallbackType);
591
597
  // Live TV catalogs (anything that isn't movies/series) skip the info page and
@@ -594,13 +600,16 @@ var ViewParts = {};
594
600
  // (a video plays from it at once, a channel lists its videos). So is anything that
595
601
  // is a movie or series itself, or has a title's id, whatever its catalog's type
596
602
  // (AIOMetadata's "anime" catalogs list movies and series: "mal:28851", a movie).
597
- var isTitle = t === 'movie' || t === 'series' || TITLE_ID.test(meta.id || '');
598
- if (fallbackType && fallbackType !== 'movie' && fallbackType !== 'series' && !isTitle && !/^(youtube|channel)$/i.test(fallbackType) && !/^(ytk|yt_id):/.test(meta.id || '')) {
603
+ if (isLive()) {
599
604
  App.openLive(t, meta.id, meta, rowChannels(c));
600
605
  } else {
601
606
  App.openDetail(t, meta.id, meta);
602
607
  }
603
608
  };
609
+ // the remote's Play key: a movie's or channel's top source; a series has no one episode, so its page
610
+ if (titleType(kind) === 'movie') { c.__onplay = function () { App.openDetail('movie', meta.id, meta, null, { playBest: true }); }; }
611
+ else if (titleType(kind) === 'series') { c.__onplay = function () { c.__onselect(); }; }
612
+ else if (fallbackType !== 'local' && isLive()) { c.__onplay = function () { App.openLive(titleType(kind), meta.id, meta, rowChannels(c), { playBest: true }); }; } // (a channel)
604
613
  return c;
605
614
  }
606
615
 
@@ -707,6 +716,15 @@ var ViewParts = {};
707
716
  if (sib[i] === card) { idx = list.length; }
708
717
  list.push({ meta: sib[i].__meta, card: sib[i] });
709
718
  }
719
+ // (a long row: the channels whose cards aren't built yet too; a card made when it's asked for)
720
+ var row = card.parentNode && card.parentNode.parentNode;
721
+ if (row && row.__rest && row.__more) {
722
+ row.__rest().forEach(function (m) {
723
+ var e = { meta: m };
724
+ Object.defineProperty(e, 'card', { get: function () { return row.__cardOf(m); } });
725
+ list.push(e);
726
+ });
727
+ }
710
728
  return { list: list, idx: idx };
711
729
  }
712
730
 
package/js/view-detail.js CHANGED
@@ -45,7 +45,7 @@
45
45
  return function still() { return _d === page && !(tok && tok.cancelled); };
46
46
  }
47
47
 
48
- function renderLive(type, id, preview, channels) {
48
+ function renderLive(type, id, preview, channels, opts) {
49
49
  newPage();
50
50
  _d = { type: type, id: id, meta: preview || { id: id, type: type }, mode: 'streams',
51
51
  season: null, preview: preview || null, target: null,
@@ -70,6 +70,9 @@
70
70
  }
71
71
  if (playable.length === 1) {
72
72
  startPlayback(playable[0], id, _d.streamLabel || _d.meta.name || 'Live');
73
+ } else if ((opts && opts.playBest) || _d.autoBest) { // (the remote's Play key)
74
+ var top = bestRow(rankRowsFor(list));
75
+ startPlayback(top ? top.st : playable[0], id, _d.streamLabel || _d.meta.name || 'Live');
73
76
  } else {
74
77
  drawDetail(); // multiple sources → straight to the source list
75
78
  }
@@ -80,7 +83,7 @@
80
83
  function renderDetail(type, id, preview, target, opts) {
81
84
  newPage();
82
85
  _d = { type: type, id: id, meta: null, mode: 'info', season: null, preview: preview || null, target: target || null };
83
- var resume = (opts && opts.resume) || null;
86
+ var resume = (opts && opts.resume) || null, playBest = !!(opts && opts.playBest); // (playBest: the remote's Play key)
84
87
  var s = scr('detail');
85
88
  U.clear(s);
86
89
  s.appendChild(U.el('div', 'detail-hero'));
@@ -114,8 +117,10 @@
114
117
  function afterMeta() {
115
118
  asEpisodeList();
116
119
  var files = embeddedFiles(_d.meta);
117
- if (_d.type === 'movie') { openStreams(_d.id, _d.meta.name || _d.meta.title); }
120
+ var ep = playBest && target ? (_d.meta.videos || []).filter(function (v) { return v.id === target; })[0] : null;
121
+ if (_d.type === 'movie') { openStreams(_d.id, _d.meta.name || _d.meta.title, false, playBest ? PLAY_KEY : null); }
118
122
  else if (files.length === 1) { openEmbedded(files[0]); }
123
+ else if (ep) { _d.season = (ep.season === undefined ? 1 : ep.season); openStreams(ep.id, epName(ep), false, PLAY_KEY); }
119
124
  else { drawDetail(); }
120
125
  if (resume) { startResume(resume); }
121
126
  else if (files.length === 1 && (_d.meta.videos || []).length === 1) { playYouTubeNow(files[0]); }
@@ -142,7 +147,7 @@
142
147
  _d.yearSeasons = false;
143
148
  return true;
144
149
  }
145
- function openTitle(v) { App.openDetail('movie', v.id, { id: v.id, type: 'movie', name: v.title || v.name || '', poster: v.thumbnail }); }
150
+ function openTitle(v, opts) { App.openDetail('movie', v.id, { id: v.id, type: 'movie', name: v.title || v.name || '', poster: v.thumbnail }, null, opts); }
146
151
 
147
152
  function asEpisodeList() {
148
153
  if (asCollection()) { return; }
@@ -525,6 +530,7 @@
525
530
  var c = posterCard({ id: 'tmdb:' + item.kind + ':' + item.tmdbId, type: item.type,
526
531
  name: item.name + (item.year ? ' (' + item.year + ')' : ''), poster: item.poster, background: item.background }, item.type);
527
532
  c.__onselect = function () { openTmdbTitle(item); };
533
+ c.__onplay = function () { openTmdbTitle(item, item.type === 'movie' ? { playBest: true } : null); };
528
534
  // hold OK: the menu any poster has (Details, Continue Watching, watched), on the title
529
535
  // by its IMDb id (what the addons, Continue Watching and watched marks know it by)
530
536
  c.__onlongpress = function () {
@@ -532,8 +538,8 @@
532
538
  };
533
539
  return c;
534
540
  }
535
- function openTmdbTitle(item) {
536
- withImdb(item, function (imdb) { App.openDetail(item.type, imdb, { name: item.name, poster: item.poster, type: item.type }); });
541
+ function openTmdbTitle(item, opts) {
542
+ withImdb(item, function (imdb) { App.openDetail(item.type, imdb, { name: item.name, poster: item.poster, type: item.type }, null, opts); });
537
543
  }
538
544
  function withImdb(item, then) {
539
545
  U.spinner(true);
@@ -848,6 +854,10 @@
848
854
  if (up.resume && up.resume.url) { startResume(up.resume); }
849
855
  else { openStreams(up.v.id, epName(up.v), false, AUTO); }
850
856
  };
857
+ btn.__onplay = function () {
858
+ if (up.resume && up.resume.url) { startResume(up.resume); }
859
+ else { openStreams(up.v.id, epName(up.v), false, PLAY_KEY); }
860
+ };
851
861
  // hold OK: where you were, or the episode from the start (its saved source; with none
852
862
  // saved, its page, where everything then plays from the start)
853
863
  if (up.resume && up.resume.position > 0) {
@@ -1046,6 +1056,7 @@
1046
1056
  var row = U.el('div', 'btn-row');
1047
1057
  var play = U.el('div', 'pill focusable', '▶ Play');
1048
1058
  play.__onselect = function () { openStreams(_d.id, _d.meta.name, false, AUTO); };
1059
+ play.__onplay = function () { openStreams(_d.id, _d.meta.name, false, PLAY_KEY); };
1049
1060
  row.appendChild(play);
1050
1061
  return row;
1051
1062
  }
@@ -1275,6 +1286,10 @@
1275
1286
  if (_d.collection) { openTitle(v); return; }
1276
1287
  openStreams(v.id, epName(v), false, AUTO);
1277
1288
  };
1289
+ e.__onplay = function () {
1290
+ if (_d.collection) { openTitle(v, { playBest: true }); return; }
1291
+ openStreams(v.id, epName(v), false, PLAY_KEY);
1292
+ };
1278
1293
  e.__onlongpress = function () { if (_d.collection) { collectionMenu(meta, v); } else { episodeMenu(meta, v); } };
1279
1294
  if (_d.target && v.id === _d.target) { _d._epFocus = e; }
1280
1295
  listScroll.appendChild(e);
@@ -1645,11 +1660,13 @@
1645
1660
 
1646
1661
  // how (optional): { fromStart } — everything played from the page plays from the start;
1647
1662
  // { auto } — Skip the source list (Settings › Source ranking): the top source plays once the
1648
- // addons have answered (with nothing playable, the list shows as usual).
1649
- var AUTO = { auto: true };
1663
+ // addons have answered (with nothing playable, the list shows as usual); { always }: whatever
1664
+ // that setting says (the remote's Play key).
1665
+ var AUTO = { auto: true }, PLAY_KEY = { auto: true, always: true };
1650
1666
  function openStreams(videoId, label, force, how) {
1651
1667
  if (!force) { _d.fromStart = !!(how && how.fromStart); } // (a re-scan keeps it)
1652
- var auto = !force && !!(how && how.auto) && Stremio.getPrefs().skipSourceList && !_d.live;
1668
+ var auto = !force && !!(how && how.auto) && (how.always || Stremio.getPrefs().skipSourceList) && !_d.live;
1669
+ _d.autoBest = null;
1653
1670
  _d.mode = 'streams';
1654
1671
  _d.streamId = videoId;
1655
1672
  _d.streamLabel = label;
@@ -1686,7 +1703,7 @@
1686
1703
  }, force).then(function (list) {
1687
1704
  if (!here() && !Player.isActive()) { U.spinner(false); }
1688
1705
  show(list, 0);
1689
- if (auto && here() && !Player.isActive()) { // (Skip the source list: the top one plays)
1706
+ if (here() && (auto || _d.autoBest === videoId) && !Player.isActive()) { // (Skip the source list, the Play key: the top one plays)
1690
1707
  var top = (_d.streams && _d.streams.length) ? bestRow(rankRowsFor(_d.streams)) : null;
1691
1708
  if (top) { startPlayback(top.st, videoId, label, howHere()); return; }
1692
1709
  }
@@ -1787,6 +1804,15 @@
1787
1804
  };
1788
1805
  return p;
1789
1806
  }
1807
+ // The remote's Play key on a title's or channel's sources, wherever focus is on them: ▶ Play best. With
1808
+ // nothing to pick yet, once the addons have answered.
1809
+ function playKey() {
1810
+ if (!_d || _d.mode !== 'streams' || !_d.streamId) { return; }
1811
+ var best = (_d.streams && _d.streams.length) ? bestRow(filterRows(rankRowsFor(_d.streams))) : null;
1812
+ if (best) { startPlayback(best.st, _d.streamId, _d.streamLabel || _d.meta.name, howHere()); }
1813
+ else if (!_d.streams || _d.streamsPending > 0) { _d.autoBest = _d.streamId; }
1814
+ else { U.toast('Nothing here plays on this TV'); }
1815
+ }
1790
1816
  function streamActionsBar() {
1791
1817
  var row = U.el('div', 'btn-row streams-actions');
1792
1818
  var allRows = (_d.streams && _d.streams.length) ? rankRowsFor(_d.streams) : [];
@@ -2330,6 +2356,7 @@
2330
2356
  V.episodeWatched = episodeWatched;
2331
2357
  V.nextUp = nextUp;
2332
2358
  V.renderDetail = renderDetail;
2359
+ V.playKey = playKey;
2333
2360
  V.leaveDetail = leaveDetail;
2334
2361
  V.renderLive = renderLive;
2335
2362
  V.renderPerson = renderPerson;
package/js/view-guide.js CHANGED
@@ -169,6 +169,7 @@
169
169
  wait.__meta = { name: c.name, releaseInfo: 'Reading its TV guide…' };
170
170
  hooks(wait, -1);
171
171
  wait.__onlongpress = function () { hold(g, r, null); };
172
+ if (!c.guideOnly) { wait.__onplay = function () { playChannel(g, r, true); }; }
172
173
  track.appendChild(wait);
173
174
  nodes.push(wait);
174
175
  if (want && want.id === c.id) { found = wait; }
@@ -182,6 +183,7 @@
182
183
  n.__p = p; n.__i = i;
183
184
  n.__onselect = function () { pick(g, r, p); };
184
185
  n.__onlongpress = function () { hold(g, r, p); };
186
+ if (!c.guideOnly) { n.__onplay = function () { playChannel(g, r, true); }; } // (the remote's Play key: the channel, whichever program)
185
187
  hooks(n, i);
186
188
  track.appendChild(n);
187
189
  nodes.push(n);
@@ -284,24 +286,24 @@
284
286
  for (var i = 0; i < nodes.length; i++) { if (nodes[i].__p === p) { return nodes[i]; } }
285
287
  return false;
286
288
  }
287
- // OK: what's on now plays the channel; another program says what it is.
288
289
  // Played, CH+ / CH− go through the Guide's channels; each one's card (where BACK lands, on
289
- // the channel you end on) is what's on now on it.
290
+ // the channel you end on) is what's on now on it. best: the remote's Play key.
291
+ function playChannel(g, r, best) {
292
+ var c = g.chans[r], now = Date.now() / 1000, list = [], idx = 0;
293
+ g.chans.forEach(function (ch, i) { // (every channel: a cell only for the rows drawn, where BACK lands)
294
+ if (ch.guideOnly) { return; } // (nothing to play)
295
+ var nodes = g.nodes[i] || [], card = nodes[0] || null;
296
+ for (var j = 0; j < nodes.length; j++) { if (nodes[j].__p.start <= now && now < nodes[j].__p.stop) { card = nodes[j]; break; } }
297
+ if (i === r) { idx = list.length; }
298
+ list.push({ meta: { id: ch.id, type: ch.type, name: ch.name, poster: ch.logo || '', logo: ch.logo || '', posterShape: 'landscape' }, card: card });
299
+ });
300
+ App.openLive(c.type, c.id, list[idx].meta, { list: list, idx: idx }, best ? { playBest: true } : null);
301
+ }
302
+ // OK: what's on now plays the channel; another program says what it is.
290
303
  function pick(g, r, p) {
291
304
  var c = g.chans[r], now = Date.now() / 1000;
292
305
  if (c.guideOnly) { findInAddons(p); return; }
293
- if (p.start <= now && now < p.stop) {
294
- var list = [], idx = 0;
295
- g.chans.forEach(function (ch, i) { // (every channel: a cell only for the rows drawn, where BACK lands)
296
- if (ch.guideOnly) { return; } // (nothing to play)
297
- var nodes = g.nodes[i] || [], card = nodes[0] || null;
298
- for (var j = 0; j < nodes.length; j++) { if (nodes[j].__p.start <= now && now < nodes[j].__p.stop) { card = nodes[j]; break; } }
299
- if (i === r) { idx = list.length; }
300
- list.push({ meta: { id: ch.id, type: ch.type, name: ch.name, poster: ch.logo || '', logo: ch.logo || '', posterShape: 'landscape' }, card: card });
301
- });
302
- App.openLive(c.type, c.id, list[idx].meta, { list: list, idx: idx });
303
- return;
304
- }
306
+ if (p.start <= now && now < p.stop) { playChannel(g, r); return; }
305
307
  U.toast(EPG.dayTime(p.start) + '–' + EPG.hhmm(p.stop) + ' ' + c.name + ' · ' + p.title + (p.desc ? ': ' + p.desc : '') +
306
308
  (p.stop <= now ? ' (already shown)' : ''), 8000);
307
309
  }