stremiok 2.4.3 → 2.4.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/profiles.js CHANGED
@@ -78,7 +78,17 @@ var Profiles = (function () {
78
78
  if (m) { return m[1]; }
79
79
  return isTv(physical) ? null : '';
80
80
  }
81
- function list() { return _data ? _data.list.map(function (p) { return { id: p.id, name: p.name, color: p.color, slot: p.slot, at: p.at }; }) : []; }
81
+ function list() { return _data ? _data.list.map(function (p) { return { id: p.id, name: p.name, color: p.color, slot: p.slot, at: p.at, pic: picOf(p) }; }) : []; }
82
+ // A profile's picture (Settings › Profiles › Picture): a small JPEG as a data: link (made
83
+ // PIC_PX square by the app or the phone), PIC_MAX characters at most; '' none.
84
+ var PIC_MAX = 120000;
85
+ function picOf(p) { return p && typeof p.pic === 'string' && p.pic.length <= PIC_MAX && /^data:image\/jpeg;base64,[A-Za-z0-9+\/=]+$/.test(p.pic) ? p.pic : ''; }
86
+ function setPic(id, pic) {
87
+ var p = find(id);
88
+ if (!p) { return false; }
89
+ if (pic) { if (!picOf({ pic: pic })) { return false; } p.pic = pic; } else { delete p.pic; }
90
+ return save();
91
+ }
82
92
 
83
93
  // ---- changing the list (Settings › Profiles, the picker) ----
84
94
  function save() { try { window.localStorage.setItem(KEY, JSON.stringify(_data)); return true; } catch (e) { return false; } }
@@ -170,12 +180,12 @@ var Profiles = (function () {
170
180
  key: key, keyFor: keyFor, isTv: isTv, slotOf: slotOf,
171
181
  slot: function () { return _slot; },
172
182
  list: list,
173
- active: function () { var a = active(); return a ? { id: a.id, name: a.name, color: a.color, slot: a.slot } : null; },
183
+ active: function () { var a = active(); return a ? { id: a.id, name: a.name, color: a.color, slot: a.slot, pic: picOf(a) } : null; },
174
184
  count: function () { return _data ? _data.list.length : 1; },
175
185
  justSwitched: justSwitched,
176
186
  ask: function () { return !!(_data && _data.list.length > 1 && _data.ask !== false); },
177
187
  askSetting: function () { return !_data || _data.ask !== false; },
178
- ensure: function (firstName) { ensure(firstName); save(); }, add: add, rename: rename, recolor: recolor, setAsk: setAsk, startChoice: startChoice, setStart: setStart, setActive: setActive, remove: remove, copyInto: copyInto, keysOf: keysOf, COPY: COPY,
188
+ ensure: function (firstName) { ensure(firstName); save(); }, add: add, rename: rename, recolor: recolor, setPic: setPic, setAsk: setAsk, startChoice: startChoice, setStart: setStart, setActive: setActive, remove: remove, copyInto: copyInto, keysOf: keysOf, COPY: COPY,
179
189
  __data: function () { return _data; }, __reload: function () { _data = read(); _slot = (active() || { slot: '' }).slot; }
180
190
  };
181
191
  })();
package/js/view-core.js CHANGED
@@ -209,7 +209,12 @@ var ViewParts = {};
209
209
  // A profile's round badge: its color, the first character of its name.
210
210
  function profileBadge(p, cls) {
211
211
  var b = U.el('span', 'pf-badge' + (cls ? ' ' + cls : ''));
212
- b.style.background = PROFILE_COLORS[p.color] || PROFILE_COLORS.indigo;
212
+ b.style.backgroundColor = PROFILE_COLORS[p.color] || PROFILE_COLORS.indigo;
213
+ if (p.pic) { // (its picture: Settings › Profiles › Picture; filling the badge, its middle in view)
214
+ b.className += ' pf-pic';
215
+ b.style.backgroundImage = 'url("' + p.pic + '")'; b.style.backgroundSize = 'cover'; b.style.backgroundPosition = 'center center'; b.style.backgroundRepeat = 'no-repeat';
216
+ return b;
217
+ }
213
218
  var m = /^[\uD800-\uDBFF][\uDC00-\uDFFF]|^[\s\S]/.exec(('' + (p.name || '?')).trim() || '?');
214
219
  b.textContent = (m ? m[0] : '?').toUpperCase();
215
220
  return b;
@@ -489,6 +489,50 @@
489
489
  // this one (addons, settings, media server sign-ins; not its history or accounts) or empty.
490
490
  // Ask who's watching when StremioK opens (two or more).
491
491
  var PROFILE_COLOR_NAMES = { indigo: U.t('Indigo'), teal: U.t('Teal'), orange: U.t('Orange'), pink: U.t('Pink'), green: U.t('Green'), red: U.t('Red'), purple: U.t('Purple'), amber: U.t('Amber') };
492
+ // A profile's picture: from the phone (a photo it made small, or an image's link) or typed (a
493
+ // link); a link downloaded by the service (YTPlay.imageBytes). Made PROFILE_PIC_PX square here
494
+ // (centred, cut to fit) and kept as a small JPEG (Profiles.setPic), never the link.
495
+ var PROFILE_PIC_PX = 240;
496
+ function picSource(bytes) {
497
+ try { return URL.createObjectURL(new Blob([bytes])); } catch (e) {}
498
+ var s = ''; for (var i = 0; i < bytes.length; i++) { s += String.fromCharCode(bytes[i]); }
499
+ return 'data:image/jpeg;base64,' + btoa(s);
500
+ }
501
+ function shrinkPicture(src) {
502
+ return new Promise(function (resolve, reject) {
503
+ var img = new Image();
504
+ img.onload = function () {
505
+ try {
506
+ var w = img.naturalWidth, h = img.naturalHeight, side = Math.min(w, h), c = document.createElement('canvas');
507
+ if (!side) { reject(new Error('empty')); return; }
508
+ c.width = c.height = PROFILE_PIC_PX;
509
+ c.getContext('2d').drawImage(img, (w - side) / 2, (h - side) / 2, side, side, 0, 0, PROFILE_PIC_PX, PROFILE_PIC_PX);
510
+ var out = c.toDataURL('image/jpeg', 0.85);
511
+ if (out.length > 110000) { out = c.toDataURL('image/jpeg', 0.6); }
512
+ resolve(out);
513
+ } catch (e) { reject(e); }
514
+ if (/^blob:/.test(src)) { try { URL.revokeObjectURL(src); } catch (e2) {} }
515
+ };
516
+ img.onerror = function () { reject(new Error('not an image')); };
517
+ img.src = src;
518
+ });
519
+ }
520
+ function profilePicture(p) {
521
+ V.phoneEntry({ title: U.t('A picture for “{name}”', { name: p.name }), what: 'picture', typeTitle: U.t('An image’s link'), placeholder: 'https://…/picture.jpg',
522
+ hint: U.t('From your phone: one of its photos, or an image’s link. Typed here: an image’s link.'),
523
+ validate: function (v) { v = ('' + v).trim(); return /^data:image\/jpeg;base64,/.test(v) || /^https?:\/\/\S+$/i.test(v) ? null : U.t('Not a picture, nor an image’s link'); },
524
+ onText: function (v) {
525
+ v = ('' + v).trim();
526
+ U.toast(U.t('Getting the picture…'), 20000);
527
+ var got = /^data:/.test(v) ? Promise.resolve(v) : YTPlay.imageBytes(v).then(picSource);
528
+ got.then(shrinkPicture).then(function (pic) {
529
+ profileEnsure();
530
+ if (!Profiles.setPic(p.id || Profiles.active().id, pic)) { throw new Error('not kept'); }
531
+ U.toast(U.t('Picture set'));
532
+ renderSettings();
533
+ }).then(null, function (e) { U.log('profiles', 'A profile picture couldn\'t be used: ' + ((e && e.message) || 'unknown')); U.toast(U.t('Couldn’t use that picture'), 4000); });
534
+ } });
535
+ }
492
536
  var PROFILE_STORAGE_MAX = 4194304; // (bytes of the settings storage used: no new profile past this, the 2017 TV keeps about 5 MB)
493
537
  function storageUsed() {
494
538
  var n = 0;
@@ -508,7 +552,8 @@
508
552
  r.__onselect = function () {
509
553
  var opts = [];
510
554
  if (!mine) { opts.push(['switch', U.t('Switch to it')]); }
511
- opts.push(['rename', U.t('Rename')], ['color', U.t('Color')]);
555
+ opts.push(['rename', U.t('Rename')], ['color', U.t('Color')], ['picture', U.t('Picture')]);
556
+ if (p.pic) { opts.push(['nopic', U.t('Remove picture')]); }
512
557
  if (!mine && list.length > 1) { opts.push(['delete', U.t('Delete')]); }
513
558
  pickList(p.name, opts, null, function (v) {
514
559
  _focusChild = 'pf:' + p.id;
@@ -516,7 +561,9 @@
516
561
  else if (v === 'rename') { profileName(U.t('Rename “{name}”', { name: p.name }), p.name, function (name) { profileEnsure(); Profiles.rename(p.id || Profiles.active().id, name); renderSettings(); }); }
517
562
  else if (v === 'color') {
518
563
  pickList(U.t('Color'), Profiles.COLORS.map(function (c) { return [c, PROFILE_COLOR_NAMES[c] || c, null, V.PROFILE_COLORS[c]]; }), p.color, function (c) { profileEnsure(); Profiles.recolor(p.id || Profiles.active().id, c); renderSettings(); });
519
- } else if (v === 'delete') {
564
+ } else if (v === 'picture') { profilePicture(p); }
565
+ else if (v === 'nopic') { Profiles.setPic(p.id, ''); U.toast(U.t('Picture removed')); renderSettings(); }
566
+ else if (v === 'delete') {
520
567
  confirm(U.t('Delete “{name}”? Its addons, settings, progress, watched marks and sign-ins go with it; the rest of the TV’s doesn’t.', { name: p.name }), U.t('Delete'), function () {
521
568
  Profiles.remove(p.id, U.bigStore && U.bigStore.removeExact);
522
569
  U.toast(U.t('“{name}” deleted', { name: p.name }));
package/js/ytplay.js CHANGED
@@ -81,6 +81,11 @@ var YTPlay = (function () {
81
81
  return U.getJSON(PROXY + '/bak/read?drive=' + encodeURIComponent(drive) + a.q, 15000, 3 * 1048576, null, a.h);
82
82
  });
83
83
  }
84
+ // An image's link, downloaded by the service (a profile picture): its bytes (Uint8Array).
85
+ function imageBytes(url) {
86
+ if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
87
+ return ensureService().then(entryAuth).then(function (a) { return U.getText(PROXY + '/img?u=' + encodeURIComponent(url) + a.q, 25000, 8388608, null, true, a.h, null, true); });
88
+ }
84
89
  function entryOpen(what) {
85
90
  return entryAuth().then(function (a) { return U.getJSON(PROXY + '/entry/open?what=' + encodeURIComponent(what || 'link') + a.q, 8000, undefined, null, a.h); });
86
91
  }
@@ -364,6 +369,6 @@ var YTPlay = (function () {
364
369
  return MODE === 'tizenbrew' ? U.t('TizenBrew module') : MODE === 'wgt' ? U.t('Sideloaded app (.wgt)') : U.t('Browser (development)');
365
370
  }
366
371
 
367
- return { ensureService: ensureService, resolverUrl: resolverUrl, infoUrl: infoUrl, canPlay: canPlay, liveOpen: liveOpen, fileOpen: fileOpen, mediaInfo: mediaInfo, pluginNet: pluginNet, 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, bakWrite: bakWrite, bakRead: bakRead, entrySeen: entrySeen, entryPoll: entryPoll, entryClose: entryClose, subsUrl: subsUrl, audioLang: audioLang, setAudioLang: setAudioLang, installMode: function () { return MODE; },
372
+ return { ensureService: ensureService, resolverUrl: resolverUrl, infoUrl: infoUrl, canPlay: canPlay, liveOpen: liveOpen, fileOpen: fileOpen, mediaInfo: mediaInfo, pluginNet: pluginNet, 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, imageBytes: imageBytes, entryGive: entryGive, bakWrite: bakWrite, bakRead: bakRead, entrySeen: entrySeen, entryPoll: entryPoll, entryClose: entryClose, subsUrl: subsUrl, audioLang: audioLang, setAudioLang: setAudioLang, installMode: function () { return MODE; },
368
373
  installLabel: installLabel, unavailableMessage: unavailableMessage, isRunning: isRunning, port: PORT };
369
374
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stremiok",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",
package/service/index.js CHANGED
@@ -2386,6 +2386,7 @@ function handle(req, res) {
2386
2386
  if (/^\/smb\//.test(path)) { smbControl(req, res, path, parts[1], leaving); return; } // (a Windows / NAS share: see smbControl)
2387
2387
  if (/^\/dlna\//.test(path)) { dlnaControl(req, res, path, parts[1], leaving); return; } // (a DLNA media server: see dlnaControl) // (a network folder's file, for the player: its ticket) // (a network folder: see davControl)
2388
2388
  if (path === '/aiom/addons') { aiomControl(req, res, parts[1], leaving); return; }
2389
+ if (path === '/img') { imgControl(req, res, parts[1], leaving); return; } // (an image's link, for a profile picture: see imgControl)
2389
2390
  if (path === '/xtvod/list' || path === '/xtvod/find') { xtvControl(req, res, path, parts[1]); return; } // (an Xtream account's films and series: see xtvControl)
2390
2391
  if (path === '/stalker/list' || path === '/stalker/link' || path === '/stalker/genres' || path === '/stalker/vod' || path === '/stalker/play') { stalkerControl(req, res, path, parts[1], leaving); return; } // (a Stalker portal: see stalkerControl) // (AIOManager's addons: see aiomControl) // (a live channel's sound repacked: see liveControl) // (the phone's one-time page: see below)
2391
2392
  if (path === '/fsfile') { // a USB file over HTTP, with Range: the player reads a big one from here (see fsfile in the header)
@@ -6331,6 +6332,7 @@ function epgControl(req, res, path, query) {
6331
6332
  // minute. The port is open only while one is: ENTRY_CONNECTIONS at a time, each given
6332
6333
  // ENTRY_VISIT_MS (ENTRY_QUIET_MS of silence). It's plain HTTP: the page says so.
6333
6334
  var ENTRY_PORT = PORT + 10, ENTRY_MS = 5 * 60 * 1000, ENTRY_IDLE_MS = 30000, ENTRY_MAX = 8192;
6335
+ var PICTURE_PX = 240, PICTURE_MAX = 262144; // (a profile picture from the phone: made that small there, sent as a JPEG data: link)
6334
6336
  // A configuration file: pasted on the import's page (CONFIG_MAX, sent %-encoded: 3 times that), or
6335
6337
  // given by the TV to the export's page (GIVE_MAX, POSTed to /entry/give), shown to copy or download.
6336
6338
  var CONFIG_MAX = 1572864, GIVE_MAX = 1572864; // (1.5 MB: a file with your history too; the page reads it as JSON, 2 MB at most)
@@ -6338,7 +6340,7 @@ var ENTRY_OPEN_MAX = 2, ENTRY_OPENS = 12, ENTRY_CONNECTIONS = 8, ENTRY_VISIT_MS
6338
6340
  var ENTRY_TITLES = { link: 'Play a link on StremioK', addon: 'Add an addon to StremioK', playlist: 'Add an IPTV playlist to StremioK', config: 'Import a configuration file into StremioK', give: 'Your StremioK configuration', givelog: 'Your StremioK logs',
6339
6341
  search: 'Search on StremioK', youtube: 'Add a YouTube catalog to StremioK', aiom: 'Your AIOManager address for StremioK', aiomkey: 'Your AIOManager API key for StremioK',
6340
6342
  server: 'Your streaming server’s address for StremioK', mac: 'Your Stalker portal’s MAC address for StremioK', webdav: 'Your network folder’s address for StremioK',
6341
- jellyfin: 'Your media server’s address for StremioK', plugins: 'Add a Nuvio plugin repository to StremioK' };
6343
+ jellyfin: 'Your media server’s address for StremioK', plugins: 'Add a Nuvio plugin repository to StremioK', picture: 'A profile picture for StremioK' };
6342
6344
  var ENTRY_TEXT = { search: 'Words to search for', youtube: 'A channel, a playlist link, or words to search YouTube for', aiomkey: 'Your account API key', mac: 'Its MAC address (00:1A:79:…)' }; // (plain text, not a link)
6343
6345
  var _entries = Object.create(null), _entryServer = null, _entrySockets = [], _entryOpened = [];
6344
6346
  function lanAddress() {
@@ -6357,6 +6359,34 @@ function lanAddress() {
6357
6359
  // folder, or, where it can't read it (TizenBrew has nowhere private to keep one; on Tizen 6
6358
6360
  // the service's folder isn't the app's), an X-StremioK header: a web page can't send one
6359
6361
  // without a pre-check naming where it comes from, and that's refused.
6362
+ // ---- An image's link, for a profile picture (/img?u=) ----
6363
+ // StremioK only (its token or header). The image downloaded (the downloads' host rule, redirects
6364
+ // followed: liveGet), IMG_MAX at most, and passed on only if it is one (JPEG, PNG, GIF, WebP,
6365
+ // BMP: by its first bytes); the app makes it small and keeps that, never the link.
6366
+ var IMG_MAX = 8 * 1048576;
6367
+ function imgType(b) {
6368
+ if (!b || b.length < 12) { return ''; }
6369
+ if (b[0] === 0xFF && b[1] === 0xD8) { return 'image/jpeg'; }
6370
+ if (b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4E && b[3] === 0x47) { return 'image/png'; }
6371
+ if (b[0] === 0x47 && b[1] === 0x49 && b[2] === 0x46) { return 'image/gif'; }
6372
+ if (b.toString('binary', 0, 4) === 'RIFF' && b.toString('binary', 8, 12) === 'WEBP') { return 'image/webp'; }
6373
+ if (b[0] === 0x42 && b[1] === 0x4D) { return 'image/bmp'; }
6374
+ return '';
6375
+ }
6376
+ function imgControl(req, res, query, leaving) {
6377
+ if (!entryAllowed(req, query)) { send(res, 403, 'text/plain', 'not allowed (token)'); return; }
6378
+ var m = /(?:^|&)u=([^&]*)/.exec(query || ''), u = '';
6379
+ try { u = m ? decodeURIComponent(m[1]) : ''; } catch (e) { u = ''; }
6380
+ if (!/^https?:\/\/[^\s]+$/i.test(u) || u.length > 2000) { send(res, 400, 'text/plain', 'bad link'); return; }
6381
+ var stop = liveGet(u, { ua: '' }, IMG_MAX, function (err, body) {
6382
+ if (err) { send(res, err.status || 502, 'text/plain', 'failed: ' + err.message); return; }
6383
+ var type = imgType(body);
6384
+ if (!type) { send(res, 415, 'text/plain', 'not an image'); return; }
6385
+ res.writeHead(200, { 'Content-Type': type, 'Content-Length': body.length, 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff' });
6386
+ res.end(body);
6387
+ });
6388
+ if (leaving && stop) { leaving.push(stop); }
6389
+ }
6360
6390
  function entryAllowed(req, query) {
6361
6391
  return hasToken(query) || !!(req.headers && req.headers['x-stremiok']);
6362
6392
  }
@@ -6450,7 +6480,19 @@ function entryPage(req, res) {
6450
6480
  return;
6451
6481
  }
6452
6482
  if (m[2]) { send(res, 404, 'text/plain', 'Not here'); return; }
6453
- var config = e.what === 'config', max = config ? CONFIG_MAX * 3 : ENTRY_MAX; // (a pasted file: its lines kept, %-encoded as sent)
6483
+ var config = e.what === 'config', max = config ? CONFIG_MAX * 3 : e.what === 'picture' ? PICTURE_MAX : ENTRY_MAX; // (a pasted file: its lines kept, %-encoded as sent)
6484
+ if (req.method === 'GET' && e.what === 'picture') { // (a photo from the phone, made small here, on the phone: or an image's link)
6485
+ send(res, 200, 'text/html; charset=utf-8', entryHtml(title, '<form method="post" id="fm"><p>A photo from this phone</p><input id="pick" type="file" accept="image/*">' +
6486
+ '<img id="pv" alt="" style="display:none;width:120px;height:120px;border-radius:50%;margin:8px 0;object-fit:cover">' +
6487
+ '<p>Or an image\'s link</p><input id="ln" type="url" autocomplete="off" placeholder="https://…/picture.jpg">' +
6488
+ '<input type="hidden" name="text" id="t"><button type="submit">Send to the TV</button></form>' +
6489
+ '<p>A photo is cut to a square and made small (' + PICTURE_PX + ' × ' + PICTURE_PX + ') on this phone before it goes. It goes straight to your TV over your home network, <b>unencrypted</b>. This page stops working once it has been sent.</p>' +
6490
+ '<script>var t=document.getElementById("t");document.getElementById("pick").onchange=function(){var f=this.files&&this.files[0];if(!f){return;}var r=new FileReader();' +
6491
+ 'r.onload=function(){var i=new Image();i.onload=function(){var s=Math.min(i.naturalWidth,i.naturalHeight),c=document.createElement("canvas");c.width=c.height=' + PICTURE_PX + ';' +
6492
+ 'c.getContext("2d").drawImage(i,(i.naturalWidth-s)/2,(i.naturalHeight-s)/2,s,s,0,0,' + PICTURE_PX + ',' + PICTURE_PX + ');t.value=c.toDataURL("image/jpeg",0.85);var p=document.getElementById("pv");p.src=t.value;p.style.display="block";};i.src=r.result;};r.readAsDataURL(f);};' +
6493
+ 'document.getElementById("fm").onsubmit=function(){if(!t.value){t.value=document.getElementById("ln").value.trim();}if(!t.value){return false;}};</script>'));
6494
+ return;
6495
+ }
6454
6496
  if (req.method === 'GET' && config) { // (its link, as before; or the file itself, chosen from the phone's files or pasted)
6455
6497
  send(res, 200, 'text/html; charset=utf-8', entryHtml(title, '<form method="post"><p>A link to the file</p><input name="link" type="url" autocomplete="off" placeholder="https://…">' +
6456
6498
  '<p>Or the file itself (an export\'s stremiok.txt)</p><input id="pick" type="file" accept=".txt,.cfg,.conf,text/plain">' +
package/tizenbrew.html CHANGED
@@ -10,7 +10,7 @@
10
10
  // from there: it opens this version's own copy (npm/stremiok@<version>/index.html), whose
11
11
  // files all come from that address. build.sh stamps the ?v= below.
12
12
  (function () {
13
- var v = '?v=2.4.3'.slice(3), l = location, rest = (l.search || '') + (l.hash || '');
13
+ var v = '?v=2.4.4'.slice(3), l = location, rest = (l.search || '') + (l.hash || '');
14
14
  var m = /^(\/module\/npm%2F[^\/%@]+)\//i.exec(l.pathname || '');
15
15
  l.replace(m ? m[1] + '%40' + v + '/index.html' + rest : 'index.html' + rest);
16
16
  })();