stremiok 2.3.7 → 2.4.0

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.
@@ -478,11 +478,299 @@
478
478
  else if (_settingsSection === 'appearance') { settingsAppearance(wrap); }
479
479
  else if (_settingsSection === 'home') { settingsHome(wrap); }
480
480
  else if (_settingsSection === 'formats') { settingsFormats(wrap); }
481
+ else if (_settingsSection === 'profiles') { settingsProfiles(wrap); }
481
482
  else { settingsMenu(wrap); }
482
483
  var ver = appVersion();
483
484
  if (ver) { s.appendChild(U.el('div', 'settings-version', 'StremioK ' + ver)); }
484
485
  }
485
486
 
487
+ // ----- Settings › Profiles (js/profiles.js) -----
488
+ // Each profile: Switch to it, Rename, Color, Delete. + Add a profile: its name, then a copy of
489
+ // this one (addons, settings, media server sign-ins; not its history or accounts) or empty.
490
+ // Ask who's watching when StremioK opens (two or more).
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
+ var PROFILE_STORAGE_MAX = 4194304; // (bytes of the settings storage used: no new profile past this, the 2017 TV keeps about 5 MB)
493
+ function storageUsed() {
494
+ var n = 0;
495
+ try { for (var i = 0; i < window.localStorage.length; i++) { var k = window.localStorage.key(i); n += (k.length + (window.localStorage.getItem(k) || '').length) * 2; } } catch (e) {}
496
+ return n;
497
+ }
498
+ function settingsProfiles(wrap) {
499
+ wrap.appendChild(U.el('h2', null, U.t('Profiles')));
500
+ var list = Profiles.list(), now = Profiles.active(), focus = null;
501
+ if (!list.length) { list = [{ id: '', name: U.t('Profile {n}', { n: 1 }), color: 'indigo', slot: '' }]; now = list[0]; }
502
+ list.forEach(function (p) {
503
+ var mine = now && p.id === now.id, r = U.el('div', 'addon-item focusable cfg-row pf-setting');
504
+ var nm = U.el('div', 'a-name');
505
+ nm.appendChild(V.profileBadge(p, 'small'));
506
+ nm.appendChild(document.createTextNode(' ' + p.name + (mine ? ' · ' + U.t('in use') : '')));
507
+ r.appendChild(nm);
508
+ r.__onselect = function () {
509
+ var opts = [];
510
+ if (!mine) { opts.push(['switch', U.t('Switch to it')]); }
511
+ opts.push(['rename', U.t('Rename')], ['color', U.t('Color')]);
512
+ if (!mine && list.length > 1) { opts.push(['delete', U.t('Delete')]); }
513
+ pickList(p.name, opts, null, function (v) {
514
+ _focusChild = 'pf:' + p.id;
515
+ if (v === 'switch') { V.switchProfile(p.id); }
516
+ 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
+ else if (v === 'color') {
518
+ 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') {
520
+ 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
+ Profiles.remove(p.id, U.bigStore && U.bigStore.removeExact);
522
+ U.toast(U.t('“{name}” deleted', { name: p.name }));
523
+ renderSettings();
524
+ });
525
+ }
526
+ });
527
+ };
528
+ if (_focusChild === 'pf:' + p.id) { focus = r; }
529
+ wrap.appendChild(r);
530
+ });
531
+ if (list.length < Profiles.MAX) {
532
+ var add = U.el('div', 'addon-item focusable cfg-row');
533
+ add.appendChild(U.el('div', 'a-name', U.t('+ Add a profile')));
534
+ add.appendChild(U.el('div', 'a-url', U.t('Its name, then a copy of this profile’s addons and settings, or none')));
535
+ add.__onselect = function () {
536
+ if (storageUsed() > PROFILE_STORAGE_MAX) { U.toast(U.t('The TV’s storage is nearly full: no room for another profile (Settings › Diagnostics › Storage).'), 6000); return; }
537
+ profileName(U.t('New profile'), '', function (name) {
538
+ var starts = [['copy', U.t('A copy of this profile’s addons and settings')], ['empty', U.t('Nothing: its own from the start')]];
539
+ if (typeof StremioAccount !== 'undefined' && typeof StremioSync !== 'undefined') { starts.push(['stremio', U.t('A Stremio account: its addons, Continue Watching and watched marks')]); }
540
+ if (typeof NuvioImport !== 'undefined' && typeof NuvioSync !== 'undefined') { starts.push(['nuvio', U.t('A Nuvio account’s profile: kept in step with it')]); }
541
+ pickList(U.t('“{name}” starts with', { name: name }), starts, 'copy', function (how) {
542
+ if (how === 'stremio') { profileFromStremio(name); return; }
543
+ if (how === 'nuvio') { nuvioConnect(name); return; }
544
+ var p = Profiles.add(name, null, U.t('Profile {n}', { n: 1 }));
545
+ if (!p) { U.toast(U.t('Up to {n} profiles', { n: Profiles.MAX }), 4000); return; }
546
+ if (how === 'copy') { Profiles.copyInto(p.slot, Profiles.slot()); }
547
+ markHomeDirty();
548
+ _focusChild = 'pf:' + p.id;
549
+ renderSettings();
550
+ confirm(U.t('“{name}” added. Switch to it now?', { name: p.name }), U.t('Switch to it'), function () { V.switchProfile(p.id); }, { plain: true, noLabel: U.t('Not now'), focusYes: true });
551
+ });
552
+ });
553
+ };
554
+ wrap.appendChild(add);
555
+ } else {
556
+ wrap.appendChild(U.el('div', 'hint', U.t('Up to {n} profiles', { n: Profiles.MAX })));
557
+ }
558
+ if (list.length < Profiles.MAX && typeof NuvioImport !== 'undefined') {
559
+ var nv = U.el('div', 'addon-item focusable cfg-row');
560
+ nv.appendChild(U.el('div', 'a-name', U.t('⇩ Import profiles from Nuvio')));
561
+ nv.appendChild(U.el('div', 'a-url', U.t('Sign in on your phone, pick its profiles: each with its addons, watched marks and recent progress. Once; Nuvio’s account isn’t changed')));
562
+ nv.__onselect = nuvioImport;
563
+ wrap.appendChild(nv);
564
+ }
565
+ if (Profiles.count() > 1) {
566
+ var askOn = Profiles.askSetting(), ask = U.el('div', 'addon-item focusable cfg-row');
567
+ ask.appendChild(U.el('div', 'a-name', U.t('Ask who’s watching when StremioK opens:') + ' ' + (askOn ? U.t('On') : U.t('Off'))));
568
+ ask.appendChild(U.el('div', 'a-url', askOn ? U.t('Each time it opens, before anything else') : U.t('It opens in the last profile used; switch from the top menu')));
569
+ ask.__onselect = function () { Profiles.setAsk(!askOn); _focusChild = 'pf:ask'; renderSettings(); };
570
+ if (_focusChild === 'pf:ask') { focus = ask; }
571
+ wrap.appendChild(ask);
572
+ }
573
+ wrap.appendChild(U.el('div', 'hint', U.t('Each profile keeps its own addons and their order, settings, progress, watched marks, Continue Watching, Trakt, Stremio account and media server sign-ins. Playlists, USB drives, network folders, plugins, API keys and the streaming server are the TV’s, for every profile.')));
574
+ if (focus) { _focusChild = null; Focus.setScope(scr('settings'), focus); } else { focusSettings(); }
575
+ }
576
+ // A new profile from a Stremio account (one account, one profile: a Stremio account has no
577
+ // profiles of its own): signed in on your phone, its addons read; the profile made with them
578
+ // and the account kept connected for it (its sign-in under the profile's own keys), so when
579
+ // it's in use its Continue Watching, watched marks and Library sync in (js/stremio-sync.js).
580
+ function profileFromStremio(name) {
581
+ stremioSignIn(U.t('New profile from a Stremio account'), function (key, body, gone, fail) {
582
+ U.clear(body);
583
+ body.appendChild(U.el('div', 'tc-line', U.t('Reading your addons…')));
584
+ var user = StremioAccount.call('getUser', { type: 'GetUser', authKey: key }).then(function (u) { return u && typeof u.email === 'string' ? U.drawable(u.email).slice(0, 120) : ''; }, function () { return ''; });
585
+ return Promise.all([StremioAccount.addons(key), user]).then(function (r) {
586
+ if (gone()) { StremioAccount.signOut(key); return; }
587
+ var p = Profiles.add(name, null, U.t('Profile {n}', { n: 1 }));
588
+ if (!p) { StremioAccount.signOut(key); fail(new Error(U.t('Up to {n} profiles', { n: Profiles.MAX }))); return; }
589
+ var urls = [], origin = {};
590
+ r[0].forEach(function (a) { var u = (Stremio.normalizeAddonUrl && Stremio.normalizeAddonUrl(a.url)) || a.url; if (urls.indexOf(u) === -1) { urls.push(u); origin[u] = 'stremio'; } });
591
+ function put(k, v) { try { window.localStorage.setItem(Profiles.keyFor(p.slot, 'stremiok.' + k), JSON.stringify(v)); } catch (e) {} }
592
+ if (urls.length) { put('addons', urls); put('addonorigin', origin); }
593
+ put('stremio', { key: key, user: r[1], at: Date.now() });
594
+ closeModal();
595
+ markHomeDirty();
596
+ _focusChild = 'pf:' + p.id;
597
+ renderSettings();
598
+ confirm(U.t('“{name}” added, with {n} addons from {user}. Switch to it now?', { name: p.name, n: urls.length, user: r[1] || 'Stremio' }), U.t('Switch to it'), function () { V.switchProfile(p.id); }, { plain: true, noLabel: U.t('Not now'), focusYes: true });
599
+ });
600
+ });
601
+ }
602
+ // Profiles from a Nuvio account (js/nuvio-import.js): Nuvio's TV sign-in (a code and a QR code
603
+ // of its page, approved on your phone), its profiles read and the session signed out at once;
604
+ // the ones you tick (as many as there's room for) made StremioK profiles, with their addons,
605
+ // watched marks and recent progress (its titles' names and posters from this profile's addons).
606
+ // Nuvio's sign-in box (js/nuvio-import.js): a code and a QR code of Nuvio's page, approved on
607
+ // your phone; then signedIn(cfg, session, body, gone, fail) (gone(): the box closed meanwhile).
608
+ function nuvioSignIn(title, note, signedIn) {
609
+ var existing = document.querySelector('.modal-overlay');
610
+ if (existing) { existing.parentNode.removeChild(existing); }
611
+ var overlay = U.el('div', 'modal-overlay'), box = U.el('div', 'modal-box'), body = U.el('div', 'trakt-connect');
612
+ box.appendChild(U.el('div', 'modal-msg', title));
613
+ body.appendChild(U.el('div', 'tc-line', U.t('Asking Nuvio for a code…')));
614
+ box.appendChild(body);
615
+ var row = U.el('div', 'modal-row'), cancel = U.el('div', 'pill focusable modal-btn', U.t('Cancel'));
616
+ cancel.__onselect = function () { closeModal(); };
617
+ row.appendChild(cancel); box.appendChild(row); overlay.appendChild(box); document.body.appendChild(overlay);
618
+ showModal(overlay, cancel);
619
+ var gone = false, cfg = null;
620
+ onModalClose(function () { gone = true; });
621
+ function stopped() { return gone; }
622
+ function fail(e) { if (gone) { return; } U.clear(body); body.appendChild(U.el('div', 'tc-line', U.t('It failed: {why}', { why: (e && e.message) || U.t('unknown') }))); }
623
+ NuvioImport.discover().then(function (c) { cfg = c; return NuvioImport.start(c); }).then(function (sess) {
624
+ if (gone) { return; }
625
+ U.clear(body);
626
+ var qrSpot = body.appendChild(U.el('div', 'tc-qr-spot'));
627
+ var goTo = body.appendChild(U.el('div', 'tc-line', U.t('On your phone or computer, go to:')));
628
+ (typeof qrcode !== 'undefined' ? Promise.resolve() : U.loadScript('js/qrcode.js')).then(function () {
629
+ var qr = U.qrCanvas(sess.link, 6);
630
+ if (!qr || !qrSpot.parentNode) { return; }
631
+ qr.className = 'tc-qr';
632
+ qrSpot.appendChild(U.el('div', 'tc-line', U.t('Scan with your phone:')));
633
+ qrSpot.appendChild(qr);
634
+ goTo.textContent = U.t('or go to');
635
+ }, function () {});
636
+ body.appendChild(U.el('div', 'tc-url', sess.link));
637
+ body.appendChild(U.el('div', 'tc-line', U.t('Code:')));
638
+ body.appendChild(U.el('div', 'tc-code', sess.code));
639
+ body.appendChild(U.el('div', 'tc-line small', note));
640
+ return NuvioImport.wait(cfg, sess, stopped).then(function (tok) {
641
+ if (gone) { NuvioImport.signOut(cfg, tok.access); return; }
642
+ U.clear(body);
643
+ body.appendChild(U.el('div', 'tc-line', U.t('Reading your profiles…')));
644
+ return signedIn(cfg, tok, body, stopped, fail);
645
+ });
646
+ }).then(null, function (e) { if (!e || e.message !== 'stopped') { fail(e); } });
647
+ }
648
+ function nuvioImport() {
649
+ nuvioSignIn(U.t('Import profiles from Nuvio'), U.t('Sign in to Nuvio there and approve (Nuvio calls it signing in a TV). StremioK reads your profiles once, then signs out. Waiting…'), function (cfg, tok, body, gone) {
650
+ return NuvioImport.readAll(cfg, tok.access).then(function (list) {
651
+ if (gone()) { return; }
652
+ closeModal();
653
+ nuvioPick(list);
654
+ });
655
+ });
656
+ }
657
+ // Kept in sync (js/nuvio-sync.js): the Nuvio profile this one follows, picked; then for a new
658
+ // profile (name) made from it, or for the one in use (no name).
659
+ function nuvioConnect(name) {
660
+ nuvioSignIn(name ? U.t('New profile from a Nuvio account') : U.t('Nuvio account'), U.t('Sign in to Nuvio there and approve (Nuvio calls it signing in a TV). The profile you pick then stays in step with this one. Waiting…'), function (cfg, tok, body, gone, fail) {
661
+ return NuvioImport.readAll(cfg, tok.access, true).then(null, function (e) { NuvioImport.signOut(cfg, tok.access); throw e; }).then(function (list) {
662
+ if (gone()) { NuvioImport.signOut(cfg, tok.access); return; }
663
+ if (!list.length) { NuvioImport.signOut(cfg, tok.access); fail(new Error(U.t('That Nuvio account has no profiles'))); return; }
664
+ closeModal();
665
+ function chosen(n) {
666
+ if (!name) {
667
+ NuvioSync.connect(cfg, tok, n).then(function () { markHomeDirty(); renderSettings(); });
668
+ U.toast(U.t('Connected to Nuvio’s “{name}”: syncing…', { name: n.name }), 4000);
669
+ renderSettings();
670
+ offerPlugins(n.plugins, null);
671
+ return;
672
+ }
673
+ U.spinner(true, U.t('Importing…'));
674
+ nuvioMake(n, name).then(function (p) {
675
+ U.spinner(false);
676
+ if (!p) { NuvioImport.signOut(cfg, tok.access); U.toast(U.t('Up to {n} profiles', { n: Profiles.MAX }), 4000); return; }
677
+ NuvioSync.connectFor(p.slot, cfg, tok, n);
678
+ markHomeDirty();
679
+ _focusChild = 'pf:' + p.id;
680
+ renderSettings();
681
+ offerPlugins(n.plugins, function () {
682
+ confirm(U.t('“{name}” added, kept in step with Nuvio’s “{nuvio}”. Switch to it now?', { name: p.name, nuvio: n.name }), U.t('Switch to it'), function () { V.switchProfile(p.id); }, { plain: true, noLabel: U.t('Not now'), focusYes: true });
683
+ });
684
+ });
685
+ }
686
+ if (list.length === 1) { chosen(list[0]); return; }
687
+ var picked = false;
688
+ pickList(U.t('Which Nuvio profile?'), list.map(function (n, i) { return ['' + i, n.name + (n.locked ? ' · ' + U.t('PIN-locked in Nuvio') : '')]; }), null, function (i) { picked = true; chosen(list[+i]); });
689
+ onModalClose(function () { setTimeout(function () { if (!picked) { NuvioImport.signOut(cfg, tok.access); } }, 0); }); // (none picked: signed out)
690
+ });
691
+ });
692
+ }
693
+ // Nuvio's plugin repositories (a profile's), offered to add to Nuvio plugins (the TV's, every
694
+ // profile's: Settings › Content › Nuvio plugins), those already there left out; then().
695
+ function offerPlugins(repos, then) {
696
+ var have = typeof Plugins !== 'undefined' && Plugins.repos ? Plugins.repos().map(function (r) { return r.url; }) : null;
697
+ var fresh = have && Plugins.supported && Plugins.supported() ? (repos || []).filter(function (r) { var u = Plugins.manifestUrl ? Plugins.manifestUrl(r.url) : r.url; return u && have.indexOf(u) === -1; }) : [];
698
+ if (!fresh.length) { if (then) { then(); } return; }
699
+ var adding = false;
700
+ pickMany(U.t('Its Nuvio plugins: add them too? (for every profile on this TV)'), fresh.map(function (r, i) { return { key: '' + i, label: (r.name || U.t('Repository')) + ' · ' + shortHost(r.url) }; }),
701
+ { on: fresh.map(function (r, i) { return '' + i; }), button: function (n) { return U.tn(n, 'Add {n} repository', 'Add {n} repositories'); } }, function (keys) {
702
+ adding = true;
703
+ U.spinner(true, U.t('Adding…'));
704
+ keys.reduce(function (chain, k) { return chain.then(function () { return Plugins.addRepo(fresh[+k].url).then(null, function () {}); }); }, Promise.resolve()).then(function () {
705
+ U.spinner(false);
706
+ U.toast(U.t('Added to Settings › Content › Nuvio plugins (turn them on there)'), 5000);
707
+ if (then) { then(); }
708
+ });
709
+ });
710
+ // (closed without adding: then() all the same; Add closes it first, so its turn is let pass)
711
+ if (then) { onModalClose(function () { setTimeout(function () { if (!adding) { then(); } }, 0); }); }
712
+ }
713
+ function nuvioPick(list) {
714
+ if (!list.length) { U.toast(U.t('That Nuvio account has no profiles'), 5000); return; }
715
+ var room = Profiles.MAX - Math.max(1, Profiles.count());
716
+ var items = list.map(function (p, i) {
717
+ return { key: '' + i, label: p.name + ' · ' + U.tn(p.addons.length, '{n} addon', '{n} addons') + ', ' + U.tn(Object.keys(p.watched).length, '{n} watched', '{n} watched'),
718
+ note: p.locked ? U.t('PIN-locked in Nuvio') : '' };
719
+ });
720
+ pickMany(U.tn(room, 'Nuvio’s profiles: tick up to {n}', 'Nuvio’s profiles: tick up to {n}'), items, { button: function (n) { return U.tn(n, 'Import {n} profile', 'Import {n} profiles'); } }, function (keys) {
721
+ keys = keys.slice(0, room);
722
+ U.spinner(true, U.t('Importing…'));
723
+ var made = [];
724
+ keys.reduce(function (chain, k) { return chain.then(function () { return nuvioMake(list[+k]).then(function (p) { if (p) { made.push(p); } }); }); }, Promise.resolve()).then(function () {
725
+ U.spinner(false);
726
+ markHomeDirty();
727
+ renderSettings();
728
+ if (!made.length) { U.toast(U.t('Nothing imported'), 4000); return; }
729
+ var repos = [];
730
+ keys.forEach(function (k) { (list[+k].plugins || []).forEach(function (r) { if (!repos.some(function (x) { return x.url === r.url; })) { repos.push(r); } }); });
731
+ offerPlugins(repos, function () {
732
+ if (made.length === 1) {
733
+ confirm(U.t('“{name}” added. Switch to it now?', { name: made[0].name }), U.t('Switch to it'), function () { V.switchProfile(made[0].id); }, { plain: true, noLabel: U.t('Not now'), focusYes: true });
734
+ } else { U.toast(U.tn(made.length, 'Imported {n} profile', 'Imported {n} profiles'), 4000); }
735
+ });
736
+ });
737
+ });
738
+ }
739
+ function nuvioMake(n, name) {
740
+ var p = Profiles.add(name || n.name, NuvioImport.nearestColor(n.color, V.PROFILE_COLORS), U.t('Profile {n}', { n: 1 }));
741
+ if (!p) { return Promise.resolve(null); }
742
+ function put(k, v) { try { window.localStorage.setItem(Profiles.keyFor(p.slot, 'stremiok.' + k), JSON.stringify(v)); } catch (e) {} }
743
+ var urls = [];
744
+ n.addons.forEach(function (u) { var x = (Stremio.normalizeAddonUrl && Stremio.normalizeAddonUrl(u)) || ''; if (x && urls.indexOf(x) === -1) { urls.push(x); } });
745
+ if (urls.length) { var origin = {}; urls.forEach(function (u) { origin[u] = 'nuvio'; }); put('addons', urls); put('addonorigin', origin); }
746
+ if (Object.keys(n.watched).length) { put('watched', n.watched); }
747
+ // (its progress: each title's name and poster looked up, the most recent first; one that
748
+ // can't be found isn't brought)
749
+ var recent = n.progress.slice().sort(function (a, b) { return b.updated - a.updated; });
750
+ return Promise.all(recent.map(function (x) {
751
+ return Promise.resolve(Stremio.getMeta(x.type, x.parent)).then(function (m) { return m && m.name ? { x: x, m: m } : null; }, function () { return null; });
752
+ })).then(function (found) {
753
+ var all = {};
754
+ found.forEach(function (f) {
755
+ if (!f) { return; }
756
+ var x = f.x, ep = x.type === 'series';
757
+ all[x.type + ':' + x.id] = { id: x.id, type: x.type, name: ep ? f.m.name + ' S' + x.season + 'E' + x.episode : f.m.name, poster: f.m.poster, background: f.m.background,
758
+ parent: ep ? x.parent : undefined, position: x.position, duration: x.duration, updated: x.updated || Date.now() };
759
+ });
760
+ if (Object.keys(all).length) { put('progress', all); }
761
+ return p;
762
+ });
763
+ }
764
+ // The list kept from the first change on (the profile StremioK has always run as, the first).
765
+ function profileEnsure() { Profiles.ensure(U.t('Profile {n}', { n: 1 })); }
766
+ function profileName(title, value, then) {
767
+ App.openEntry({
768
+ title: title, hint: U.t('Its name, as the profiles list shows it. RETURN cancels.'), value: value || '', placeholder: U.t('name'),
769
+ validate: function (v) { return ('' + v).trim() ? null : U.t('A name, please'); },
770
+ onConfirm: function (v) { App.back(); then(('' + v).trim().slice(0, 24)); }
771
+ });
772
+ }
773
+
486
774
  // The app version, from the ?v= cache-buster build.sh stamps on every script tag
487
775
  // (kept in sync with package.json / config.xml; works on TizenBrew and desktop too).
488
776
  function appVersion() {
@@ -521,6 +809,7 @@
521
809
  wrap.appendChild(sectionRow(U.t('Appearance'), U.t('Look, background, accent color, zoom, posters, spoilers'), 'appearance'));
522
810
  wrap.appendChild(sectionRow(U.t('Home'), U.t('The tab it opens on, the top menu, Home feeds, Search results'), 'home'));
523
811
  wrap.appendChild(sectionRow(U.t('Diagnostics'), U.t('Logs, storage, installed apps; how StremioK was installed'), 'diagnostics'));
812
+ if (typeof Profiles !== 'undefined') { wrap.appendChild(sectionRow(U.t('Profiles'), U.t('Who watches: each profile its own addons, settings, progress and accounts'), 'profiles')); }
524
813
  if (typeof YTPlay !== 'undefined' && YTPlay.installMode && YTPlay.installMode() === 'tizenbrew') { wrap.appendChild(U.el('div', 'hint', TIZENBREW_NOTE)); }
525
814
  focusBack(wrap);
526
815
  }
@@ -666,6 +955,16 @@
666
955
  acct.__onselect = stremioImport;
667
956
  wrap.appendChild(acct);
668
957
  }
958
+ if (typeof NuvioImport !== 'undefined') {
959
+ var nacct = U.el('div', 'addon-item focusable add-row');
960
+ var nn = U.el('div', 'a-name', U.t('Import addons from Nuvio'));
961
+ nn.appendChild(originBadge('nuvio'));
962
+ nacct.appendChild(nn);
963
+ nacct.appendChild(U.el('div', 'a-url', typeof NuvioSync !== 'undefined' && NuvioSync.isConnected() && !NuvioSync.connectStatus().reconnect ? U.t('From the Nuvio account connected in Integrations: tick the addons to add')
964
+ : U.t('Sign in on your phone with a QR code, then tick the addons to add (StremioK signs out straight after)')));
965
+ nacct.__onselect = nuvioAddonsImport;
966
+ wrap.appendChild(nacct);
967
+ }
669
968
  if (typeof YTPlay !== 'undefined' && YTPlay.aiomAddons && YTPlay.installMode() !== 'browser') {
670
969
  var am = aiomSaved();
671
970
  var aio = U.el('div', 'addon-item focusable');
@@ -713,6 +1012,48 @@
713
1012
  });
714
1013
  });
715
1014
  }
1015
+ // Import addons from Nuvio: the connected account's (its kept session; the profile it follows
1016
+ // first), else Nuvio's sign-in, read and signed out at once; a profile picked (if several),
1017
+ // then its addons to tick, as Stremio's.
1018
+ function nuvioAddonsImport() {
1019
+ function chooseFrom(list, first) {
1020
+ list = list.filter(function (p) { return p.addons.length; });
1021
+ if (!list.length) { U.toast(U.t('That Nuvio account has no addons StremioK can use'), 5000); return; }
1022
+ if (list.length === 1) { nuvioAddonPick(list[0]); return; }
1023
+ pickList(U.t('Which Nuvio profile?'), list.map(function (p, i) { return ['' + i, p.name + ' · ' + U.tn(p.addons.length, '{n} addon', '{n} addons')]; }),
1024
+ first != null ? '' + Math.max(0, list.map(function (p) { return p.index; }).indexOf(first)) : null, function (i) { nuvioAddonPick(list[+i]); });
1025
+ }
1026
+ if (typeof NuvioSync !== 'undefined' && NuvioSync.isConnected() && !NuvioSync.connectStatus().reconnect) {
1027
+ U.spinner(true);
1028
+ NuvioSync.session().then(function (s) { return NuvioImport.readAddons(s.cfg, s.token, true).then(function (list) { U.spinner(false); chooseFrom(list, s.profile); }); }).then(null, function (e) {
1029
+ U.spinner(false);
1030
+ U.toast(U.t('Couldn’t import: {why}', { why: (e && e.message) || U.t('unknown') }), 5000);
1031
+ });
1032
+ return;
1033
+ }
1034
+ nuvioSignIn(U.t('Import addons from Nuvio'), U.t('Sign in to Nuvio there and approve (Nuvio calls it signing in a TV). StremioK reads your addons once, then signs out. Waiting…'), function (cfg, tok, body, gone) {
1035
+ return NuvioImport.readAddons(cfg, tok.access).then(function (list) {
1036
+ if (gone()) { return; }
1037
+ closeModal();
1038
+ chooseFrom(list, null);
1039
+ });
1040
+ });
1041
+ }
1042
+ function nuvioAddonPick(p) {
1043
+ var mine = Stremio.getAddonUrls();
1044
+ var items = p.addons.map(function (x, i) {
1045
+ var u = (Stremio.normalizeAddonUrl && Stremio.normalizeAddonUrl(x.url)) || x.url;
1046
+ return { key: '' + i, label: (x.name || shortHost(x.url)) + ' · ' + shortHost(x.url), have: mine.indexOf(x.url) !== -1 || mine.indexOf(u) !== -1 };
1047
+ });
1048
+ pickMany(U.t('Nuvio’s “{name}” addons: tick the ones to add', { name: p.name }), items, { button: function (n) { return U.tn(n, 'Import {n} addon', 'Import {n} addons'); } }, function (keys) {
1049
+ var n = 0, last = null;
1050
+ keys.forEach(function (k) { var added = Stremio.addAddon(p.addons[+k].url); if (added) { n++; last = added; if (Stremio.setAddonOrigin) { Stremio.setAddonOrigin(added, 'nuvio'); } } });
1051
+ clearCatalogCache();
1052
+ refreshAddonRows(last);
1053
+ U.toast(U.tn(n, 'Imported {n} addon', 'Imported {n} addons'), 3000);
1054
+ renderSettings();
1055
+ });
1056
+ }
716
1057
  function importPick(list) {
717
1058
  if (!list.length) { U.toast(U.t('Your Stremio account has no addons StremioK can use'), 5000); return; }
718
1059
  var mine = Stremio.getAddonUrls();
@@ -788,7 +1129,7 @@
788
1129
  // refuses is forgotten (the address stays) and asked for again.
789
1130
  var AIOM_KEY = 'stremiok.aiomanager';
790
1131
  // Where an addon came from (Stremio.addonOrigin): a letter badge, and the words for it.
791
- var ORIGIN_BADGE = { stremio: ['S', 'src-s', U.t('From Stremio')], aiomanager: ['A', 'src-a', U.t('From AIOManager')], config: ['C', 'src-c', U.t('From a configuration file')] };
1132
+ var ORIGIN_BADGE = { stremio: ['S', 'src-s', U.t('From Stremio')], aiomanager: ['A', 'src-a', U.t('From AIOManager')], config: ['C', 'src-c', U.t('From a configuration file')], nuvio: ['N', 'src-n', U.t('From Nuvio')] };
792
1133
  function originBadge(kind) { var b = ORIGIN_BADGE[kind]; return b ? U.el('span', 'src-badge ' + b[1], b[0]) : null; }
793
1134
  function aiomSaved() {
794
1135
  var x = U.store.get(AIOM_KEY, {}) || {};
@@ -929,9 +1270,26 @@
929
1270
  // A configuration file's text: what it has listed, none ticked, to tick and import. here():
930
1271
  // the entry screen still showing (back to Settings from it). Imported settings: StremioK
931
1272
  // starts again with them.
932
- function importText(text, here) {
1273
+ function importText(text, here, intoThis) {
933
1274
  var parsed = Stremio.parseSetupList(text);
934
1275
  if (!parsed.items.length) { U.toast(U.t('No supported entries found in that file') + (parsed.ignored ? ' ' + U.t('({n} ignored)', { n: parsed.ignored }) : ''), 4500); return; }
1276
+ // (into this profile, or a new one: made, the file kept for it, and StremioK started in it,
1277
+ // where it's listed to tick: js/profiles.js)
1278
+ if (!intoThis && typeof Profiles !== 'undefined' && Profiles.list().length < Profiles.MAX && Profiles.list().length !== Profiles.MAX) {
1279
+ var fromName = parsed.profile && parsed.profile.name;
1280
+ pickList(U.t('Import it into'), [['this', U.t('This profile')], ['new', fromName ? U.t('A new profile: “{name}”', { name: fromName }) : U.t('A new profile')]], 'this', function (v) {
1281
+ if (v === 'this') { importText(text, here, true); return; }
1282
+ function make(name) {
1283
+ var p = Profiles.add(name, parsed.profile && parsed.profile.color, U.t('Profile {n}', { n: 1 }));
1284
+ if (!p) { U.toast(U.t('Up to {n} profiles', { n: Profiles.MAX }), 4000); return; }
1285
+ try { window.localStorage.setItem(Profiles.keyFor(p.slot, 'stremiok.importpending'), JSON.stringify(('' + text).slice(0, 1572864))); } catch (e) {}
1286
+ if (here()) { App.back(); }
1287
+ V.switchProfile(p.id);
1288
+ }
1289
+ if (fromName) { make(fromName); } else { profileName(U.t('New profile'), '', make); }
1290
+ });
1291
+ return;
1292
+ }
935
1293
  if (here()) { App.back(); renderSettings(); }
936
1294
  pickMany(U.t('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 }; }),
937
1295
  { button: function (n) { return U.t('Import {n}', { n: n }); } }, function (keys) {
@@ -1088,7 +1446,7 @@
1088
1446
  if (!st.url) { return U.t('Not read yet'); }
1089
1447
  parts.push(U.tn(st.count || 0, '{n} channel', '{n} channels', { n: thousands(st.count || 0) }) + (st.groups ? ' ' + U.tn(st.groups, 'in {n} group', 'in {n} groups') : ''));
1090
1448
  if (st.fetchedAt) { var d = new Date(st.fetchedAt); parts.push(U.t('downloaded {when}', { when: U.dayLabel(st.fetchedAt) + ' ' + two(d.getHours()) + ':' + two(d.getMinutes()) })); }
1091
- if (st.dropped) { parts.push(U.t('{n} more left out (a playlist keeps its first 30,000)', { n: thousands(st.dropped) })); }
1449
+ if (st.dropped) { parts.push(U.t('{n} more left out (a playlist keeps its first {max}: Largest playlist, below)', { n: thousands(st.dropped), max: thousands(IPTV.maxChannels()) })); }
1092
1450
  if (p.genres) { parts.push(U.tn(p.genres.length, '{n} group chosen', '{n} groups chosen')); }
1093
1451
  if (st.cut) { parts.push(st.cut > 0 ? U.t('stopped short of {n}: OK on it, then Channel groups, reads only what you want', { n: thousands(st.cut) }) : U.t('stopped short: OK on it, then Channel groups, reads only what you want')); }
1094
1452
  if (st.uncached) { parts.push(U.t('too large to save on the TV: downloaded each launch')); }
@@ -1111,7 +1469,7 @@
1111
1469
  function playlistProblem(p) {
1112
1470
  var st = Stremio.iptvStatus(p.id);
1113
1471
  if (p.off || !st.error) { return ''; }
1114
- return '⚠ ' + (st.stale ? U.t('Couldn’t refresh it (showing the saved copy):') + ' ' : '') + st.error;
1472
+ return '⚠ ' + (st.stale ? U.t('Couldn’t refresh it (showing the saved copy):') + ' ' : '') + st.error + (/^Too large/.test(st.error) ? ' — ' + U.t('see Largest playlist, below') : '');
1115
1473
  }
1116
1474
  // + Add Xtream account: its server, username and password, a page each (a whole Xtream link
1117
1475
  // in the server's fills the rest); checked with the server, then added (Stremio.iptvAddXtream).
@@ -1331,6 +1689,23 @@
1331
1689
  wrap.appendChild(subPickRow(U.t('Auto-refresh'), IPTV_EVERY, 'every',
1332
1690
  { get: function () { return { every: String(Stremio.iptvRefreshEvery()) }; }, set: function (c) { Stremio.iptvSetRefreshEvery(+c.every); } }));
1333
1691
  }
1692
+ // Largest playlist: what one may be (MB) and keep (channels); raised, the playlists it
1693
+ // cut short or refused are read again.
1694
+ var IPTV_SIZES = IPTV.SIZES.map(function (n) {
1695
+ var v = { mb: n, n: thousands(n * 1500) };
1696
+ return [String(n), n === 20 ? U.t('{mb} MB, up to {n} channels (default)', v) : U.t('{mb} MB, up to {n} channels', v)];
1697
+ });
1698
+ wrap.appendChild(subPickRow(U.t('Largest playlist'), IPTV_SIZES, 'size', {
1699
+ warning: U.t('Above 20 MB, an older TV may run out of memory and close StremioK; a big playlist takes longer to read, and may be too large to save on the TV'),
1700
+ get: function () { return { size: String(IPTV.sizeMb()) }; },
1701
+ set: function (c) {
1702
+ var was = IPTV.sizeMb();
1703
+ IPTV.setSizeMb(+c.size);
1704
+ if (IPTV.sizeMb() <= was) { return; }
1705
+ playlists.filter(function (p) { var st = Stremio.iptvStatus(p.id); return !p.off && !IPTV.isStalker(p) && (st.dropped || /^Too large/.test(st.error || '')); })
1706
+ .forEach(function (p) { Stremio.iptvReload(p.id).then(function () { refreshAddonRows('local:iptv'); }); });
1707
+ }
1708
+ }));
1334
1709
  wrap.appendChild(subPickRow(U.t('Stalker channels'), [['pages', U.t('First 100 pages (about 1,400 channels)')], ['all', U.t('Whole portal (up to 30,000 channels)')]], 'stalker', {
1335
1710
  warning: U.t('Whole portal can take many minutes on every Reload and Auto-refresh, the IPTV rows wait for a first read, and a portal may slow down, cut off or block a MAC address that asks so much'),
1336
1711
  get: function () { return { stalker: IPTV.stalkerAll() ? 'all' : 'pages' }; },
@@ -1574,6 +1949,7 @@
1574
1949
 
1575
1950
  // Your Stremio account, kept in step (js/stremio-sync.js)
1576
1951
  if (typeof StremioSync !== 'undefined' && typeof StremioAccount !== 'undefined') {
1952
+ if (typeof NuvioSync !== 'undefined') { wrap.appendChild(U.el('h2', null, U.t('Nuvio account'))); wrap.appendChild(nuvioAccountRow()); }
1577
1953
  wrap.appendChild(U.el('h2', null, U.t('Stremio account')));
1578
1954
  wrap.appendChild(stremioAccountRow());
1579
1955
  wrap.appendChild(U.el('div', 'hint', U.t('Connect your Stremio account (sign in on your phone): its Continue Watching, watched marks and Library then sync with StremioK, both ways.')));
@@ -1665,6 +2041,24 @@
1665
2041
 
1666
2042
  // Your Stremio account: connected (who, when it last synced, OK for Sync now / Disconnect), or
1667
2043
  // not (OK to connect: Stremio's sign-in code, as the addon import).
2044
+ // This profile kept in step with a Nuvio account's profile (js/nuvio-sync.js).
2045
+ function nuvioAccountRow() {
2046
+ var st = NuvioSync.connectStatus(), r = U.el('div', 'addon-item focusable cfg-row');
2047
+ function two(x) { return (x < 10 ? '0' : '') + x; }
2048
+ var d = st.lastSync ? new Date(st.lastSync) : null;
2049
+ r.appendChild(U.el('div', 'a-name', U.t('Nuvio account') + (st.connected && st.name ? ': ' + st.name : '')));
2050
+ r.appendChild(U.el('div', 'a-url', st.connected && st.reconnect ? U.t('Its sign-in no longer works — press OK to connect again')
2051
+ : st.connected ? (d ? U.t('Last synced {when}', { when: (U.dayLabel ? U.dayLabel(st.lastSync) + ' ' : '') + two(d.getHours()) + ':' + two(d.getMinutes()) }) : U.t('Not synced yet')) + (st.err ? ' · ⚠ ' + st.err : '') + ' · ' + U.t('OK for options')
2052
+ : U.t('Not connected — press OK to connect (where you stopped, watched marks and Library, both ways)')));
2053
+ r.__onselect = function () {
2054
+ if (!st.connected || st.reconnect) { if (st.reconnect) { NuvioSync.disconnect(); } nuvioConnect(null); return; }
2055
+ pickList(U.t('Nuvio account'), [['now', U.t('Sync now')], ['off', U.t('Disconnect')]], null, function (v) {
2056
+ if (v === 'now') { U.toast(U.t('Syncing with Nuvio…')); NuvioSync.sync().then(function () { markHomeDirty(); renderSettings(); }); }
2057
+ else if (v === 'off') { confirm(U.t('Disconnect from Nuvio? Nothing here is removed.'), U.t('Disconnect'), function () { NuvioSync.disconnect(); U.toast(U.t('Disconnected from Nuvio')); renderSettings(); }); }
2058
+ });
2059
+ };
2060
+ return r;
2061
+ }
1668
2062
  function stremioAccountRow() {
1669
2063
  var st = StremioSync.connectStatus(), r = U.el('div', 'addon-item focusable cfg-row');
1670
2064
  function two(x) { return (x < 10 ? '0' : '') + x; }
@@ -3014,5 +3408,6 @@
3014
3408
  V.backInSettings = backInSettings;
3015
3409
  V.renderEntry = renderEntry;
3016
3410
  V.renderSettings = renderSettings;
3411
+ V.importText = function (text) { ++_importGen; importText(text, function () { return false; }, true); }; // (a file imported as a new profile, once it's in use: js/app.js)
3017
3412
  V.settingsRoot = settingsRoot;
3018
3413
  })(ViewParts);
package/js/views.js CHANGED
@@ -5,7 +5,7 @@
5
5
  var Views = (function (V) {
6
6
  'use strict';
7
7
  return {
8
- renderHome: V.renderHome, renderDetail: V.renderDetail, applyAppearance: V.applyAppearance,
8
+ renderHome: V.renderHome, renderDetail: V.renderDetail, applyAppearance: V.applyAppearance, profilePicker: V.profilePicker, switchProfile: V.switchProfile, importText: V.importText,
9
9
  renderPerson: V.renderPerson, detailSnapshot: V.detailSnapshot, restoreDetail: V.restoreDetail, lightSnapshot: V.lightSnapshot, renderSettings: V.renderSettings,
10
10
  settingsRoot: V.settingsRoot, backInSettings: V.backInSettings, guideBackOn: V.guideBackOn,
11
11
  // a screen left: its downloads still running (a title page's details, Discover's
package/js/ytplay.js CHANGED
@@ -129,10 +129,15 @@ var YTPlay = (function () {
129
129
  // Where a Nuvio plugin's Worker sends its requests (js/plugins.js): { url, headers }, the
130
130
  // token in the link (a Worker's POST then needs no preflight). lan: home-network requests
131
131
  // allowed (Local-network links from internet addons).
132
+ // Without the token (it can't be read on every TV), the guide ticket goes in the link too: a
133
+ // Worker's POST can carry an Origin (seen on a Tizen 4 TV: every plugin request refused,
134
+ // "not allowed (origin)"), which the service lets through only with one of them (#21).
132
135
  function pluginNet(lan) {
133
136
  if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
134
137
  return ensureService().then(entryAuth).then(function (a) {
135
- return { url: PROXY + '/plug/fetch?' + (a.q || '').replace(/^&/, '') + (lan ? '&lan=1' : ''), headers: a.h || {} };
138
+ return (a.q ? Promise.resolve(a.q) : ticketOf(a)).then(function (cred) {
139
+ return { url: PROXY + '/plug/fetch?' + (cred || '').replace(/^&/, '') + (lan ? '&lan=1' : ''), headers: a.h || {} };
140
+ });
136
141
  });
137
142
  }
138
143
  function liveOpen(url, h, force, opts, cancel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stremiok",
3
- "version": "2.3.7",
3
+ "version": "2.4.0",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",
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.3.7'.slice(3), l = location, rest = (l.search || '') + (l.hash || '');
13
+ var v = '?v=2.4.0'.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
  })();