stremiok 2.3.3 → 2.3.5

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +6 -5
  3. package/config.xml +1 -1
  4. package/css/style.css +5 -0
  5. package/index.html +42 -39
  6. package/js/app.js +7 -3
  7. package/js/downloads.js +16 -16
  8. package/js/epg.js +2 -3
  9. package/js/hubpreview.js +1 -1
  10. package/js/i18n.js +108 -0
  11. package/js/iptv.js +13 -13
  12. package/js/jellyfin.js +62 -29
  13. package/js/lang/ar.js +1941 -0
  14. package/js/lang/de.js +1941 -0
  15. package/js/lang/es.js +1941 -0
  16. package/js/lang/fi.js +1941 -0
  17. package/js/lang/fr.js +1941 -0
  18. package/js/lang/he.js +1941 -0
  19. package/js/lang/hi.js +1941 -0
  20. package/js/lang/it.js +1941 -0
  21. package/js/lang/ja.js +1941 -0
  22. package/js/lang/ko.js +1941 -0
  23. package/js/lang/languages.js +21 -0
  24. package/js/lang/pl.js +1941 -0
  25. package/js/lang/pt-BR.js +1941 -0
  26. package/js/lang/ru.js +1941 -0
  27. package/js/lang/tr.js +1941 -0
  28. package/js/lang/zh-CN.js +1941 -0
  29. package/js/local.js +9 -9
  30. package/js/netfolders.js +13 -13
  31. package/js/player-audio.js +17 -17
  32. package/js/player-controls.js +100 -100
  33. package/js/player-core.js +60 -57
  34. package/js/player-lang.js +22 -22
  35. package/js/player-quality.js +15 -15
  36. package/js/player-store.js +25 -18
  37. package/js/player-subs.js +69 -69
  38. package/js/plex.js +69 -21
  39. package/js/stremio-account.js +17 -12
  40. package/js/stremio-sync.js +641 -0
  41. package/js/stremio.js +79 -76
  42. package/js/stvod.js +4 -4
  43. package/js/trakt.js +23 -23
  44. package/js/tvapps.js +4 -4
  45. package/js/util.js +39 -27
  46. package/js/view-core.js +109 -92
  47. package/js/view-detail.js +135 -126
  48. package/js/view-discover.js +27 -27
  49. package/js/view-guide.js +13 -13
  50. package/js/view-home.js +148 -120
  51. package/js/view-search.js +25 -25
  52. package/js/view-settings.js +735 -643
  53. package/js/xtvod.js +2 -2
  54. package/js/youtube.js +17 -17
  55. package/js/ytplay.js +11 -6
  56. package/package.json +1 -1
  57. package/tizenbrew.html +1 -1
package/js/plex.js CHANGED
@@ -21,7 +21,7 @@ var Plex = (function () {
21
21
 
22
22
  var KEY = 'stremiok.plex.servers', DEV_KEY = 'stremiok.plex.device', LIBS_KEY = 'stremiok.plex.libs';
23
23
  var TV = 'https://clients.plex.tv', LINK = 'https://plex.tv/link';
24
- var PAGE = 100, INDEX_FRESH_MS = 30 * 60000, INDEX_RETRY_MS = 60000, LIBS_FRESH_MS = 86400000;
24
+ var PAGE = 100, INDEX_FRESH_MS = 30 * 60000, INDEX_RETRY_MS = 60000, INDEX_SLOW_MS = 30 * 60000, LIBS_FRESH_MS = 86400000;
25
25
  var PIN_EVERY = 3000, PIN_FOR = 10 * 60000, REPORT_EVERY = 60000, PIC_EVERY = 5000;
26
26
  var _changeFns = [];
27
27
  function onChange(fn) { _changeFns.push(fn); }
@@ -94,22 +94,22 @@ var Plex = (function () {
94
94
  function poll() {
95
95
  timer = setTimeout(function () {
96
96
  if (stopped) { return; }
97
- if (Date.now() - t0 > PIN_FOR) { fail('The code ran out: start again.'); return; }
97
+ if (Date.now() - t0 > PIN_FOR) { fail(U.t('The code ran out: start again.')); return; }
98
98
  U.getJSON(TV + '/api/v2/pins/' + enc(pin.id), 10000, 65536, null, headers(''), null, true).then(function (p) {
99
99
  if (stopped) { return; }
100
100
  if (!p || !p.authToken) { poll(); return; }
101
101
  stopped = true;
102
102
  accountServers('' + p.authToken).then(function (list) {
103
- if (!list.length) { cb.onError('Your Plex account has no servers.'); return; }
103
+ if (!list.length) { cb.onError(U.t('Your Plex account has no servers.')); return; }
104
104
  cb.onServers(list);
105
- }, function (e) { cb.onError('Couldn’t list your Plex servers (' + U.problem(e) + ').'); });
105
+ }, function (e) { cb.onError(U.t('Couldn’t list your Plex servers ({why}).', { why: U.problem(e) })); });
106
106
  }, function (e) {
107
- if (/HTTP 404/.test(e && e.message)) { fail('The code ran out: start again.'); } else { poll(); }
107
+ if (/HTTP 404/.test(e && e.message)) { fail(U.t('The code ran out: start again.')); } else { poll(); }
108
108
  });
109
109
  }, PIN_EVERY);
110
110
  }
111
111
  poll();
112
- }).then(null, function (e) { fail('Couldn’t get a code from Plex (' + U.problem(e) + ').'); });
112
+ }).then(null, function (e) { fail(U.t('Couldn’t get a code from Plex ({why}).', { why: U.problem(e) })); });
113
113
  return function () { stopped = true; clearTimeout(timer); };
114
114
  }
115
115
  // The account's servers (plex.tv's resources), each with its connections and its own token.
@@ -143,7 +143,7 @@ var Plex = (function () {
143
143
  function add(res) {
144
144
  var list = candidates(res), tried = [];
145
145
  function next(i) {
146
- if (i >= list.length) { return Promise.reject(new Error('No address of “' + res.name + '” answered' + (tried.length ? ' (' + tried.join(', ') + ')' : '') + '.')); }
146
+ if (i >= list.length) { return Promise.reject(new Error(tried.length ? U.t('No address of “{name}” answered ({tried}).', { name: res.name, tried: tried.join(', ') }) : U.t('No address of “{name}” answered.', { name: res.name }))); }
147
147
  return U.getJSON(list[i] + '/identity', 6000, 65536, null, { 'Accept': 'application/json' }, null, true).then(function (r) {
148
148
  if (('' + mc(r).machineIdentifier) !== res.machineId) { throw new Error('another server'); }
149
149
  return list[i];
@@ -197,7 +197,7 @@ var Plex = (function () {
197
197
  _libsAsked[srv.id] = true;
198
198
  return get(srv, '/library/sections').then(function (r) {
199
199
  var list = U.listOf(mc(r).Directory, 50, function (x) { return x.key != null && (x.type === 'movie' || x.type === 'show'); }).map(function (x) {
200
- return { id: clean(x.key, 20), name: clean(x.title) || (x.type === 'movie' ? 'Movies' : 'Shows'), type: x.type === 'movie' ? 'movie' : 'series' };
200
+ return { id: clean(x.key, 20), name: clean(x.title) || (x.type === 'movie' ? U.t('Movies') : U.t('Shows')), type: x.type === 'movie' ? 'movie' : 'series' };
201
201
  });
202
202
  if (!server(srv.id)) { return; }
203
203
  var all = libsAll(), keep = {}, before = JSON.stringify(all[srv.id] && all[srv.id].list);
@@ -219,8 +219,8 @@ var Plex = (function () {
219
219
  servers().forEach(function (srv) {
220
220
  var libs = libsOf(srv), on = many ? ' · ' + srv.name : '';
221
221
  if (!libs.length) { return; }
222
- if (libs.some(function (l) { return l.type === 'movie'; })) { out.push({ type: 'movie', id: 'px.' + srv.id + '.resume', name: 'Continue watching' + on, extra: [] }); }
223
- if (libs.some(function (l) { return l.type === 'series'; })) { out.push({ type: 'series', id: 'px.' + srv.id + '.nextup', name: 'Next up' + on, extra: [] }); }
222
+ if (libs.some(function (l) { return l.type === 'movie'; })) { out.push({ type: 'movie', id: 'px.' + srv.id + '.resume', name: U.t('Continue watching') + on, extra: [] }); }
223
+ if (libs.some(function (l) { return l.type === 'series'; })) { out.push({ type: 'series', id: 'px.' + srv.id + '.nextup', name: U.t('Next up') + on, extra: [] }); }
224
224
  libs.forEach(function (lib) {
225
225
  out.push({ type: lib.type, id: 'px.' + srv.id + '.' + lib.id, name: lib.name + on, extra: [{ name: 'search' }, { name: 'skip' }] });
226
226
  });
@@ -361,12 +361,12 @@ var Plex = (function () {
361
361
  if (tags(it.Genre).length) { m.genres = tags(it.Genre); }
362
362
  if (tags(it.Role).length) { m.cast = tags(it.Role); }
363
363
  if (tags(it.Director).length) { m.director = tags(it.Director); }
364
- if (+it.duration > 0 && t === 'movie') { m.runtime = Math.round(it.duration / 60000) + ' min'; }
364
+ if (+it.duration > 0 && t === 'movie') { m.runtime = U.t('{n} min', { n: Math.round(it.duration / 60000) }); }
365
365
  if (m.releaseInfo) { m.year = m.releaseInfo; }
366
366
  if (t === 'movie') { return m; }
367
367
  return episodes(srv, it.ratingKey).then(function (eps) {
368
368
  m.videos = eps.map(function (e) {
369
- var v = { id: showId + ':' + e.season + ':' + e.episode, season: e.season, episode: e.episode, title: clean(e.it.title, 200) || 'Episode ' + e.episode };
369
+ var v = { id: showId + ':' + e.season + ':' + e.episode, season: e.season, episode: e.episode, title: clean(e.it.title, 200) || U.t('Episode {n}', { n: e.episode }) };
370
370
  if (e.it.summary) { v.overview = ('' + e.it.summary).slice(0, 1000); }
371
371
  if (e.it.thumb) { v.thumbnail = img(srv, e.it.thumb, 640, 360); }
372
372
  var rel = Date.parse(e.it.originallyAvailableAt || '');
@@ -384,9 +384,16 @@ var Plex = (function () {
384
384
  var x = _index[srv.id];
385
385
  if (x && x.map && (x.p || Date.now() - x.at < INDEX_FRESH_MS)) { return Promise.resolve(x.map); }
386
386
  if (x && x.p) { return x.p; }
387
+ // (each library a page at a time, as Jellyfin's list: Jellyfin.shared.pages; one not all
388
+ // read, or not at all after its first page: __part, its titles looked up by name too)
389
+ var part = null;
387
390
  var p = Promise.all(libsOf(srv).map(function (lib) {
388
- return get(srv, '/library/sections/' + enc(lib.id) + '/all?type=' + (lib.type === 'movie' ? 1 : 2) + '&includeGuids=1', 16 * 1048576).then(function (r) {
389
- return U.listOf(mc(r).Metadata, 100000).map(function (it) { return { t: lib.type, it: it }; });
391
+ return share().pages(function (start) {
392
+ return get(srv, '/library/sections/' + enc(lib.id) + '/all?type=' + (lib.type === 'movie' ? 1 : 2) + '&includeGuids=1&sort=titleSort' +
393
+ '&X-Plex-Container-Start=' + start + '&X-Plex-Container-Size=' + share().INDEX_PAGE, 8 * 1048576).then(function (r) { return U.listOf(mc(r).Metadata, share().INDEX_PAGE); });
394
+ }).then(function (got) {
395
+ if (got.part) { part = part && part.e ? part : got.part; }
396
+ return got.items.map(function (it) { return { t: lib.type, it: it }; });
390
397
  });
391
398
  })).then(function (lists) {
392
399
  var map = { __ids: {}, __tm: {}, __played: [] }; // (__played: its watched films and shows)
@@ -399,12 +406,22 @@ var Plex = (function () {
399
406
  var played = e.t === 'movie' ? +it.viewCount > 0 : +it.leafCount > 0 && +it.viewedLeafCount >= +it.leafCount;
400
407
  if (played) { map.__played.push({ t: e.t, ids: titleIds(map, (e.t === 'movie' ? 'pxm.' : 'pxs.') + srv.id + '.', rk), at: (+it.lastViewedAt || 0) * 1000 }); }
401
408
  });
402
- if (_index[srv.id] && _index[srv.id].p === p) { _index[srv.id] = { at: Date.now(), map: map }; }
409
+ var at = Date.now();
410
+ if (part) {
411
+ map.__part = true;
412
+ if (part.e) {
413
+ U.log('plex', '“' + srv.name + '”: only some of its titles read (' + U.problem(part.e) + ')');
414
+ at -= INDEX_FRESH_MS - (/Timed out/i.test(part.e.message || '') ? INDEX_SLOW_MS : INDEX_RETRY_MS);
415
+ }
416
+ }
417
+ if (_index[srv.id] && _index[srv.id].p === p) { _index[srv.id] = { at: at, map: map }; }
403
418
  return map;
404
419
  }, function (e) {
405
420
  U.log('plex', '“' + srv.name + '”: its titles couldn’t be read (' + U.problem(e) + ')');
406
421
  var old = _index[srv.id], map = (old && old.map) || { __ids: {}, __tm: {}, __played: [], __err: true };
407
- if (old && old.p === p) { _index[srv.id] = { at: Date.now() - INDEX_FRESH_MS + INDEX_RETRY_MS, map: map }; }
422
+ // (asked again in a minute; one that timed out, after 30: titles looked up by name meanwhile, idsFor)
423
+ var slow = /Timed out/i.test((e && e.message) || '');
424
+ if (old && old.p === p) { _index[srv.id] = { at: Date.now() - INDEX_FRESH_MS + (slow ? INDEX_SLOW_MS : INDEX_RETRY_MS), map: map }; }
408
425
  return map;
409
426
  });
410
427
  _index[srv.id] = { at: x ? x.at : 0, map: x ? x.map : null, p: p };
@@ -438,7 +455,37 @@ var Plex = (function () {
438
455
  return sh.marksFrom(list);
439
456
  });
440
457
  }
441
- function copies(type, id) {
458
+ // A title the server's list can't give (never read, or not all of it: a library too big or slow):
459
+ // searched for by its name in each library of its kind, taken only when its IMDb or TMDB id is
460
+ // the one asked for (Jellyfin's way). Kept FOUND_MS (a failed search: asked again next time).
461
+ var FOUND_MS = 30 * 60000, _found = U.lru(300);
462
+ function lookup(srv, type, key, name) {
463
+ name = ('' + (name || '')).replace(/\s+/g, ' ').trim().slice(0, 100);
464
+ if (!name) { return Promise.resolve([]); }
465
+ var k = srv.id + '|' + type + '|' + key, had = _found.get(k);
466
+ if (had && had.p && Date.now() - had.at < FOUND_MS) { return had.p; }
467
+ var p = Promise.all(libsOf(srv).filter(function (l) { return l.type === type; }).map(function (lib) {
468
+ return get(srv, '/library/sections/' + enc(lib.id) + '/all?type=' + (type === 'movie' ? 1 : 2) + '&includeGuids=1&title=' + enc(name) +
469
+ '&X-Plex-Container-Start=0&X-Plex-Container-Size=40').then(function (r) {
470
+ return U.listOf(mc(r).Metadata, 40, function (it) { return it && it.ratingKey != null && (imdbOf(it) === key || (!!tmdbOf(it) && 'tmdb:' + tmdbOf(it) === key)); }).map(function (it) { return '' + it.ratingKey; });
471
+ });
472
+ })).then(flat, function (e) {
473
+ _found.set(k, null);
474
+ U.log('plex', '“' + srv.name + '”: “' + name + '” couldn’t be looked up (' + U.problem(e) + ')');
475
+ return [];
476
+ });
477
+ _found.set(k, { at: Date.now(), p: p });
478
+ return p;
479
+ }
480
+ // The server's items for a title: from its list; with no list yet, none to be had or not all of
481
+ // it, looked up by name meanwhile, the list's answer used when that finds none.
482
+ function idsFor(srv, type, key, name) {
483
+ var x = _index[srv.id];
484
+ var fromList = index(srv).then(function (map) { return map[type + '|' + key] || []; });
485
+ if (x && x.map && !x.map.__err && !x.map.__part) { return fromList; }
486
+ return lookup(srv, type, key, name).then(function (ids) { return ids.length ? ids : fromList; });
487
+ }
488
+ function copies(type, id, meta) {
442
489
  var key = '', season = null, episode = null;
443
490
  if (type === 'movie') { key = /^(tt\d+|tmdb:\d+)$/.test('' + id) ? '' + id : ''; }
444
491
  else if (type === 'series') {
@@ -446,9 +493,10 @@ var Plex = (function () {
446
493
  if (mm) { key = mm[1]; season = +mm[2]; episode = +mm[3]; }
447
494
  }
448
495
  if (!key) { return Promise.resolve([]); }
496
+ var name = meta && typeof meta.name === 'string' ? meta.name : '';
449
497
  return Promise.all(servers().map(function (srv) {
450
- return index(srv).then(function (map) {
451
- return Promise.all((map[type + '|' + key] || []).slice(0, 3).map(function (rk) {
498
+ return idsFor(srv, type, key, name).then(function (rks) {
499
+ return Promise.all(rks.slice(0, 3).map(function (rk) {
452
500
  return type === 'movie' ? item(srv, rk).then(function (it) { return sourcesOf(srv, it); }, none) : episodeSources(srv, rk, season, episode);
453
501
  }));
454
502
  }).then(flat, none);
@@ -527,14 +575,14 @@ var Plex = (function () {
527
575
  return e ? item(srv, e.it.ratingKey).then(function (it) { return sourcesOf(srv, it); }, none) : [];
528
576
  }, none);
529
577
  }
530
- function streams(type, id) {
578
+ function streams(type, id, meta) { // (meta: the title's details, for its name: lookup)
531
579
  var x = parseId(id);
532
580
  if (x) {
533
581
  if (!x.srv) { return Promise.resolve([]); }
534
582
  if (x.kind === 'm') { return item(x.srv, x.item).then(function (it) { return sourcesOf(x.srv, it); }, none); }
535
583
  return x.season != null ? episodeSources(x.srv, x.item, x.season, x.episode) : Promise.resolve([]);
536
584
  }
537
- return copies(type, id);
585
+ return copies(type, id, meta);
538
586
  }
539
587
  function isPlexId(id) { return /^px[ms]\./.test('' + id); }
540
588
 
@@ -4,6 +4,7 @@
4
4
  seconds, it then gives a sign-in key (start, wait). With it the account's addons are read
5
5
  (addons) and the key is given up at once (signOut): no password on the TV, nothing of the
6
6
  account kept, the account itself unchanged. StremioK has no key of Stremio's: none is needed.
7
+ Keeping your account in step (js/stremio-sync.js) signs in the same way and keeps the key.
7
8
  Global namespace: StremioAccount */
8
9
  var StremioAccount = (function () {
9
10
  'use strict';
@@ -14,7 +15,7 @@ var StremioAccount = (function () {
14
15
  function start() {
15
16
  return U.getJSON(LINK + 'create?type=Create', 15000, 65536).then(function (r) {
16
17
  var x = (r && r.result) || r || {};
17
- if (!/^[A-Za-z0-9]{2,16}$/.test(x.code || '') || !U.parseUrl(x.link)) { throw new Error('Stremio didn’t give a code'); }
18
+ if (!/^[A-Za-z0-9]{2,16}$/.test(x.code || '') || !U.parseUrl(x.link)) { throw new Error(U.t('Stremio didn’t give a code')); }
18
19
  return { code: x.code, link: x.link };
19
20
  });
20
21
  }
@@ -25,7 +26,7 @@ var StremioAccount = (function () {
25
26
  return new Promise(function (resolve, reject) {
26
27
  function ask() {
27
28
  if (stopped && stopped()) { reject(new Error('stopped')); return; }
28
- if (Date.now() > until) { reject(new Error('The code expired: try again')); return; }
29
+ if (Date.now() > until) { reject(new Error(U.t('The code expired: try again'))); return; }
29
30
  U.getJSON(LINK + 'read?type=Read&code=' + encodeURIComponent(code), 15000, 65536).then(function (r) {
30
31
  var key = r && r.result && r.result.authKey;
31
32
  if (typeof key === 'string' && key && key.length < 200) { if (stopped && stopped()) { signOut(key); reject(new Error('stopped')); return; } resolve(key); return; }
@@ -35,28 +36,32 @@ var StremioAccount = (function () {
35
36
  setTimeout(ask, POLL_MS);
36
37
  });
37
38
  }
38
- // POST a request to Stremio's API: its result.
39
- function call(method, body) {
39
+ // POST a request to Stremio's API: its result (an answer over max, MAX_BYTES unless given,
40
+ // refused). A refusal's Error carries Stremio's code (1: the sign-in no longer works).
41
+ function call(method, body, max) {
42
+ max = max || MAX_BYTES;
40
43
  return new Promise(function (resolve, reject) {
41
44
  var xhr = new XMLHttpRequest(), done = false;
42
- try { xhr.open('POST', API + method, true); } catch (e) { reject(new Error('couldn’t reach Stremio')); return; }
45
+ try { xhr.open('POST', API + method, true); } catch (e) { reject(new Error(U.t('couldn’t reach Stremio'))); return; }
43
46
  xhr.timeout = 20000;
44
47
  xhr.setRequestHeader('Content-Type', 'application/json');
45
48
  xhr.onprogress = function (ev) { // (an answer over MAX_BYTES: stopped as it arrives, as every other request is)
46
- if (!done && ev && ev.loaded > MAX_BYTES) { done = true; try { xhr.abort(); } catch (e) {} reject(new Error('too large an answer')); }
49
+ if (!done && ev && ev.loaded > max) { done = true; try { xhr.abort(); } catch (e) {} reject(new Error(U.t('too large an answer'))); }
47
50
  };
48
51
  xhr.onreadystatechange = function () {
49
52
  if (xhr.readyState !== 4 || done) { return; }
50
53
  done = true;
51
54
  var text = '' + (xhr.responseText || ''), data = null;
52
- if (text.length > MAX_BYTES) { reject(new Error('too large an answer')); return; }
55
+ if (text.length > max) { reject(new Error(U.t('too large an answer'))); return; }
53
56
  try { data = JSON.parse(text); } catch (e2) { data = null; }
54
57
  if (xhr.status >= 200 && xhr.status < 300 && data && data.result) { resolve(data.result); return; }
55
- reject(new Error((data && data.error && data.error.message) || ('HTTP ' + xhr.status)));
58
+ var err = new Error((data && data.error && data.error.message) || ('HTTP ' + xhr.status));
59
+ err.code = (data && data.error && typeof data.error.code === 'number') ? data.error.code : 0;
60
+ reject(err);
56
61
  };
57
- xhr.ontimeout = function () { if (!done) { done = true; reject(new Error('Stremio didn’t answer')); } };
58
- xhr.onerror = function () { if (!done) { done = true; reject(new Error('couldn’t reach Stremio')); } };
59
- try { xhr.send(JSON.stringify(body)); } catch (e3) { reject(new Error('couldn’t reach Stremio')); }
62
+ xhr.ontimeout = function () { if (!done) { done = true; reject(new Error(U.t('Stremio didn’t answer'))); } };
63
+ xhr.onerror = function () { if (!done) { done = true; reject(new Error(U.t('couldn’t reach Stremio'))); } };
64
+ try { xhr.send(JSON.stringify(body)); } catch (e3) { reject(new Error(U.t('couldn’t reach Stremio'))); }
60
65
  });
61
66
  }
62
67
  // The account's addons StremioK can use: [{ url, name, description }] (a link on the
@@ -75,5 +80,5 @@ var StremioAccount = (function () {
75
80
  // The key given up (Stremio's own sign-out): whatever happens, nothing is kept here.
76
81
  function signOut(key) { return call('logout', { type: 'Logout', authKey: key }).then(function () {}, function () {}); }
77
82
 
78
- return { start: start, wait: wait, addons: addons, signOut: signOut };
83
+ return { start: start, wait: wait, addons: addons, signOut: signOut, call: call };
79
84
  })();