stremiok 2.2.7 → 2.2.8

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; });
@@ -890,7 +931,7 @@ var ViewParts = {};
890
931
  V.buildTopMenu = buildTopMenu;
891
932
  V.closeModal = closeModal;
892
933
  V.confirm = confirm;
893
- V.qrModal = qrModal;
934
+ V.qrModal = qrModal; V.phoneGive = phoneGive;
894
935
  V.phoneEntry = phoneEntry;
895
936
  V.header = header;
896
937
  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';
@@ -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);
@@ -367,7 +368,8 @@
367
368
  ['YouTube', 'Your YouTube channels, playlists and searches; YouTube in Search', 'youtube'],
368
369
  ['Streaming apps', 'Your apps (Prime Video, Netflix, …) that open a title\'s "where to watch" sources', 'appshortcuts'],
369
370
  ['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']] },
371
+ ['Import configuration file', 'Import addons, API keys & IPTV playlists', 'import'],
372
+ ['Export configuration', 'Your addons, playlists, API keys and settings, to your phone', 'export']] },
371
373
  playback: { title: 'Playback', rows: [
372
374
  ['Audio', 'Preferred and second-choice audio language', 'audio'],
373
375
  ['Subtitles', 'Default language, size, color, background, position, font', 'subtitles'],
@@ -430,6 +432,7 @@
430
432
  else if (_settingsSection === 'private') { settingsPrivate(wrap); }
431
433
  else if (_settingsSection === 'appshortcuts') { settingsAppShortcuts(wrap); }
432
434
  else if (_settingsSection === 'import') { settingsImport(wrap); }
435
+ else if (_settingsSection === 'export') { settingsExport(wrap); }
433
436
  else if (_settingsSection === 'aiomanager') { settingsAiom(wrap); }
434
437
  else if (_settingsSection === 'server') { settingsServer(wrap); }
435
438
  else if (_settingsSection === 'appearance') { settingsAppearance(wrap); }
@@ -856,6 +859,53 @@
856
859
  var IMPORT_URL_KEY = 'stremiok.importurl';
857
860
 
858
861
  var _importGen = 0; // (the configuration file being imported, the latest)
862
+ // A configuration file's text: what it has listed, none ticked, to tick and import. here():
863
+ // the entry screen still showing (back to Settings from it). Imported settings: StremioK
864
+ // starts again with them.
865
+ function importText(text, here) {
866
+ var parsed = Stremio.parseSetupList(text);
867
+ if (!parsed.items.length) { U.toast('No supported entries found in that file' + (parsed.ignored ? ' (' + parsed.ignored + ' ignored)' : ''), 4500); return; }
868
+ if (here()) { App.back(); renderSettings(); }
869
+ 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 }; }),
870
+ { button: function (n) { return 'Import ' + n; } }, function (keys) {
871
+ var imported = Stremio.applySetupEntries(keys.map(function (k) { return parsed.items[+k]; })), parts = [];
872
+ if (imported.addons) { parts.push(imported.addons + ' addon' + (imported.addons === 1 ? '' : 's')); }
873
+ if (imported.playlists) { parts.push(imported.playlists + ' playlist' + (imported.playlists === 1 ? '' : 's')); }
874
+ if (imported.omdb) { parts.push('OMDb key'); }
875
+ if (imported.tmdb) { parts.push('TMDB key'); }
876
+ if (imported.mdblist) { parts.push('MDBList key'); }
877
+ if (imported.settings) { parts.push('your settings'); }
878
+ if (imported.addons || imported.playlists) { clearCatalogCache(); }
879
+ var message = parts.length ? ('Imported: ' + parts.join(', ')) : 'Nothing imported';
880
+ if (parsed.ignored) { message += ' (' + parsed.ignored + ' ignored)'; }
881
+ if (imported.settings) { // (every part of StremioK reads them afresh)
882
+ U.toast(message + '. StremioK starts again with them…', 4000);
883
+ setTimeout(function () { try { window.location.reload(); } catch (e) {} }, 2500);
884
+ return;
885
+ }
886
+ U.toast(message, 4500);
887
+ renderSettings();
888
+ });
889
+ }
890
+ // Settings › Content › Export configuration: what goes in, all ticked at first, given to your
891
+ // phone (V.phoneGive) as the file Import configuration file reads (Stremio.exportSetup).
892
+ function settingsExport(wrap) {
893
+ wrap.appendChild(U.el('h2', null, 'Export configuration'));
894
+ var row = U.el('div', 'addon-item focusable add-row');
895
+ row.appendChild(U.el('div', 'a-name', '⇧ Export to your phone'));
896
+ row.appendChild(U.el('div', 'a-url', 'Your addons, IPTV playlists, API keys and settings, as a file to import later'));
897
+ row.__onselect = function () {
898
+ var groups = Stremio.exportGroups();
899
+ pickMany('Tick what to export', groups.map(function (g) { return { key: g.key, label: g.label }; }),
900
+ { on: groups.map(function (g) { return g.key; }), button: function (n) { return 'Export ' + n; } }, function (keys) {
901
+ V.phoneGive('Export configuration', Stremio.exportSetup(keys, appVersion()),
902
+ '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.');
903
+ });
904
+ };
905
+ wrap.appendChild(row);
906
+ 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).'));
907
+ focusSettings();
908
+ }
859
909
  function settingsImport(wrap) {
860
910
  wrap.appendChild(U.el('h2', null, 'Import configuration file'));
861
911
  var lastUrl = U.store.get(IMPORT_URL_KEY, '') || '';
@@ -881,34 +931,17 @@
881
931
  var entry = scr('addaddon'), mine = ++_importGen;
882
932
  function here() { return mine === _importGen && !/\bhidden\b/.test(entry.className); }
883
933
  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
- });
934
+ importText(text, here);
892
935
  }, function (err) {
893
936
  if (!here()) { return; }
894
937
  var why = U.problem(err);
895
938
  U.toast(/^too large/.test(why) ? 'That file is ' + why + ': a configuration file is a short list of URLs and keys.'
896
939
  : 'Could not fetch that configuration file (' + why + '; check the URL / CORS).', 5000);
897
940
  });
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
- }
941
+ },
942
+ // From your phone, the file itself pasted (not a link): imported as it is
943
+ phoneText: { accepts: function (t) { return /\n/.test(t) || !/^https?:\/\//i.test(('' + t).trim()); },
944
+ take: function (t) { ++_importGen; importText(t, function () { return true; }); } }
912
945
  });
913
946
  };
914
947
  wrap.appendChild(listRow);
package/js/ytplay.js CHANGED
@@ -50,6 +50,17 @@ var YTPlay = (function () {
50
50
  var t = (typeof LocalMedia !== 'undefined' && LocalMedia.serviceToken) ? LocalMedia.serviceToken() : Promise.resolve('');
51
51
  return t.then(function (tk) { return tk ? { q: '&token=' + encodeURIComponent(tk), h: null } : HEADER; }, function () { return HEADER; });
52
52
  }
53
+ // An export (a configuration file) given to the phone: a one-time page to copy or download it
54
+ // -> { url, token } (polled like an entry: { seen }; closed with entryClose). POSTed: the token,
55
+ // or the guide ticket (the page's POST carries an Origin the header alone doesn't pass).
56
+ function entryGive(text) {
57
+ if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
58
+ return ensureService().then(entryAuth).then(function (a) {
59
+ return (a.q ? Promise.resolve(a.q) : ticketOf(a)).then(function (cred) {
60
+ return U.postJSON(PROXY + '/entry/give' + (cred ? '?' + cred.replace(/^&/, '') : ''), text, 10000, 65536, a.h);
61
+ });
62
+ });
63
+ }
53
64
  function entryOpen(what) {
54
65
  return entryAuth().then(function (a) { return U.getJSON(PROXY + '/entry/open?what=' + encodeURIComponent(what || 'link') + a.q, 8000, undefined, null, a.h); });
55
66
  }
@@ -57,6 +68,10 @@ var YTPlay = (function () {
57
68
  return entryAuth().then(function (a) { return U.getJSON(PROXY + '/entry/poll?t=' + encodeURIComponent(token) + a.q, 5000, undefined, null, a.h); })
58
69
  .then(function (r) { return (r && typeof r.text === 'string') ? r.text : null; });
59
70
  }
71
+ function entrySeen(token) { // (an export's page: kept open by asking, and whether the phone has opened it)
72
+ return entryAuth().then(function (a) { return U.getJSON(PROXY + '/entry/poll?t=' + encodeURIComponent(token) + a.q, 5000, undefined, null, a.h); })
73
+ .then(function (r) { return !!(r && r.seen); });
74
+ }
60
75
  function entryClose(token) {
61
76
  return entryAuth().then(function (a) { return U.getText(PROXY + '/entry/close?t=' + encodeURIComponent(token) + a.q, 4000, 4096, null, true, a.h); }).then(null, function () {});
62
77
  }
@@ -71,7 +86,7 @@ var YTPlay = (function () {
71
86
  if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
72
87
  var cc = opts && opts.cc ? opts.cc.map(function (c) { return c.ch + (c.lang ? '-' + c.lang : ''); }).join(',') : '';
73
88
  return ensureService().then(entryAuth).then(function (a) {
74
- var q = '/live/open?u=' + encodeURIComponent(url) + (h && h.ua ? '&ua=' + encodeURIComponent(h.ua) : '') + (h && h.ref ? '&ref=' + encodeURIComponent(h.ref) : '') + (force ? '&force=1' : '') +
89
+ var q = '/live/open?u=' + encodeURIComponent(url) + (h && h.ua ? '&ua=' + encodeURIComponent(h.ua) : '') + (h && h.ref ? '&ref=' + encodeURIComponent(h.ref) : '') + (h && h.cookie ? '&cookie=' + encodeURIComponent(h.cookie) : '') + (force ? '&force=1' : '') +
75
90
  (force && opts && opts.fix === false ? '&fix=0' : '') + (force && cc ? '&cc=' + encodeURIComponent(cc) : '');
76
91
  return U.getJSON(PROXY + q + a.q, force ? 5000 : 30000, 65536, cancel || null, a.h);
77
92
  });
@@ -81,7 +96,7 @@ var YTPlay = (function () {
81
96
  function hlsMaster(url, h) {
82
97
  if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
83
98
  return ensureService().then(entryAuth).then(function (a) {
84
- var q = '/live/master?u=' + encodeURIComponent(url) + (h && h.ua ? '&ua=' + encodeURIComponent(h.ua) : '') + (h && h.ref ? '&ref=' + encodeURIComponent(h.ref) : '');
99
+ var q = '/live/master?u=' + encodeURIComponent(url) + (h && h.ua ? '&ua=' + encodeURIComponent(h.ua) : '') + (h && h.ref ? '&ref=' + encodeURIComponent(h.ref) : '') + (h && h.cookie ? '&cookie=' + encodeURIComponent(h.cookie) : '');
85
100
  return U.getText(PROXY + q + a.q, 12000, 524288, null, false, a.h);
86
101
  });
87
102
  }
@@ -170,6 +185,18 @@ var YTPlay = (function () {
170
185
  });
171
186
  });
172
187
  }
188
+ // A Widevine channel's license request (challenge: base64), posted by the service to its
189
+ // license server with the playlist's headers (see service/index.js, drmControl) -> { license:
190
+ // base64 } or { why }. b64: the server answers in base64 already.
191
+ function drmLicense(server, headers, challenge, b64) {
192
+ if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
193
+ return ensureService().then(entryAuth).then(function (a) {
194
+ return (a.q ? Promise.resolve(a.q) : ticketOf(a)).then(function (cred) {
195
+ var body = JSON.stringify({ u: server, h: headers || {}, c: challenge, b64: !!b64 });
196
+ return U.postJSON(PROXY + '/drm/license' + (cred ? '?' + cred.replace(/^&/, '') : ''), body, 20000, 2 * 1048576, a.h);
197
+ });
198
+ });
199
+ }
173
200
  // Settings › Storage: the saved guides ({ count, bytes }), and deleting them all.
174
201
  function epgFiles() {
175
202
  if (MODE === 'browser') { return Promise.resolve(null); }
@@ -272,6 +299,6 @@ var YTPlay = (function () {
272
299
  return MODE === 'tizenbrew' ? 'TizenBrew module' : MODE === 'wgt' ? 'Sideloaded app (.wgt)' : 'Browser (development)';
273
300
  }
274
301
 
275
- return { ensureService: ensureService, resolverUrl: resolverUrl, infoUrl: infoUrl, canPlay: canPlay, liveOpen: liveOpen, hlsMaster: hlsMaster, aiomAddons: aiomAddons, stalkerList: stalkerList, stalkerVod: stalkerVod, stalkerPlayUrl: stalkerPlayUrl, stalkerGenres: stalkerGenres, stalkerLink: stalkerLink, xtvodAsk: xtvodAsk, epgLoad: epgLoad, epgGet: epgGet, epgFiles: epgFiles, epgClear: epgClear, entryOpen: entryOpen, entryPoll: entryPoll, entryClose: entryClose, subsUrl: subsUrl, audioLang: audioLang, setAudioLang: setAudioLang, installMode: function () { return MODE; },
302
+ return { ensureService: ensureService, resolverUrl: resolverUrl, infoUrl: infoUrl, canPlay: canPlay, liveOpen: liveOpen, hlsMaster: hlsMaster, aiomAddons: aiomAddons, stalkerList: stalkerList, stalkerVod: stalkerVod, drmLicense: drmLicense, stalkerPlayUrl: stalkerPlayUrl, stalkerGenres: stalkerGenres, stalkerLink: stalkerLink, xtvodAsk: xtvodAsk, epgLoad: epgLoad, epgGet: epgGet, epgFiles: epgFiles, epgClear: epgClear, entryOpen: entryOpen, entryGive: entryGive, entrySeen: entrySeen, entryPoll: entryPoll, entryClose: entryClose, subsUrl: subsUrl, audioLang: audioLang, setAudioLang: setAudioLang, installMode: function () { return MODE; },
276
303
  installLabel: installLabel, unavailableMessage: unavailableMessage, isRunning: isRunning, port: PORT };
277
304
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stremiok",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",