stremiok 2.2.7 → 2.2.9

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/view-core.js CHANGED
@@ -140,6 +140,47 @@ var ViewParts = {};
140
140
  }, function () { if (!over) { how.textContent = 'Your phone can’t reach the TV just now (no home network, or StremioK’s service isn’t running): type it instead.'; } });
141
141
  }
142
142
  function qrSpotCanvas(text) { var s = qrSpot(text); s.className = ''; return s; }
143
+ // A file given to the phone (an export: YTPlay.entryGive): a QR to the service's one-time page
144
+ // that shows it to copy or download; kept open while the QR is on screen (asked every
145
+ // GIVE_POLL_MS, which also says once the phone has it), closed with Done.
146
+ var GIVE_POLL_MS = 3000;
147
+ function phoneGive(title, text, note) {
148
+ var existing = document.querySelector('.modal-overlay');
149
+ if (existing) { existing.parentNode.removeChild(existing); }
150
+ var overlay = U.el('div', 'modal-overlay'), box = U.el('div', 'modal-box qr-box');
151
+ box.appendChild(U.el('div', 'modal-msg', title));
152
+ var spot = U.el('div', 'qr-spot'), how = U.el('div', 'qr-note', 'Opening the page for your phone…'), link = U.el('div', 'qr-link', '');
153
+ box.appendChild(spot); box.appendChild(link); box.appendChild(how);
154
+ if (note) { box.appendChild(U.el('div', 'qr-note', note)); }
155
+ var row = U.el('div', 'modal-row'), done = U.el('div', 'pill focusable modal-btn', 'Done');
156
+ var token = null, timer = null, over = false;
157
+ done.__onselect = function () { closeModal(); };
158
+ row.appendChild(done); box.appendChild(row); overlay.appendChild(box);
159
+ document.body.appendChild(overlay);
160
+ showModal(overlay, done);
161
+ onModalClose(function () { over = true; if (timer) { clearTimeout(timer); } if (token && YTPlay.entryClose) { YTPlay.entryClose(token); } token = null; });
162
+ function poll() {
163
+ timer = setTimeout(function () {
164
+ timer = null;
165
+ if (over || !token) { return; }
166
+ YTPlay.entrySeen(token).then(function (seen) {
167
+ if (over) { return; }
168
+ if (seen) { how.textContent = 'Your phone has it: copy or download it there, then Done.'; }
169
+ poll();
170
+ }, function () { if (!over) { how.textContent = 'The phone page closed. Export again to open another.'; token = null; } });
171
+ }, GIVE_POLL_MS);
172
+ }
173
+ if (typeof YTPlay === 'undefined' || !YTPlay.entryGive) { how.textContent = 'It needs StremioK’s service on the TV (not in a desktop browser).'; return; }
174
+ YTPlay.entryGive(text).then(function (r) {
175
+ if (over) { if (r && r.token) { YTPlay.entryClose(r.token); } return; }
176
+ if (!r || !r.url) { throw new Error('no page'); }
177
+ token = r.token;
178
+ spot.appendChild(qrSpotCanvas(r.url));
179
+ link.textContent = r.url;
180
+ how.textContent = 'Scan it with your phone (on the same Wi-Fi as the TV): the page shows the file to copy or download. For the next 5 minutes, unencrypted over your home network: only on a network you trust.';
181
+ poll();
182
+ }, function () { if (!over) { how.textContent = 'Your phone can’t reach the TV just now (no home network, or StremioK’s service isn’t running).'; } });
183
+ }
143
184
 
144
185
  // Show `overlay` (already in the page) as the modal: focus moves into it, and
145
186
  // closeModal() returns focus to where it was on the screen underneath.
@@ -444,7 +485,7 @@ var ViewParts = {};
444
485
  var go = U.el('div', 'pill focusable modal-btn');
445
486
  function ticked() { return items.filter(function (it) { return on[it.key]; }).map(function (it) { return it.key; }); }
446
487
  function drawGo() { go.textContent = opts.button(ticked().length); }
447
- var all = U.el('div', 'pick-item focusable', 'Select all');
488
+ var all = U.el('div', 'pick-item focusable', can.length && can.every(function (it) { return on[it.key]; }) ? 'Select none' : 'Select all'); // (all ticked at first: an export's)
448
489
  all.__onselect = function () {
449
490
  var every = can.every(function (it) { return on[it.key]; });
450
491
  can.forEach(function (it) { on[it.key] = !every; });
@@ -615,7 +656,9 @@ var ViewParts = {};
615
656
  }
616
657
  function isLive() {
617
658
  var t = titleType(meta.type || fallbackType);
618
- var isTitle = t === 'movie' || t === 'series' || TITLE_ID.test(meta.id || '');
659
+ // (an "anime" or "other" item: a title whatever its id; a debrid library's download, an
660
+ // addon's own "cnc:…" show: its page, so its episodes or files, not a channel's sources)
661
+ var isTitle = t === 'movie' || t === 'series' || TITLE_ID.test(meta.id || '') || /^(anime|other)$/i.test(t || '');
619
662
  return !!fallbackType && fallbackType !== 'movie' && fallbackType !== 'series' && !isTitle && !/^(youtube|channel)$/i.test(fallbackType) && !/^(ytk|yt_id):/.test(meta.id || '');
620
663
  }
621
664
  c.__onselect = function () {
@@ -890,7 +933,7 @@ var ViewParts = {};
890
933
  V.buildTopMenu = buildTopMenu;
891
934
  V.closeModal = closeModal;
892
935
  V.confirm = confirm;
893
- V.qrModal = qrModal;
936
+ V.qrModal = qrModal; V.phoneGive = phoneGive;
894
937
  V.phoneEntry = phoneEntry;
895
938
  V.header = header;
896
939
  V.isModalOpen = isModalOpen;
package/js/view-detail.js CHANGED
@@ -151,8 +151,22 @@
151
151
  }
152
152
  function openTitle(v, opts) { App.openDetail('movie', v.id, { id: v.id, type: 'movie', name: v.title || v.name || '', poster: v.thumbnail }, null, opts); }
153
153
 
154
+ // A series by its details, whatever its card or row called it (an anime addon's: a film,
155
+ // "anime", "other"): they say it's a series, or list numbered episodes without files of
156
+ // their own. Its seasons and episodes, then, not sources. (A YouTube list: as it is.)
157
+ var AS_SERIES = /^(movie|anime|other)$/;
158
+ function asSeries() {
159
+ var meta = _d.meta, vids = (meta && Array.isArray(meta.videos)) ? meta.videos : [];
160
+ if (!vids.length || !AS_SERIES.test('' + _d.type) || /^(ytk|yt_id):/.test('' + (meta.id || _d.id))) { return false; }
161
+ if (vids.some(function (v) { return !v || (v.streams && v.streams.length); })) { return false; }
162
+ var numbered = vids.length > 1 && vids.every(function (v) { return typeof v.season === 'number' && typeof v.episode === 'number'; });
163
+ if (meta.type !== 'series' && !numbered) { return false; }
164
+ _d.type = 'series';
165
+ return true;
166
+ }
167
+
154
168
  function asEpisodeList() {
155
- if (asCollection()) { return; }
169
+ if (asCollection() || asSeries()) { return; } // (a collection first: its films are numbered too)
156
170
  var meta = _d.meta, t = _d.type;
157
171
  // (opened again as a series, from Continue Watching: still a YouTube list, by its own type)
158
172
  var again = !!meta && t === 'series' && /^(ytk|yt_id):/.test('' + (meta.id || _d.id)) && !!meta.type && meta.type !== 'series';
@@ -243,7 +257,14 @@
243
257
  var listed = _d.mode === 'streams' || (_d.mode === 'info' && _d.type === 'series'); // (a source list, an episode list)
244
258
  var hero = U.el('div', 'detail-hero' + (listed ? ' hero-full' : '')); // (a list: over the whole backdrop)
245
259
  var bg = meta.background || meta.poster;
246
- if (bg) { U.deferBg(hero, U.cardImage(bg, 'hero'), true); } // (sized for the page, first in the queue)
260
+ // (sized for the page, first in the queue; one that doesn't load: the next of its
261
+ // pictures, a YouTube video's 1280x720 ones first: U.heroImages)
262
+ var heroes = bg ? U.heroImages(bg) : [];
263
+ (function heroTry(i) {
264
+ if (i >= heroes.length) { return; }
265
+ hero.__bgFail = function () { heroTry(i + 1); };
266
+ U.deferBg(hero, heroes[i], true);
267
+ })(0);
247
268
  hero.appendChild(U.el('div', 'shade'));
248
269
  s.appendChild(hero);
249
270
  s.appendChild(buildTopMenu('detail')); // the main menu, above the title
@@ -1262,6 +1283,13 @@
1262
1283
  var hide = spoilerFor(v); // (Hide spoilers: an episode not watched yet)
1263
1284
  var thumb = U.el('div', 'ep-thumb' + (hide ? ' spoiler' : ''));
1264
1285
  // through the poster queue: a season's thumbnails don't all download at once
1286
+ var ref = { num: v.episode, thumb: thumb, hasThumb: !!v.thumbnail, hideOv: hide === 'all', still: null };
1287
+ // (the addon's picture doesn't load, now or earlier: TMDB's, with a key, once known; see below)
1288
+ thumb.__bgFail = function () {
1289
+ thumb.__bgFail = null; // (once: TMDB's failing too is the end of it)
1290
+ ref.hasThumb = false;
1291
+ if (ref.still) { ref.hasThumb = true; U.deferBg(thumb, U.cardImage(ref.still, 'still')); }
1292
+ };
1265
1293
  if (v.thumbnail) { U.deferBg(thumb, U.cardImage(v.thumbnail, 'still')); }
1266
1294
  var pr = !watched && Player.progressFor(_d.collection ? 'movie' : 'series', v.id);
1267
1295
  if (pr && pr.duration && pr.position > 0) { // partly watched: progress stripe
@@ -1295,7 +1323,8 @@
1295
1323
  e.__onlongpress = function () { if (_d.collection) { collectionMenu(meta, v); } else { episodeMenu(meta, v); } };
1296
1324
  if (_d.target && v.id === _d.target) { _d._epFocus = e; }
1297
1325
  listScroll.appendChild(e);
1298
- epRefs.push({ num: v.episode, thumb: thumb, rating: rating, ov: ov, hasThumb: !!v.thumbnail, hideOv: hide === 'all' });
1326
+ ref.rating = rating; ref.ov = ov;
1327
+ epRefs.push(ref);
1299
1328
  });
1300
1329
  panel.appendChild(listScroll);
1301
1330
 
@@ -1322,6 +1351,7 @@
1322
1351
  epRefs.forEach(function (r) {
1323
1352
  var ep = map[r.num];
1324
1353
  if (!ep) { return; }
1354
+ if (ep.still) { r.still = ep.still; } // (kept: for the addon's picture, should it fail)
1325
1355
  if (ep.still && !r.hasThumb) { r.hasThumb = true; U.deferBg(r.thumb, U.cardImage(ep.still, 'still')); }
1326
1356
  // Fill the rating only if OMDb didn't provide one for this episode
1327
1357
  // (OMDb's dataset is missing IMDb ratings for some episodes).
@@ -1591,19 +1621,30 @@
1591
1621
  }
1592
1622
  U.store.set(UNSUIT_KEY, all);
1593
1623
  }
1594
- // Hold OK on a source: Play from the start (a place to resume), Not suitable (or back), and
1624
+ // Hold OK on a source: Play from the start (a place to resume), Play through StremioK's service
1625
+ // (an HLS one), Not suitable (or back), and
1595
1626
  // with a USB drive plugged in, Download to it (js/downloads.js). With only Not suitable to
1596
1627
  // offer, it's asked at once.
1628
+ // An HLS source (not YouTube, DRM or a USB file): Play through StremioK's service, this once
1629
+ // (Settings › Playback › Seeking & buffering › HLS through StremioK's service, for all of them).
1630
+ function serviceHlsOk(stream) {
1631
+ if (!stream || stream._yt || stream._localFile || stream._drm || typeof YTPlay === 'undefined' || YTPlay.installMode() === 'browser') { return false; }
1632
+ var url = '' + (stream.url || '');
1633
+ return /^https?:\/\//i.test(url) && (/\.m3u8?(?:[?#]|$)/i.test(url) || Stremio.streamInfo(stream).container === 'hls');
1634
+ }
1597
1635
  function sourceMenu(stream) {
1598
1636
  var canStart = !howHere() && savedPlace(_d.streamId);
1599
1637
  var canDownload = typeof Downloads !== 'undefined' && Downloads.available() && (Downloads.isFileLink ? Downloads.isFileLink(stream) : /^https?:\/\//i.test(stream.url || '')) && !stream._localFile && !stream._yt;
1600
- if (!canStart && !canDownload) { toggleUnsuitable(stream); return; }
1638
+ var canService = serviceHlsOk(stream);
1639
+ if (!canStart && !canDownload && !canService) { toggleUnsuitable(stream); return; }
1601
1640
  var unsuit = isUnsuitable(_d.id, stream), opts = [];
1602
1641
  if (canStart) { opts.push(['start', 'Play from the start']); }
1642
+ if (canService) { opts.push(['service', 'Play through StremioK’s service']); }
1603
1643
  if (canDownload) { opts.push(['download', '⬇ Download to USB drive']); }
1604
1644
  opts.push(['suit', unsuit ? 'Put back among the sources' : 'Not suitable']);
1605
1645
  pickList(Stremio.streamName(stream), opts, null, function (k) {
1606
1646
  if (k === 'start') { startPlayback(stream, _d.streamId, _d.streamLabel || _d.meta.name, { fromStart: true }); }
1647
+ else if (k === 'service') { startPlayback(stream, _d.streamId, _d.streamLabel || _d.meta.name, { viaService: true, fromStart: !!howHere() }); }
1607
1648
  else if (k === 'download') { downloadSource(stream); }
1608
1649
  else { toggleUnsuitable(stream); }
1609
1650
  });
@@ -2126,7 +2167,7 @@
2126
2167
  var ctx = { url: stream.url, type: _d.type, addonType: _d.addonType, id: videoId, name: label, parent: _d.id,
2127
2168
  poster: _d.meta.poster, background: _d.meta.background, streams: playableSources(), _headers: U.sanitizeHeaders(stream._headers) || undefined, zap: zap, zapTo: zap ? zapToChannel : null,
2128
2169
  localSubs: stream._localSubs, localFile: stream._localFile,
2129
- subExtra: fileHintsOf(stream), sourceSubs: sourceSubsOf(stream), formatInfo: Stremio.streamInfo(stream), fromStart: !!(how && how.fromStart) || undefined,
2170
+ subExtra: fileHintsOf(stream), sourceSubs: sourceSubsOf(stream), formatInfo: Stremio.streamInfo(stream), fromStart: !!(how && how.fromStart) || undefined, viaService: !!(how && how.viaService) || undefined,
2130
2171
  titleIds: titleIdsOf(_d.meta, videoId), stream: stream, nextSource: nextSourceFor, downloadAs: typeof Downloads !== 'undefined' ? downloadTitle(videoId) : undefined,
2131
2172
  onStarted: learn.onStarted, onFailed: learn.onFailed, learnFor: learnFor };
2132
2173
  if (_d.type === 'series' && _d.meta.videos) {
@@ -227,13 +227,13 @@
227
227
  });
228
228
  });
229
229
  var ofType = _dv.cats.filter(function (c) { return c.type === _dv.type; });
230
- pill('Catalog: ' + catLabel(_dv.cat) + ' ▾', function () {
230
+ pill('Catalog: ' + catLabel(_dv.cat) + ' ▾', function () { // (.discover-cat: the one cut short when the bar is full)
231
231
  pickList('Catalog', ofType.map(function (c) { return [Stremio.catalogKey(c), catLabel(c)]; }), Stremio.catalogKey(_dv.cat), function (k) {
232
232
  var c = ofType.filter(function (x) { return Stremio.catalogKey(x) === k; })[0];
233
233
  if (!c || c === _dv.cat) { return; }
234
234
  choose(_dv.type, c); reload();
235
235
  });
236
- });
236
+ }).className += ' discover-cat';
237
237
  var f = genreFilter(_dv.cat);
238
238
  if (f) {
239
239
  pill(f.label + ': ' + (_dv.value ? genreLabel(_dv.value) : 'All') + ' ▾', function () { genrePicker(f, false); });
@@ -323,18 +323,23 @@
323
323
  // measures nothing.
324
324
  var WINDOW = 600;
325
325
  function gridEl() { return scr('discover').querySelector('.discover-grid'); }
326
+ // A card's top in the grid's own pixels: where it's laid out (offsetTop), not where it's
327
+ // drawn: the focused card is drawn larger (its scale), its top a few pixels higher, and a
328
+ // single row (three titles) measured with it counted one card per row: LEFT / RIGHT went
329
+ // nowhere and UP / DOWN went along the row.
330
+ function cardTop(el) { return typeof el.offsetTop === 'number' ? el.offsetTop : el.getBoundingClientRect().top / U.zoom(); }
326
331
  function cols() {
327
332
  var els = _dv.cardEls || [];
328
333
  if (_dv.cols && els.length > _dv.cols) { return _dv.cols; }
329
334
  if (els.length < 2) { return 1; }
330
- var top = els[0].getBoundingClientRect().top, n = 1; // (the cards of the first row share its top)
331
- while (n < els.length && Math.abs(els[n].getBoundingClientRect().top - top) < 2) { n++; }
335
+ var top = cardTop(els[0]), n = 1; // (the cards of the first row share its top)
336
+ while (n < els.length && Math.abs(cardTop(els[n]) - top) < 2) { n++; }
332
337
  if (n < els.length) { _dv.cols = n; } // (known once a second row exists)
333
338
  return Math.max(1, n);
334
339
  }
335
340
  function rowHeight() {
336
341
  var els = _dv.cardEls, c = cols();
337
- return (els.length > c) ? (els[c].getBoundingClientRect().top - els[0].getBoundingClientRect().top) / U.zoom() : 0; // (in the grid's own pixels)
342
+ return (els.length > c) ? cardTop(els[c]) - cardTop(els[0]) : 0; // (in the grid's own pixels)
338
343
  }
339
344
  function drawGrid() {
340
345
  var grid = gridEl();
package/js/view-home.js CHANGED
@@ -650,7 +650,7 @@
650
650
  };
651
651
  c.__onlongpress = function () { continueActions(e, base, preview, target, c); };
652
652
  c.__cwKey = showKey(e);
653
- c.__meta = { name: e.name, description: e.position
653
+ c.__meta = { _id: base, _bg: a.background || e.background || '', _ep: e.type === 'series' && target ? codeOfId(target) : '', name: e.name, description: e.position
654
654
  ? 'Resume at ' + U.fmtTime(e.position) + (e.duration ? ' of ' + U.fmtTime(e.duration) : '')
655
655
  : e.upNext !== undefined ? 'Next episode' + (e.upNext ? ': “' + e.upNext + '”' : '') + ' · from Trakt'
656
656
  : 'Added, not started yet' };
@@ -786,7 +786,7 @@
786
786
  var c = posterCard({ id: u.show, type: 'series', name: u.name, poster: u.poster || calPoster(u.show) }, 'series');
787
787
  var code = epCodeOf(u.ep);
788
788
  c.appendChild(U.el('div', 'card-new card-code', code));
789
- c.__meta = { name: u.name, description: code + (u.ep.t ? ' “' + u.ep.t + '”' : '') + ' · ' + (u.ep.r > now ? 'out ' : 'came out ') + U.dayLabel(u.ep.r) };
789
+ c.__meta = { _id: u.show, name: u.name, description: code + (u.ep.t ? ' “' + u.ep.t + '”' : '') + ' · ' + (u.ep.r > now ? 'out ' : 'came out ') + U.dayLabel(u.ep.r) };
790
790
  c.__onselect = function () { App.openDetail('series', u.show, { name: u.name, poster: u.poster, type: 'series' }, u.ep.id); };
791
791
  c.__onplay = function () { App.openDetail('series', u.show, { name: u.name, poster: u.poster, type: 'series' }, u.ep.id, { playBest: true }); };
792
792
  return c;
@@ -1240,9 +1240,12 @@
1240
1240
  if (launch && asked === 'guide' && (Stremio.getPrefs().hiddenTabs || []).indexOf('guide') === -1) { _wantGuide = _homeTab; } // (see EPG.onChange below)
1241
1241
  }
1242
1242
 
1243
+ var hero = U.look() === 'modern' && !NO_HERO[_homeTab]; // (Modern: the focused title's backdrop, behind it all)
1244
+ if (hero) { s.appendChild(homeBackdrop(_homeTab)); }
1243
1245
  s.appendChild(buildTopMenu(_homeTab));
1244
- // The focused title's details, between the top menu and the rows (#home-info).
1245
- var info = U.el('div', 'home-info');
1246
+ // The focused title's details, between the top menu and the rows (#home-info); Modern's
1247
+ // title tabs: large, over the backdrop (hero).
1248
+ var info = U.el('div', 'home-info' + (hero ? ' hero' : ''));
1246
1249
  info.appendChild(U.el('div', 'home-info-title'));
1247
1250
  info.appendChild(U.el('div', 'home-info-meta'));
1248
1251
  info.appendChild(U.el('div', 'home-info-desc'));
@@ -1315,7 +1318,61 @@
1315
1318
  // Details strip: updated when focus settles on a Home card (debounced, so holding a
1316
1319
  // direction doesn't redo it for every card passed).
1317
1320
  var _homeInfoTimer = null;
1318
- function fillHomeInfo(m) { fillInfoBox(scr('home').querySelector('.home-info'), m); }
1321
+ function fillHomeInfo(m) { fillInfoBox(scr('home').querySelector('.home-info'), m); fillBackdrop(scr('home').querySelector('.home-bg'), m); }
1322
+ // Modern look: the focused title's backdrop behind Home, two layers taking turns, so the
1323
+ // new one fades in over the last (Effects: Full) once it has loaded; a picture that doesn't
1324
+ // load gives way to the next of its choices (U.heroImages). A title without one: black; the
1325
+ // menu (no title): the last kept. Not on the live tabs and Local (their pictures are
1326
+ // logos and program stills: the details strip shows those).
1327
+ var NO_HERO = { tv: 1, guide: 1, radio: 1, sport: 1, local: 1 };
1328
+ var _homeBg = { tab: '', src: '' }; // (the last one, for when Home draws that tab again)
1329
+ function homeBackdrop(tab) {
1330
+ var bg = U.el('div', 'home-bg');
1331
+ bg.appendChild(U.el('div', 'hb'));
1332
+ bg.appendChild(U.el('div', 'hb'));
1333
+ bg.appendChild(U.el('div', 'hb-shade'));
1334
+ if (_homeBg.src && _homeBg.tab === tab) { bg.children[0].style.backgroundImage = 'url("' + _homeBg.src + '")'; bg.children[0].className = 'hb on'; bg.__src = _homeBg.src; }
1335
+ bg.__tab = tab;
1336
+ return bg;
1337
+ }
1338
+ // Continue Watching and the Calendar keep only a little of a title: for an IMDb one, its logo
1339
+ // is Cinemeta's for that id (one that doesn't load: its name, as for any logo).
1340
+ function ttLogo(m) {
1341
+ var tt = m && m._id && /^(tt\d{5,10})(?::|$)/.exec(m._id);
1342
+ return tt ? 'https://images.metahub.space/logo/medium/' + tt[1] + '/img' : '';
1343
+ }
1344
+ // A title's backdrop: its own; else, for an IMDb title (Continue Watching, the Calendar keep
1345
+ // only a little of it), Cinemeta's picture for that id.
1346
+ function backdropOf(m) {
1347
+ if (!m) { return null; }
1348
+ var b = m.background || m._bg || '', tt = !b && /^(tt\d{5,10})(?::|$)/.exec(m.id || m._id || '');
1349
+ if (tt) { b = 'https://images.metahub.space/background/medium/' + tt[1] + '/img'; }
1350
+ return U.heroImages(b);
1351
+ }
1352
+ function fillBackdrop(bg, m) {
1353
+ if (!bg || !m || !(m.name || m.title)) { return; } // (the menu: the last one stays)
1354
+ var list = backdropOf(m) || [], key = list.join(' ');
1355
+ if (bg.__src === key) { return; }
1356
+ bg.__src = key;
1357
+ function show(src) {
1358
+ var on = bg.querySelector('.hb.on'), next = on === bg.children[0] ? bg.children[1] : bg.children[0];
1359
+ if (src) { next.style.backgroundImage = 'url("' + src + '")'; next.className = 'hb on'; }
1360
+ if (on) { on.className = 'hb'; }
1361
+ _homeBg = { tab: bg.__tab, src: src || '' };
1362
+ }
1363
+ if (!list.length) { show(''); return; }
1364
+ (function next(i) {
1365
+ if (i >= list.length) { if (bg.__src === key) { show(''); } return; }
1366
+ var img = new Image();
1367
+ img.onload = function () {
1368
+ if (bg.__src !== key) { return; } // (focus moved on before it came)
1369
+ if (img.naturalWidth && img.naturalWidth < 200) { next(i + 1); return; } // (a stand-in, not the picture)
1370
+ show(list[i]);
1371
+ };
1372
+ img.onerror = function () { if (bg.__src === key) { next(i + 1); } };
1373
+ img.src = list[i];
1374
+ })(0);
1375
+ }
1319
1376
  // Fill a details strip (Home, Discover) with a title's logo / name, facts and synopsis.
1320
1377
  function fillInfoBox(box, m) {
1321
1378
  if (!box) { return; }
@@ -1329,10 +1386,17 @@
1329
1386
  if (m.name || m.title) { box.classList.add('on'); } else { box.classList.remove('on'); } // shaded only while describing a title
1330
1387
  var t = box.children[0], name = m.name || m.title || '';
1331
1388
  U.clear(t);
1332
- var logoSrc = U.cardImage(m.logo, 'logo');
1389
+ var logoSrc = U.cardImage(m.logo || ttLogo(m), 'logo');
1390
+ // an episode in Continue Watching: its name says which (Breaking Bad S1E1), its logo
1391
+ // doesn't, so the facts begin with it then
1392
+ var ep = logoSrc && m._ep ? m._ep : '';
1333
1393
  if (logoSrc) { // the title's logo when it has one; its name if that fails to load
1334
1394
  var img = U.el('img', 'home-info-logo');
1335
- img.onerror = function () { if (img.parentNode === t) { U.clear(t); t.textContent = name; } };
1395
+ img.onerror = function () {
1396
+ if (img.parentNode !== t) { return; }
1397
+ U.clear(t); t.textContent = name;
1398
+ if (ep && box.children[1].textContent.indexOf(ep) === 0) { box.children[1].textContent = box.children[1].textContent.slice(ep.length).replace(/^\s*·\s*/, ''); }
1399
+ };
1336
1400
  t.appendChild(img);
1337
1401
  U.deferImage(img, logoSrc, true); // (through the queue, ahead of the rest)
1338
1402
  } else {
@@ -1344,6 +1408,7 @@
1344
1408
  bits = ['Now ' + EPG.hhmm(g.now.start) + '–' + EPG.hhmm(g.now.stop) + ' ' + g.now.title];
1345
1409
  desc = (g.now.desc ? g.now.desc + ' ' : '') + (g.next ? 'Next ' + EPG.hhmm(g.next.start) + ' ' + g.next.title : '');
1346
1410
  }
1411
+ if (ep) { bits.unshift(ep); }
1347
1412
  box.children[1].textContent = bits.join(' · ');
1348
1413
  box.children[2].textContent = desc;
1349
1414
  // a program's picture from the TV guide (the Guide tab's focused one, a channel's now)
@@ -74,8 +74,9 @@
74
74
  if (cfg.phone && V.phoneEntry) {
75
75
  var phoneBtn = U.el('div', 'pill focusable', '▣ From your phone');
76
76
  phoneBtn.__onselect = function () {
77
- V.phoneEntry({ title: cfg.title || 'Enter value', what: cfg.phone, validate: cfg.validate,
78
- onText: function (t) { input.value = t; Focus.setFocus(confirmBtn); U.toast('From your phone: check it, then Confirm', 3500); },
77
+ var takes = cfg.phoneText; // (text the caller takes as it is from the phone: an import's pasted file)
78
+ V.phoneEntry({ title: cfg.title || 'Enter value', what: cfg.phone, validate: function (t) { return takes && takes.accepts(t) ? null : (cfg.validate ? cfg.validate(t) : null); },
79
+ onText: function (t) { if (takes && takes.accepts(t)) { takes.take(t); return; } input.value = t; Focus.setFocus(confirmBtn); U.toast('From your phone: check it, then Confirm', 3500); },
79
80
  onType: function () { Focus.setFocus(input); } });
80
81
  };
81
82
  row.appendChild(phoneBtn);
@@ -196,9 +197,15 @@
196
197
  // Zoom: everything bigger (see U.setZoom), in percent.
197
198
  var ZOOMS = [['100', '100%'], ['110', '110%'], ['120', '120%'], ['130', '130%'], ['140', '140%']];
198
199
  function zoomPct() { return Stremio.getPrefs().zoom; }
200
+ // Look: Classic (the stylesheet as it is) or Modern (css/modern.css, its rules only under
201
+ // body.look-modern). Effects, Modern's blur and motion: Auto turns them on where the TV's
202
+ // browser can blur behind a panel (Tizen 6 and later), Light keeps them off, Full on.
203
+ var LOOKS = [['classic', 'Classic'], ['modern', 'Modern']];
204
+ var EFFECTS = [['auto', 'Auto (by the TV)'], ['light', 'Light'], ['full', 'Full']];
199
205
  function applyAppearance() {
200
- var a = appearance();
206
+ var a = appearance(), p = Stremio.getPrefs();
201
207
  U.applyTheme(a.accent, a.bg);
208
+ U.setLook(p.look, p.effects, a.bg === 'gray' || a.bg === 'white');
202
209
  U.setZoom(zoomPct() / 100);
203
210
  }
204
211
  function settingsAppearance(wrap) {
@@ -209,6 +216,10 @@
209
216
  } };
210
217
  var accents = U.ACCENT_KEYS.map(function (k) { return [k, ACCENT_NAMES[k] || k, null, U.accentColor(k)]; });
211
218
  wrap.appendChild(U.el('h2', null, 'Appearance'));
219
+ var looks = { get: function () { var p = Stremio.getPrefs(); return { look: p.look, effects: p.effects }; },
220
+ set: function (cfg) { Stremio.setPref('look', cfg.look); Stremio.setPref('effects', cfg.effects); applyAppearance(); markHomeDirty(); } };
221
+ wrap.appendChild(subPickRow('Look', LOOKS, 'look', looks));
222
+ wrap.appendChild(subPickRow('Effects', EFFECTS, 'effects', looks));
212
223
  wrap.appendChild(subPickRow('Background', BACKGROUNDS, 'bg', store));
213
224
  wrap.appendChild(subPickRow('Accent color', accents, 'accent', store));
214
225
  wrap.appendChild(subPickRow('Zoom', ZOOMS, 'zoom', {
@@ -367,7 +378,8 @@
367
378
  ['YouTube', 'Your YouTube channels, playlists and searches; YouTube in Search', 'youtube'],
368
379
  ['Streaming apps', 'Your apps (Prime Video, Netflix, …) that open a title\'s "where to watch" sources', 'appshortcuts'],
369
380
  ['USB drive', 'The Local tab: what\'s on your drive, matched to titles; hidden files', 'usb'],
370
- ['Import configuration file', 'Import addons, API keys & IPTV playlists', 'import']] },
381
+ ['Import configuration file', 'Import addons, API keys & IPTV playlists', 'import'],
382
+ ['Export configuration', 'Your addons, playlists, API keys and settings, to your phone', 'export']] },
371
383
  playback: { title: 'Playback', rows: [
372
384
  ['Audio', 'Preferred and second-choice audio language', 'audio'],
373
385
  ['Subtitles', 'Default language, size, color, background, position, font', 'subtitles'],
@@ -430,6 +442,7 @@
430
442
  else if (_settingsSection === 'private') { settingsPrivate(wrap); }
431
443
  else if (_settingsSection === 'appshortcuts') { settingsAppShortcuts(wrap); }
432
444
  else if (_settingsSection === 'import') { settingsImport(wrap); }
445
+ else if (_settingsSection === 'export') { settingsExport(wrap); }
433
446
  else if (_settingsSection === 'aiomanager') { settingsAiom(wrap); }
434
447
  else if (_settingsSection === 'server') { settingsServer(wrap); }
435
448
  else if (_settingsSection === 'appearance') { settingsAppearance(wrap); }
@@ -475,7 +488,7 @@
475
488
  wrap.appendChild(U.el('h2', null, 'Settings'));
476
489
  wrap.appendChild(sectionRow('Content', 'Addons, API keys, IPTV playlists, streaming apps, importing a configuration file', 'content'));
477
490
  wrap.appendChild(sectionRow('Playback', 'Audio and subtitles, source ranking, feed sources, formats', 'playback'));
478
- wrap.appendChild(sectionRow('Appearance', 'Background, accent color, zoom, posters, spoilers', 'appearance'));
491
+ wrap.appendChild(sectionRow('Appearance', 'Look, background, accent color, zoom, posters, spoilers', 'appearance'));
479
492
  wrap.appendChild(sectionRow('Home', 'The tab it opens on, the top menu, Home feeds, Search results', 'home'));
480
493
  wrap.appendChild(sectionRow('Diagnostics', 'Logs, storage, installed apps; how StremioK was installed', 'diagnostics'));
481
494
  if (typeof YTPlay !== 'undefined' && YTPlay.installMode && YTPlay.installMode() === 'tizenbrew') { wrap.appendChild(U.el('div', 'hint', TIZENBREW_NOTE)); }
@@ -856,6 +869,53 @@
856
869
  var IMPORT_URL_KEY = 'stremiok.importurl';
857
870
 
858
871
  var _importGen = 0; // (the configuration file being imported, the latest)
872
+ // A configuration file's text: what it has listed, none ticked, to tick and import. here():
873
+ // the entry screen still showing (back to Settings from it). Imported settings: StremioK
874
+ // starts again with them.
875
+ function importText(text, here) {
876
+ var parsed = Stremio.parseSetupList(text);
877
+ if (!parsed.items.length) { U.toast('No supported entries found in that file' + (parsed.ignored ? ' (' + parsed.ignored + ' ignored)' : ''), 4500); return; }
878
+ if (here()) { App.back(); renderSettings(); }
879
+ pickMany('In that file: tick what to import', parsed.items.map(function (it, i) { return { key: '' + i, label: it.label, have: it.have, note: it.note }; }),
880
+ { button: function (n) { return 'Import ' + n; } }, function (keys) {
881
+ var imported = Stremio.applySetupEntries(keys.map(function (k) { return parsed.items[+k]; })), parts = [];
882
+ if (imported.addons) { parts.push(imported.addons + ' addon' + (imported.addons === 1 ? '' : 's')); }
883
+ if (imported.playlists) { parts.push(imported.playlists + ' playlist' + (imported.playlists === 1 ? '' : 's')); }
884
+ if (imported.omdb) { parts.push('OMDb key'); }
885
+ if (imported.tmdb) { parts.push('TMDB key'); }
886
+ if (imported.mdblist) { parts.push('MDBList key'); }
887
+ if (imported.settings) { parts.push('your settings'); }
888
+ if (imported.addons || imported.playlists) { clearCatalogCache(); }
889
+ var message = parts.length ? ('Imported: ' + parts.join(', ')) : 'Nothing imported';
890
+ if (parsed.ignored) { message += ' (' + parsed.ignored + ' ignored)'; }
891
+ if (imported.settings) { // (every part of StremioK reads them afresh)
892
+ U.toast(message + '. StremioK starts again with them…', 4000);
893
+ setTimeout(function () { try { window.location.reload(); } catch (e) {} }, 2500);
894
+ return;
895
+ }
896
+ U.toast(message, 4500);
897
+ renderSettings();
898
+ });
899
+ }
900
+ // Settings › Content › Export configuration: what goes in, all ticked at first, given to your
901
+ // phone (V.phoneGive) as the file Import configuration file reads (Stremio.exportSetup).
902
+ function settingsExport(wrap) {
903
+ wrap.appendChild(U.el('h2', null, 'Export configuration'));
904
+ var row = U.el('div', 'addon-item focusable add-row');
905
+ row.appendChild(U.el('div', 'a-name', '⇧ Export to your phone'));
906
+ row.appendChild(U.el('div', 'a-url', 'Your addons, IPTV playlists, API keys and settings, as a file to import later'));
907
+ row.__onselect = function () {
908
+ var groups = Stremio.exportGroups();
909
+ pickMany('Tick what to export', groups.map(function (g) { return { key: g.key, label: g.label }; }),
910
+ { on: groups.map(function (g) { return g.key; }), button: function (n) { return 'Export ' + n; } }, function (keys) {
911
+ V.phoneGive('Export configuration', Stremio.exportSetup(keys, appVersion()),
912
+ 'It holds your addon links, playlist logins, API keys and MAC addresses: keep the file private. Not in it: your Trakt sign-in, history and progress.');
913
+ });
914
+ };
915
+ wrap.appendChild(row);
916
+ wrap.appendChild(U.el('div', 'hint', 'To restore it (after a reinstall, or on another TV): Import configuration file › ▣ From your phone, then choose the file there (or paste it).'));
917
+ focusSettings();
918
+ }
859
919
  function settingsImport(wrap) {
860
920
  wrap.appendChild(U.el('h2', null, 'Import configuration file'));
861
921
  var lastUrl = U.store.get(IMPORT_URL_KEY, '') || '';
@@ -881,34 +941,17 @@
881
941
  var entry = scr('addaddon'), mine = ++_importGen;
882
942
  function here() { return mine === _importGen && !/\bhidden\b/.test(entry.className); }
883
943
  U.getText(v, 15000, 256 * 1024).then(function (text) { // (a list of URLs and keys: 256 KB is plenty)
884
- var parsed = Stremio.parseSetupList(text);
885
- if (!parsed.items.length) { U.toast('No supported entries found in that file' + (parsed.ignored ? ' (' + parsed.ignored + ' ignored)' : ''), 4500); return; }
886
- if (here()) { App.back(); renderSettings(); }
887
- // what the file has, none ticked: you tick what to import
888
- pickMany('In that file: tick what to import', parsed.items.map(function (it, i) { return { key: '' + i, label: it.label, have: it.have, note: it.note }; }),
889
- { button: function (n) { return 'Import ' + n; } }, function (keys) {
890
- done(Stremio.applySetupEntries(keys.map(function (k) { return parsed.items[+k]; })), parsed.ignored);
891
- });
944
+ importText(text, here);
892
945
  }, function (err) {
893
946
  if (!here()) { return; }
894
947
  var why = U.problem(err);
895
948
  U.toast(/^too large/.test(why) ? 'That file is ' + why + ': a configuration file is a short list of URLs and keys.'
896
949
  : 'Could not fetch that configuration file (' + why + '; check the URL / CORS).', 5000);
897
950
  });
898
- function done(imported, ignored) {
899
- var parts = [];
900
- if (imported.addons) { parts.push(imported.addons + ' addon' + (imported.addons === 1 ? '' : 's')); }
901
- if (imported.playlists) { parts.push(imported.playlists + ' playlist' + (imported.playlists === 1 ? '' : 's')); }
902
- if (imported.omdb) { parts.push('OMDb key'); }
903
- if (imported.tmdb) { parts.push('TMDB key'); }
904
- if (imported.mdblist) { parts.push('MDBList key'); }
905
- if (imported.addons || imported.playlists) { clearCatalogCache(); }
906
- var message = parts.length ? ('Imported: ' + parts.join(', ')) : 'Nothing imported';
907
- if (ignored) { message += ' (' + ignored + ' ignored)'; }
908
- U.toast(message, 4500);
909
- renderSettings();
910
- }
911
- }
951
+ },
952
+ // From your phone, the file itself pasted (not a link): imported as it is
953
+ phoneText: { accepts: function (t) { return /\n/.test(t) || !/^https?:\/\//i.test(('' + t).trim()); },
954
+ take: function (t) { ++_importGen; importText(t, function () { return true; }); } }
912
955
  });
913
956
  };
914
957
  wrap.appendChild(listRow);
@@ -1196,6 +1239,13 @@
1196
1239
  }
1197
1240
  }));
1198
1241
 
1242
+ if (typeof StVod !== 'undefined' && StVod.keepMinutes) { // (what the service keeps of a portal's films and series)
1243
+ wrap.appendChild(subPickRow('Stalker films and series', [['10', 'Kept 10 minutes'], ['5', 'Kept 5 minutes'], ['0', 'Off (asked each time)']], 'keep', {
1244
+ get: function () { return { keep: String(StVod.keepMinutes()) }; },
1245
+ set: function (c) { StVod.setKeepMinutes(+c.keep); }
1246
+ }));
1247
+ }
1248
+
1199
1249
  wrap.appendChild(U.el('div', 'hint',
1200
1250
  'Channels are grouped into IPTV and Radio rows on Home. ▲ / ▼ set the playlists\' order: a channel in two playlists comes from the first.'));
1201
1251
  var s = scr('settings'), want = null;
@@ -1603,14 +1653,17 @@
1603
1653
  // Seeking & buffering: how far LEFT / RIGHT jump; a bigger buffer for slow connections; how
1604
1654
  // often a live channel that drops is opened again.
1605
1655
  var RECONNECTS = [['off', 'Off'], ['few', 'A few times (3 in 5 minutes)'], ['always', 'Keep trying']];
1656
+ // (an HLS source through the service, with its own headers on every piece: see player-core's viaService)
1657
+ var HLS_ROUTES = [['off', 'Off'], ['headers', 'Sources that need headers'], ['all', 'All HLS sources']];
1606
1658
  function settingsSeeking(wrap) {
1607
1659
  wrap.appendChild(U.el('h2', null, 'Seeking & buffering'));
1608
- var store = { get: function () { var c = Player.playerCfg(); return { seek: '' + c.seek, buffer: c.buffer, reconnect: c.reconnect }; },
1609
- set: function (cfg) { Player.setPlayerCfg({ seek: +cfg.seek || 10, buffer: cfg.buffer, reconnect: cfg.reconnect }); } };
1660
+ var store = { get: function () { var c = Player.playerCfg(); return { seek: '' + c.seek, buffer: c.buffer, reconnect: c.reconnect, hls: c.hls }; },
1661
+ set: function (cfg) { Player.setPlayerCfg({ seek: +cfg.seek || 10, buffer: cfg.buffer, reconnect: cfg.reconnect, hls: cfg.hls }); } };
1610
1662
  wrap.appendChild(subPickRow('Seek step', [['5', '5 s'], ['10', '10 s'], ['15', '15 s'], ['30', '30 s']], 'seek', store));
1611
1663
  wrap.appendChild(subPickRow('Buffer', [['normal', 'Normal (the TV’s own)'], ['more', 'More'], ['most', 'Most']], 'buffer', store));
1612
1664
  wrap.appendChild(subPickRow('Reconnect live channels', RECONNECTS, 'reconnect', store));
1613
- wrap.appendChild(U.el('div', 'hint', 'Seek step: how far LEFT / RIGHT jump (FF / REW jump three steps). Buffer: More or Most starts a little slower but stops less on a slow connection, from the next video you play. Reconnect: a live channel that drops opens again; Keep trying waits a little longer each time (BACK stops it).'));
1665
+ wrap.appendChild(subPickRow('HLS through StremioK’s service', HLS_ROUTES, 'hls', store));
1666
+ wrap.appendChild(U.el('div', 'hint', 'Seek step: FF / REW jump three. Buffer: More or Most starts slower but stops less on a slow connection. Reconnect: a live channel that drops opens again (BACK stops it). HLS through StremioK’s service: for a host that wants headers the TV’s player can’t send; a step more before it starts.'));
1614
1667
  focusSettings();
1615
1668
  }
1616
1669
  function settingsSkipping(wrap) {