stremiok 2.3.8 → 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.
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); 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; } }
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);