stremiok 2.3.8 → 2.4.1

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 ADDED
@@ -0,0 +1,181 @@
1
+ /* Profiles: who's watching. Global namespace: Profiles
2
+ Each profile keeps its own addons, settings, progress, watched marks, history and sign-ins
3
+ (Trakt, a Stremio account, media servers); what's the TV's — playlists, USB drives and network
4
+ folders, plugins, API keys, the streaming server, what the TV plays, Diagnostics — every
5
+ profile shares (TV below).
6
+ - Kept as one list (stremiok.profiles, the TV's): each profile's id, name, color and slot.
7
+ - A profile's saved state is StremioK's usual keys under its slot: the first profile's are the
8
+ names StremioK has always used (stremiok.progress), another's carry its slot
9
+ (stremiok.p2.progress). With one profile nothing changes, nothing is moved, and an older
10
+ StremioK still finds its data.
11
+ - U.store and U.bigStore turn each key into the active profile's (key()): the rest of
12
+ StremioK keeps its key names. The active profile is the one StremioK started in: switching
13
+ starts StremioK again.
14
+ Loaded before everything else (it reads the TV's storage itself); nothing here needs U. */
15
+ var Profiles = (function () {
16
+ 'use strict';
17
+ var KEY = 'stremiok.profiles', MAX = 5, SLOTS = ['', 'p2', 'p3', 'p4', 'p5'];
18
+ // The TV's own (every profile shares them): stremiok.<name>, or its own keys under <name>.
19
+ var TV = ['profiles', 'manifests', 'discoverempty', 'tmdbproviders', 'integrations', 'server', 'formats', 'resblock',
20
+ 'appshortcuts', 'appsallowed', 'bigdb', 'importurl', 'aspects', 'iptv.playlists', 'iptv.stalkerall', 'iptv.stalkerkeep',
21
+ 'iptv.every', 'iptv.size', 'liveformat', 'livefix', 'xtvod.cats', 'stvod.cats', 'local.index', 'local.indexes', 'local.matches',
22
+ 'local.fixes', 'local.matching', 'local.hidden', 'netfolders', 'plugins', 'downloads', 'homesnap', 'homecache',
23
+ 'homepreview', 'session', 'lastlog', 'startup'];
24
+ var TV_PREFIX = ['iptv.cache.', 'local.index.', 'plugins.code.'];
25
+ var SLOT_KEY = /^stremiok\.(p[2-9])\./; // (a profile's own key, other than the first's)
26
+ var COLORS = ['indigo', 'teal', 'orange', 'pink', 'green', 'red', 'purple', 'amber'];
27
+
28
+ function valid(d) {
29
+ if (!d || typeof d !== 'object' || !Array.isArray(d.list) || !d.list.length || d.list.length > MAX) { return false; }
30
+ var seen = {};
31
+ return d.list.every(function (p) {
32
+ var ok = p && typeof p.id === 'string' && /^[a-z0-9]{2,12}$/.test(p.id) && typeof p.name === 'string' && SLOTS.indexOf(p.slot) !== -1 && !seen['s' + p.slot] && !seen['i' + p.id];
33
+ if (ok) { seen['s' + p.slot] = 1; seen['i' + p.id] = 1; }
34
+ return ok;
35
+ });
36
+ }
37
+ function read() {
38
+ try { var d = JSON.parse(window.localStorage.getItem(KEY) || 'null'); return valid(d) ? d : null; } catch (e) { return null; }
39
+ }
40
+ var _data = read();
41
+ // When StremioK opens (Settings › Profiles): ask (the default), the last profile used, or one
42
+ // profile always (_data.start, with ask off) — except right after a switch (see setActive).
43
+ function recentSwitch() { var at = _data && +_data.switched, now = Date.now(); return !!at && at <= now && now - at < 60000; }
44
+ if (_data && _data.ask === false && _data.start && _data.start !== _data.active && !recentSwitch()) {
45
+ for (var s0 = 0; s0 < _data.list.length; s0++) { if (_data.list[s0].id === _data.start) { _data.active = _data.start; save(); break; } } // (save: hoisted, below)
46
+ }
47
+ function active() {
48
+ if (!_data) { return null; }
49
+ for (var i = 0; i < _data.list.length; i++) { if (_data.list[i].id === _data.active) { return _data.list[i]; } }
50
+ return _data.list[0];
51
+ }
52
+ var _slot = (active() || { slot: '' }).slot; // (fixed for this run: switching starts StremioK again)
53
+
54
+ // A key of StremioK's: the TV's own, or a profile's.
55
+ function isTv(k) {
56
+ k = '' + k;
57
+ if (k.indexOf('stremiok.') !== 0) { return true; } // (not StremioK's: left alone)
58
+ var n = k.slice(9);
59
+ if (TV.indexOf(n) !== -1) { return true; }
60
+ for (var i = 0; i < TV_PREFIX.length; i++) { if (n.indexOf(TV_PREFIX[i]) === 0) { return true; } }
61
+ return false;
62
+ }
63
+ // The key as kept for the active profile: the TV's as it is; a profile's under its slot (none
64
+ // for the first profile). A key already under a slot is left as it is.
65
+ function key(k) {
66
+ k = '' + k;
67
+ if (!_slot || SLOT_KEY.test(k) || isTv(k)) { return k; }
68
+ return 'stremiok.' + _slot + '.' + k.slice(9);
69
+ }
70
+ function keyFor(slot, k) {
71
+ k = '' + k;
72
+ if (!slot || isTv(k)) { return k; }
73
+ return 'stremiok.' + slot + '.' + k.slice(9);
74
+ }
75
+ // Whose a kept key is: the slot of the profile it belongs to ('' the first's), or null (the TV's).
76
+ function slotOf(physical) {
77
+ var m = SLOT_KEY.exec('' + physical);
78
+ if (m) { return m[1]; }
79
+ return isTv(physical) ? null : '';
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 }; }) : []; }
82
+
83
+ // ---- changing the list (Settings › Profiles, the picker) ----
84
+ function save() { try { window.localStorage.setItem(KEY, JSON.stringify(_data)); return true; } catch (e) { return false; } }
85
+ function newId() {
86
+ var s = '', used = _data ? _data.list.map(function (p) { return p.id; }) : [];
87
+ do { s = ''; while (s.length < 6) { s += Math.floor(Math.random() * 36).toString(36); } } while (used.indexOf(s) !== -1); // (an id only: not a secret)
88
+ return s;
89
+ }
90
+ // The list made the first time a second profile is added: the profile StremioK has always
91
+ // run as becomes the first (firstName), in the slot it always had.
92
+ function ensure(firstName) {
93
+ if (_data) { return; }
94
+ _data = { v: 1, active: '', ask: true, list: [{ id: newId(), slot: '', name: firstName, color: COLORS[0], at: Date.now() }] };
95
+ _data.active = _data.list[0].id;
96
+ }
97
+ function find(id) { return _data ? _data.list.filter(function (p) { return p.id === id; })[0] || null : null; }
98
+ function cleanName(n) { return ('' + (n || '')).replace(/[\u0000-\u001f]/g, '').trim().slice(0, 24); }
99
+ // A new profile (MAX at most), in the first free slot: its entry, or null (full).
100
+ function add(name, color, firstName) {
101
+ ensure(firstName);
102
+ if (_data.list.length >= MAX) { return null; }
103
+ var taken = _data.list.map(function (p) { return p.slot; }), slot = SLOTS.filter(function (x) { return taken.indexOf(x) === -1; })[0];
104
+ var p = { id: newId(), slot: slot, name: cleanName(name) || 'Profile', color: COLORS.indexOf(color) !== -1 ? color : COLORS[_data.list.length % COLORS.length], at: Date.now() };
105
+ _data.list.push(p);
106
+ save();
107
+ return { id: p.id, name: p.name, color: p.color, slot: p.slot };
108
+ }
109
+ function rename(id, name) { var p = find(id); if (p && cleanName(name)) { p.name = cleanName(name); save(); } }
110
+ function recolor(id, color) { var p = find(id); if (p && COLORS.indexOf(color) !== -1) { p.color = color; save(); } }
111
+ function setAsk(on) { if (_data) { _data.ask = !!on; delete _data.start; save(); } }
112
+ // 'ask' | 'last' | a profile's id.
113
+ function startChoice() { if (!_data || _data.ask !== false) { return 'ask'; } return (_data.start && find(_data.start)) ? _data.start : 'last'; }
114
+ function setStart(v) {
115
+ if (!_data) { return; }
116
+ if (v === 'ask') { _data.ask = true; delete _data.start; } else if (v === 'last' || !find(v)) { _data.ask = false; delete _data.start; } else { _data.ask = false; _data.start = v; }
117
+ save();
118
+ }
119
+ // The profile StremioK starts in next time (switching: then started again, see setActive's caller).
120
+ // switched: chosen just now (a switch, which restarts StremioK): the restart doesn't ask
121
+ // "Who's watching?" again (justSwitched, read once, within a minute).
122
+ function setActive(id, switched) { if (find(id)) { _data.active = id; if (switched) { _data.switched = Date.now(); } else { delete _data.switched; } save(); } }
123
+ function justSwitched() {
124
+ if (!_data || !_data.switched) { return false; }
125
+ var was = recentSwitch();
126
+ delete _data.switched; save();
127
+ return was;
128
+ }
129
+ // A profile's own keys in the settings storage: [physical key].
130
+ function keysOf(slot) {
131
+ var out = [];
132
+ try {
133
+ var ls = window.localStorage;
134
+ for (var i = 0; i < ls.length; i++) { var k = ls.key(i); if (k && slotOf(k) === slot && k !== KEY) { out.push(k); } }
135
+ } catch (e) {}
136
+ return out;
137
+ }
138
+ // What a new profile copies from the one it's made from, when asked to: its addons and their
139
+ // order, its settings and its media server sign-ins (not its history, nor its Trakt or Stremio
140
+ // account, nor a server's device id).
141
+ var COPY = ['addons', 'addonsoff', 'addonorigin', 'aiomanager', 'feeds', 'searchfeeds', 'sourcefeeds', 'ranking', 'youtube', 'prefs',
142
+ 'subcfg', 'audiocfg', 'playercfg', 'jellyfin.servers', 'jellyfin.libs', 'plex.servers', 'plex.libs'];
143
+ function copyInto(toSlot, fromSlot) {
144
+ var n = 0;
145
+ COPY.forEach(function (k) {
146
+ try {
147
+ var v = window.localStorage.getItem(keyFor(fromSlot, 'stremiok.' + k));
148
+ if (v !== null) { window.localStorage.setItem(keyFor(toSlot, 'stremiok.' + k), v); n++; }
149
+ } catch (e) {}
150
+ });
151
+ return n;
152
+ }
153
+ // A profile gone: removed from the list, and everything it kept with it (the settings storage
154
+ // here; the TV's database through bigRemove(physical key), StremioK's own). Never the active
155
+ // one, nor the last.
156
+ var BIG = ['trakt.watched', 'media.watched', 'stremio.items'];
157
+ function remove(id, bigRemove) {
158
+ var p = find(id);
159
+ if (!p || p.id === _data.active || _data.list.length < 2) { return false; }
160
+ keysOf(p.slot).forEach(function (k) { try { window.localStorage.removeItem(k); } catch (e) {} });
161
+ if (bigRemove) { BIG.forEach(function (k) { bigRemove(keyFor(p.slot, 'stremiok.' + k)); }); }
162
+ _data.list = _data.list.filter(function (x) { return x.id !== id; });
163
+ if (_data.start === id) { delete _data.start; } // (opened in: then the last one used)
164
+ save();
165
+ return true;
166
+ }
167
+
168
+ return {
169
+ KEY: KEY, MAX: MAX, COLORS: COLORS,
170
+ key: key, keyFor: keyFor, isTv: isTv, slotOf: slotOf,
171
+ slot: function () { return _slot; },
172
+ list: list,
173
+ active: function () { var a = active(); return a ? { id: a.id, name: a.name, color: a.color, slot: a.slot } : null; },
174
+ count: function () { return _data ? _data.list.length : 1; },
175
+ justSwitched: justSwitched,
176
+ ask: function () { return !!(_data && _data.list.length > 1 && _data.ask !== false); },
177
+ 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,
179
+ __data: function () { return _data; }, __reload: function () { _data = read(); _slot = (active() || { slot: '' }).slot; }
180
+ };
181
+ })();
package/js/stremio.js CHANGED
@@ -109,7 +109,7 @@ var Stremio = (function () {
109
109
 
110
110
  // Where an addon came from (Settings › Addons' letter badges): 'stremio' (your Stremio
111
111
  // account), 'aiomanager' (an AIOManager sync), 'config' (a configuration file), or '' (you).
112
- var ORIGIN_KEY = 'stremiok.addonorigin', ORIGINS = { stremio: 1, aiomanager: 1, config: 1 };
112
+ var ORIGIN_KEY = 'stremiok.addonorigin', ORIGINS = { stremio: 1, aiomanager: 1, config: 1, nuvio: 1 };
113
113
  function originsAll() { var o = U.store.get(ORIGIN_KEY, {}); return (o && typeof o === 'object' && !Array.isArray(o)) ? o : {}; }
114
114
  function addonOrigin(url) { var k = originsAll()[url]; return ORIGINS[k] ? k : ''; }
115
115
  function setAddonOrigin(url, kind) {
@@ -449,6 +449,7 @@ var Stremio = (function () {
449
449
  if (hasYouTube()) { addons.push(YouTube.synthAddon()); } // (after your addons: its rows last on Home)
450
450
  if (typeof Trakt !== 'undefined' && Trakt.isConnected()) { addons.push(Trakt.synthAddon()); } // (your Watchlist and Up next)
451
451
  if (typeof StremioSync !== 'undefined' && StremioSync.isConnected()) { addons.push(StremioSync.synthAddon()); } // (your Stremio account's Library)
452
+ if (typeof NuvioSync !== 'undefined' && NuvioSync.isConnected()) { addons.push(NuvioSync.synthAddon()); } // (the Nuvio profile's Library, kept in step)
452
453
  _loaded = addons;
453
454
  U.mark('addons');
454
455
  var stale = urls.filter(function (u) { return !_refreshedUrls[u] && saved[u]; });
@@ -609,6 +610,7 @@ var Stremio = (function () {
609
610
  out.push('# StremioK configuration, exported ' + new Date(Date.now()).toISOString().slice(0, 10) + (version ? ' from StremioK ' + version : '') + '.');
610
611
  out.push('# It holds your addon links, playlist logins, API keys and MAC addresses: keep it private.');
611
612
  out.push('# To import it: Settings › Content › Import configuration file (▣ From your phone: choose this file, or paste it).');
613
+ if (typeof Profiles !== 'undefined' && Profiles.count() > 1 && Profiles.active()) { out.push(EXPORT_LINE + 'profile ' + JSON.stringify({ name: Profiles.active().name, color: Profiles.active().color })); } // (the profile it's from: offered as a new profile's name on import)
612
614
  if (want.addons) { out.push(''); getAddonUrls().forEach(function (u) { out.push(u); }); }
613
615
  if (want.playlists) {
614
616
  out.push('');
@@ -662,6 +664,7 @@ var Stremio = (function () {
662
664
  return;
663
665
  }
664
666
  if (m[1] === 'store' && typeof o.k === 'string' && EXPORT_STORE.indexOf('stremiok.' + o.k) !== -1 && o.v !== undefined && o.v !== null) { store.push(o); return; }
667
+ if (m[1] === 'profile' && typeof o.name === 'string') { out.profile = { name: U.drawable(o.name).trim().slice(0, 24), color: typeof o.color === 'string' ? o.color : '' }; return; }
665
668
  if (m[1] === 'history' && typeof o.k === 'string' && HISTORY_STORE.indexOf('stremiok.' + o.k) !== -1 && o.v !== undefined && o.v !== null) { hist.push(o); return; }
666
669
  out.ignored++;
667
670
  }
package/js/util.js CHANGED
@@ -718,7 +718,7 @@ var U = (function () {
718
718
  var LEFTOVER_SHARE = 0.5, _busy = null, _refusalTidy = false;
719
719
  // Use the TV's database (Settings › Diagnostics › Storage; on unless turned off):
720
720
  // off, the big copies are kept in the settings storage (BIG_KEY: the ones that go here).
721
- var USE_KEY = 'stremiok.bigdb', BIG_KEY = /^stremiok\.(homecache|local\.index|iptv\.cache\.|trakt\.watched|media\.watched|stremio\.items)/;
721
+ var USE_KEY = 'stremiok.bigdb', BIG_KEY = /^stremiok\.(p[2-9]\.)?(homecache|local\.index|iptv\.cache\.|trakt\.watched|media\.watched|stremio\.items)/; // (a profile's own under its slot: js/profiles.js)
722
722
  function enabled() { return store.get(USE_KEY, true) !== false; }
723
723
  function lsBigKeys() {
724
724
  var out = [];
@@ -757,6 +757,7 @@ var U = (function () {
757
757
  }
758
758
  return {
759
759
  get: function (key) {
760
+ key = phys(key); // (the profile's own, or the TV's: js/profiles.js)
760
761
  return open().then(function (db) {
761
762
  if (!db) { return store.get(key, null, true); }
762
763
  return tx(db, 'readonly', function (os) { return os.get(key); }).then(function (v) { return v === undefined || v === true ? null : v; });
@@ -772,6 +773,7 @@ var U = (function () {
772
773
  // a newer save of the same key replaces the one waiting. Each refusal is noted with
773
774
  // the item's size, the database's figures and the TV's free disk.
774
775
  set: function (key, value) {
776
+ key = phys(key);
775
777
  delete _retry[key]; // (a newer copy: the one waiting to be tried again isn't wanted)
776
778
  return open().then(function (db) {
777
779
  if (!db) { return store.set(key, value); }
@@ -821,9 +823,16 @@ var U = (function () {
821
823
  });
822
824
  });
823
825
  },
826
+ // A key exactly as kept (a profile not in use, gone: js/profiles.js), not the active profile's.
827
+ removeExact: function (key) {
828
+ delete _retry[key];
829
+ try { window.localStorage.removeItem(key); delete _memo[key]; } catch (e) {}
830
+ return open().then(function (db) { return db ? tx(db, 'readwrite', function (os) { os['delete'](key); }) : true; });
831
+ },
824
832
  // keepRetry: a save waiting to be tried again stays (the Trakt history, moved to the
825
833
  // settings storage meanwhile, goes back into the database when it's taken)
826
834
  remove: function (key, keepRetry) {
835
+ key = phys(key);
827
836
  if (!keepRetry) { delete _retry[key]; }
828
837
  store.remove(key);
829
838
  return open().then(function (db) { return db ? tx(db, 'readwrite', function (os) { os['delete'](key); }) : true; });
@@ -1024,6 +1033,9 @@ var U = (function () {
1024
1033
  Pass noMemo=true for large one-shot blobs (IPTV playlist text) so they aren't
1025
1034
  kept in memory for the whole session. */
1026
1035
  var _memo = {};
1036
+ // A key as kept for the profile StremioK runs in (js/profiles.js: the TV's own keys as they
1037
+ // are, a profile's under its slot; with one profile, every key as it is).
1038
+ function phys(key) { return (typeof Profiles !== 'undefined' && Profiles.key) ? Profiles.key(key) : key; }
1027
1039
  // Regenerable caches, cleared first (in this order) when the storage is full.
1028
1040
  var CACHES = ['stremiok.homesnap', 'stremiok.homecache', 'stremiok.iptv.cache.', 'stremiok.showinfo', 'stremiok.manifests'];
1029
1041
  var _fullToldAt = null; // (when you were last told the storage is full)
@@ -1049,6 +1061,7 @@ var U = (function () {
1049
1061
  // whether anything changed since (the title page re-ranks its sources then).
1050
1062
  writes: function () { return _writes; },
1051
1063
  get: function (key, fallback, noMemo) {
1064
+ key = phys(key);
1052
1065
  var m = _memo[key];
1053
1066
  if (!m) {
1054
1067
  try {
@@ -1066,15 +1079,17 @@ var U = (function () {
1066
1079
  // keep: what was saved stays in memory as it is, so the next read needn't parse it again
1067
1080
  // (the playback progress, saved over and over).
1068
1081
  set: function (key, value, keep) {
1082
+ var cache = isCacheKey(key);
1083
+ key = phys(key);
1069
1084
  delete _memo[key];
1070
1085
  _writes++;
1071
1086
  var text;
1072
1087
  try { text = JSON.stringify(value); } catch (e0) { return false; }
1073
1088
  if (tryWrite(key, text)) { if (keep) { _memo[key] = { missing: false, val: value }; } return true; }
1074
- if (isCacheKey(key)) { return false; }
1089
+ if (cache) { return false; }
1075
1090
  var freed = [];
1076
1091
  for (var i = 0; i < CACHES.length; i++) {
1077
- var gone = clearCache(CACHES[i]);
1092
+ var gone = clearCache(phys(CACHES[i]));
1078
1093
  if (gone) { freed.push(CACHES[i]); }
1079
1094
  if (gone && tryWrite(key, text)) { log('storage', 'TV storage full: cleared ' + freed.join(', ') + ' to save ' + key); return true; }
1080
1095
  }
@@ -1084,6 +1099,7 @@ var U = (function () {
1084
1099
  return false;
1085
1100
  },
1086
1101
  remove: function (key) {
1102
+ key = phys(key);
1087
1103
  delete _memo[key];
1088
1104
  _writes++;
1089
1105
  try { window.localStorage.removeItem(key); } catch (e) {}
package/js/view-core.js CHANGED
@@ -204,6 +204,60 @@ var ViewParts = {};
204
204
  _modalScope = null; _modalPrevFocus = null;
205
205
  }
206
206
 
207
+ // ----- profiles: who's watching (js/profiles.js) -----
208
+ var PROFILE_COLORS = { indigo: '#5c6bc0', teal: '#26a69a', orange: '#fb8c00', pink: '#ec407a', green: '#43a047', red: '#e53935', purple: '#8e24aa', amber: '#ffb300' };
209
+ // A profile's round badge: its color, the first character of its name.
210
+ function profileBadge(p, cls) {
211
+ var b = U.el('span', 'pf-badge' + (cls ? ' ' + cls : ''));
212
+ b.style.background = PROFILE_COLORS[p.color] || PROFILE_COLORS.indigo;
213
+ var m = /^[\uD800-\uDBFF][\uDC00-\uDFFF]|^[\s\S]/.exec(('' + (p.name || '?')).trim() || '?');
214
+ b.textContent = (m ? m[0] : '?').toUpperCase();
215
+ return b;
216
+ }
217
+ // "Who's watching?": every profile, the one in use focused. OK on it: then(); on another:
218
+ // StremioK starts again in it (switchProfile). BACK: as you were (then()).
219
+ function profilePicker(then, title) {
220
+ var list = (typeof Profiles !== 'undefined') ? Profiles.list() : [], now = Profiles.active();
221
+ var existing = document.querySelector('.modal-overlay');
222
+ if (existing) { existing.parentNode.removeChild(existing); }
223
+ var overlay = U.el('div', 'modal-overlay pf-overlay'), box = U.el('div', 'pf-box'), row = U.el('div', 'pf-row'), focus = null, done = false;
224
+ box.appendChild(U.el('div', 'pf-title', title || U.t('Who’s watching?')));
225
+ function finish() { if (done) { return; } done = true; if (then) { then(); } }
226
+ list.forEach(function (p) {
227
+ var c = U.el('div', 'pf-card focusable');
228
+ c.appendChild(profileBadge(p, 'big'));
229
+ c.appendChild(U.el('div', 'pf-name', p.name));
230
+ c.__onselect = function () {
231
+ if (now && p.id === now.id) { onModalClose(null); closeModal(); finish(); return; }
232
+ done = true; onModalClose(null); switchProfile(p.id);
233
+ };
234
+ if (now && p.id === now.id) { focus = c; }
235
+ row.appendChild(c);
236
+ });
237
+ box.appendChild(row);
238
+ overlay.appendChild(box);
239
+ document.body.appendChild(overlay);
240
+ showModal(overlay, focus || row.firstChild);
241
+ onModalClose(finish);
242
+ }
243
+ // Another profile: what's waiting to go to Trakt or your Stremio account given a moment
244
+ // (SWITCH_WAIT at most: what doesn't go is kept, and sent when that profile is in use again),
245
+ // then StremioK starts again in it (each profile's settings, language and syncs are read as
246
+ // StremioK starts).
247
+ var SWITCH_WAIT = 3000;
248
+ function switchProfile(id) {
249
+ if (typeof Profiles === 'undefined') { return; }
250
+ U.spinner(true, U.t('Switching profile…'));
251
+ var waits = [];
252
+ try { if (typeof Trakt !== 'undefined' && Trakt.isConnected() && Trakt.flush) { waits.push(Trakt.flush()); } } catch (e) {}
253
+ try { if (typeof StremioSync !== 'undefined' && StremioSync.isConnected() && StremioSync.sync) { waits.push(StremioSync.sync()); } } catch (e2) {}
254
+ try { if (typeof NuvioSync !== 'undefined' && NuvioSync.isConnected()) { waits.push(NuvioSync.sync()); } } catch (e4) {}
255
+ var gone = false;
256
+ function go() { if (gone) { return; } gone = true; Profiles.setActive(id, true); try { window.location.reload(); } catch (e3) {} }
257
+ setTimeout(go, SWITCH_WAIT);
258
+ Promise.all(waits.map(function (w) { return Promise.resolve(w).then(null, function () {}); })).then(go);
259
+ }
260
+
207
261
  // A YouTube channel or playlist (StremioK's own, or YouTubio's): its source for your
208
262
  // YouTube catalogs (Settings › Content › YouTube), or '' when it isn't one.
209
263
  function youTubeList(id) {
@@ -585,6 +639,14 @@ var ViewParts = {};
585
639
  var strip = U.el('div', 'menu-scroll');
586
640
  strip.appendChild(tabbar);
587
641
  item('hchip', 'settings', U.t('Settings'), '⚙', function () { App.openSettings(); }, strip);
642
+ if (typeof Profiles !== 'undefined' && Profiles.count() > 1) { // (who's watching: OK to switch)
643
+ var me = Profiles.active() || { name: '?' }, chip = U.el('div', 'hchip pf-chip focusable');
644
+ chip.appendChild(profileBadge(me, 'small'));
645
+ chip.setAttribute('aria-label', me.name);
646
+ chip.__onselect = function () { profilePicker(null, U.t('Switch profile')); };
647
+ chip.__navDOWN = down;
648
+ strip.appendChild(chip);
649
+ }
588
650
  head.appendChild(strip);
589
651
  setTimeout(function () { showActiveItem(strip); }, 0); // (once it's on screen)
590
652
  var brand = U.el('div', 'brand');
@@ -827,9 +889,8 @@ var ViewParts = {};
827
889
  if (type === 'movie' || eps.length) {
828
890
  opts.push(['watched', watched ? U.t('Mark unwatched') : (type === 'series' ? U.t('Mark whole series watched') : U.t('Mark watched'))]);
829
891
  }
830
- // Your Stremio account's Library (connected): in it, or not
831
- var lib = typeof StremioSync !== 'undefined' && StremioSync.isConnected() && (type === 'movie' || type === 'series');
832
- if (lib) { opts.push(['lib', StremioSync.inLibrary(type, m.id) ? U.t('Remove from Stremio Library') : U.t('Add to Stremio Library')]); }
892
+ // The Libraries connected (your Stremio account's, a Nuvio profile's): in each, or not
893
+ if (type === 'movie' || type === 'series') { libraries().forEach(function (L) { opts.push(['lib:' + L.id, L.has(type, m.id) ? L.remove : L.add]); }); }
833
894
  // Rate on Trakt (connected, a title with an IMDb id): yours shown once rated
834
895
  var canRate = typeof Trakt !== 'undefined' && Trakt.isConnected() && Trakt.rate && /^tt\d+$/.test(m.id);
835
896
  var mine = canRate ? Trakt.myRating(type, m.id) : null;
@@ -837,7 +898,7 @@ var ViewParts = {};
837
898
  return { name: m.name || m.title || '', items: opts, run: function (v) {
838
899
  if (v === 'details') { App.openDetail(type, m.id, meta); }
839
900
  else if (v === 'np') { toggleNowPlaying(type, m); }
840
- else if (v === 'lib') { toggleLibrary(type, m); }
901
+ else if (/^lib:/.test(v)) { toggleLibrary(type, m, v.slice(4)); }
841
902
  else if (v === 'watched') { setTitleWatched(type, m, !watched); }
842
903
  else if (v === 'rate') { rateOnTrakt(type, m.id, m.name || m.title || ''); }
843
904
  } };
@@ -943,13 +1004,29 @@ var ViewParts = {};
943
1004
  // one it was opened by, e.g. a TMDB id in Discover for an IMDb one).
944
1005
  function nowPlayingLabel(type, id) { return inNowPlaying(type, id) ? U.t('✓ In Continue Watching') : U.t('+ Add to Continue Watching'); }
945
1006
  // Your Stremio account's Library (Settings › Integrations › Stremio account): a title in it or not.
946
- function libraryLabel(type, id) { return StremioSync.inLibrary(type, id) ? U.t('✓ In Stremio Library') : U.t('+ Stremio Library'); }
947
- function toggleLibrary(type, m) {
948
- var on = !StremioSync.inLibrary(type, m.id);
949
- StremioSync.setInLibrary(type, { id: m.id, name: m.name || m.title || '', poster: m.poster || '' }, on);
950
- U.toast(on ? U.t('Added to your Stremio Library') : U.t('Removed from your Stremio Library'));
1007
+ // The Libraries this profile has: its Stremio account's (connected), its Nuvio profile's (kept in step).
1008
+ function libraries() {
1009
+ var out = [];
1010
+ if (typeof StremioSync !== 'undefined' && StremioSync.isConnected()) {
1011
+ out.push({ id: 'stremio', has: StremioSync.inLibrary, set: StremioSync.setInLibrary, add: U.t('Add to Stremio Library'), remove: U.t('Remove from Stremio Library'),
1012
+ inLabel: U.t('✓ In Stremio Library'), outLabel: U.t('+ Stremio Library'), added: U.t('Added to your Stremio Library'), removed: U.t('Removed from your Stremio Library') });
1013
+ }
1014
+ if (typeof NuvioSync !== 'undefined' && NuvioSync.isConnected()) {
1015
+ out.push({ id: 'nuvio', has: NuvioSync.inLibrary, set: NuvioSync.setInLibrary, add: U.t('Add to Nuvio Library'), remove: U.t('Remove from Nuvio Library'),
1016
+ inLabel: U.t('✓ In Nuvio Library'), outLabel: U.t('+ Nuvio Library'), added: U.t('Added to your Nuvio Library'), removed: U.t('Removed from your Nuvio Library') });
1017
+ }
1018
+ return out;
1019
+ }
1020
+ function libraryOf(which) { return libraries().filter(function (L) { return L.id === (which || 'stremio'); })[0] || libraries()[0]; }
1021
+ function libraryLabel(type, id, which) { var L = libraryOf(which); return L ? (L.has(type, id) ? L.inLabel : L.outLabel) : ''; }
1022
+ function toggleLibrary(type, m, which) {
1023
+ var L = libraryOf(which);
1024
+ if (!L) { return; }
1025
+ var on = !L.has(type, m.id);
1026
+ L.set(type, { id: m.id, name: m.name || m.title || '', poster: m.poster || '', background: m.background || '' }, on);
1027
+ U.toast(on ? L.added : L.removed);
951
1028
  }
952
- function libraryOn() { return typeof StremioSync !== 'undefined' && StremioSync.isConnected(); }
1029
+ function libraryOn() { return libraries().length > 0; }
953
1030
 
954
1031
  // "Hold OK for more": shown while the focused item has a menu of its own behind a held OK
955
1032
  // (a card, a season, an episode, a source, a file on the USB drive…), so those menus can
@@ -970,6 +1047,7 @@ var ViewParts = {};
970
1047
  V._current = _current;
971
1048
  V.addonActions = addonActions;
972
1049
  V.buildTopMenu = buildTopMenu;
1050
+ V.profilePicker = profilePicker; V.switchProfile = switchProfile; V.profileBadge = profileBadge; V.PROFILE_COLORS = PROFILE_COLORS;
973
1051
  V.closeModal = closeModal;
974
1052
  V.confirm = confirm;
975
1053
  V.qrModal = qrModal; V.phoneGive = phoneGive;
@@ -991,4 +1069,5 @@ var ViewParts = {};
991
1069
  V.libraryLabel = libraryLabel;
992
1070
  V.toggleLibrary = toggleLibrary;
993
1071
  V.libraryOn = libraryOn;
1072
+ V.libraries = libraries;
994
1073
  })(ViewParts);
package/js/view-detail.js CHANGED
@@ -17,12 +17,15 @@
17
17
  function posterActions() { return V.posterActions.apply(null, arguments); } // core
18
18
  function scr() { return V.scr.apply(null, arguments); } // core
19
19
  function toggleNowPlaying() { return V.toggleNowPlaying.apply(null, arguments); } // core
20
- // Your Stremio account's Library (connected): + Stremio Library / ✓ In Stremio Library.
21
- function libraryPill(type, id) {
22
- if (!V.libraryOn() || _d.addonType) { return null; }
23
- var p = U.el('div', 'pill focusable', V.libraryLabel(type, id));
24
- p.__onselect = function () { V.toggleLibrary(type, _d.meta); setTimeout(function () { p.textContent = V.libraryLabel(type, id); }, 0); };
25
- return p;
20
+ // The Libraries connected (a Stremio account's, a Nuvio profile's): + Stremio Library / ✓ In
21
+ // Stremio Library, one pill each.
22
+ function libraryPills(type, id) {
23
+ if (!V.libraryOn() || _d.addonType) { return []; }
24
+ return V.libraries().map(function (L) {
25
+ var p = U.el('div', 'pill focusable', V.libraryLabel(type, id, L.id));
26
+ p.__onselect = function () { V.toggleLibrary(type, _d.meta, L.id); setTimeout(function () { p.textContent = V.libraryLabel(type, id, L.id); }, 0); };
27
+ return p;
28
+ });
26
29
  }
27
30
  function trimMeta() { return V.trimMeta.apply(null, arguments); } // home
28
31
  function searchFor() { return V.searchFor.apply(null, arguments); } // search
@@ -867,8 +870,7 @@
867
870
  np.__onselect = function () { toggleNowPlaying('series', _d.meta); _d._focusNp = true; drawDetail(); };
868
871
  if (_d._focusNp) { _d._epFocus = np; _d._focusNp = false; }
869
872
  row.appendChild(np);
870
- var lp = libraryPill('series', _d.meta.id || _d.id);
871
- if (lp) { row.appendChild(lp); }
873
+ libraryPills('series', _d.meta.id || _d.id).forEach(function (lp) { row.appendChild(lp); });
872
874
  var tp = trailerPill();
873
875
  if (tp) { row.appendChild(tp); }
874
876
  var mp = morePill();
@@ -1894,8 +1896,7 @@
1894
1896
  var np = U.el('div', 'pill focusable', nowPlayingLabel('movie', npId));
1895
1897
  np.__onselect = function () { toggleNowPlaying('movie', _d.meta); np.textContent = nowPlayingLabel('movie', npId); };
1896
1898
  row.appendChild(np);
1897
- var mlp = libraryPill('movie', npId);
1898
- if (mlp) { row.appendChild(mlp); }
1899
+ libraryPills('movie', npId).forEach(function (mlp) { row.appendChild(mlp); });
1899
1900
  var tp = trailerPill();
1900
1901
  if (tp) { row.appendChild(tp); }
1901
1902
  var mp = morePill();
package/js/view-home.js CHANGED
@@ -208,7 +208,8 @@
208
208
  if (m.description) { o.description = ('' + m.description).slice(0, 320); }
209
209
  return o;
210
210
  }
211
- function addonsSig() { return Stremio.getAddonUrls().join('|'); }
211
+ // (Home's saved rows are the TV's, kept once: the profile they're for in it, so another's are never shown: js/profiles.js)
212
+ function addonsSig() { return (typeof Profiles !== 'undefined' && Profiles.count() > 1 ? 'profile:' + Profiles.slot() + '|' : '') + Stremio.getAddonUrls().join('|'); }
212
213
  function sizeOf(o) { // (about how many bytes a trimmed card takes saved)
213
214
  var n = 40;
214
215
  for (var k in o) { if (Object.prototype.hasOwnProperty.call(o, k)) { n += k.length + ('' + o[k]).length + 6; } }
@@ -1082,8 +1083,17 @@
1082
1083
  // the whole show.
1083
1084
  // byActivity: the most recent activity first, whatever order you gave the row (Move): the
1084
1085
  // home bar's tiles (previewTiles).
1086
+ // An entry with no title id (one kept that way, from wherever: #20, the whole tab came up
1087
+ // blank): left out, and said so once in Diagnostics › Logs, with what it is.
1088
+ var _unsound = {};
1089
+ function sound(e) {
1090
+ if (e && typeof e.id === 'string' && e.id && typeof e.type === 'string') { return true; }
1091
+ var what = e ? (e.type + ' “' + (e.name || '') + '”' + (e._trakt ? ' (Trakt)' : e._stremio ? ' (Stremio account)' : '')) : String(e);
1092
+ if (!_unsound[what]) { _unsound[what] = 1; U.log('home', 'Continue Watching: left out an entry with no title id: ' + what); }
1093
+ return false;
1094
+ }
1085
1095
  function continueEntries(byActivity) {
1086
- var local = Player.continueList(), traktOn = typeof Trakt !== 'undefined' && Trakt.isConnected();
1096
+ var local = Player.continueList().filter(sound), traktOn = typeof Trakt !== 'undefined' && Trakt.isConnected();
1087
1097
  if (traktOn && Trakt.watchedPast) { local = local.filter(function (e) { return !Trakt.watchedPast(e); }); }
1088
1098
  var stremioOn = typeof StremioSync !== 'undefined' && StremioSync.isConnected();
1089
1099
  if (stremioOn) {
@@ -1113,6 +1123,7 @@
1113
1123
  if (!had[k]) { had[k] = 1; merged.push(e); }
1114
1124
  });
1115
1125
  }
1126
+ merged = merged.filter(sound);
1116
1127
  var list = onePerShow(merged); // (the most recent activity first)
1117
1128
  return byActivity ? list : inYourOrder(list);
1118
1129
  }
package/js/view-search.js CHANGED
@@ -24,8 +24,19 @@
24
24
  var why = U.urlProblem ? U.urlProblem(text) : (U.parseUrl(text) ? null : U.t('Not a link'));
25
25
  return why ? why + ' ' + U.t('(a link starts with https:// or http://)') : null;
26
26
  }
27
+ // A YouTube playlist's page (youtube.com/playlist?list=…, m. or music. too): its id, or ''.
28
+ // (A video's page with a list= plays the video.)
29
+ function ytPlaylistOf(url) {
30
+ var m = ('' + url).match(/^https?:\/\/(?:www\.|m\.|music\.)?youtube\.com\/playlist\?(?:[^#]*&)?list=([A-Za-z0-9_-]{10,64})(?:[&#]|$)/);
31
+ return m ? m[1] : '';
32
+ }
33
+ // A YouTube page, video's or playlist's (pasted into Search: opened, not searched for).
34
+ function isYouTubeLink(text) {
35
+ var t = ('' + text).trim();
36
+ return /^https?:\/\/(?:(?:www\.|m\.)?youtube\.com\/watch\?(?:.*&)?v=[A-Za-z0-9_-]{11}|youtu\.be\/[A-Za-z0-9_-]{11})/.test(t) || !!ytPlaylistOf(t);
37
+ }
27
38
  // Played as it is (nothing recorded): a YouTube video's page through StremioK's YouTube
28
- // service, anything else straight to the player.
39
+ // service, a playlist's opened as its videos, anything else straight to the player.
29
40
  function playLink(text) {
30
41
  var p = U.parseUrl(text);
31
42
  if (!p) { U.toast(U.t('That isn’t a link StremioK can play')); return; }
@@ -40,6 +51,8 @@
40
51
  }, function () { if (gen === _gen) { U.toast(YTPlay.unavailableMessage('video'), 6000); } });
41
52
  return;
42
53
  }
54
+ var list = ytPlaylistOf(url);
55
+ if (list) { App.openDetail('YouTube', 'ytk:p:' + list, null); return; } // (its videos as episodes, js/youtube.js)
43
56
  var name = '';
44
57
  try { name = decodeURIComponent((p.path || '').split('/').pop() || ''); } catch (e) { name = ''; }
45
58
  Player.play({ url: url, type: 'movie', id: 'link:' + url.length + ':' + url.slice(-40), name: (name || p.host || U.t('Link')).slice(0, 120), streams: [], link: true, private: true }, back);
@@ -180,6 +193,7 @@
180
193
  query = ('' + query).trim();
181
194
  var results = U.byId('search-results');
182
195
  if (!query) { return; }
196
+ if (isYouTubeLink(query)) { playLink(query); return; } // (a YouTube page pasted in: opened, not searched for)
183
197
  rememberSearch(query);
184
198
  renderRecent(-1);
185
199
  U.clear(results);