stremiok 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/view-core.js CHANGED
@@ -827,6 +827,9 @@ var ViewParts = {};
827
827
  if (type === 'movie' || eps.length) {
828
828
  opts.push(['watched', watched ? 'Mark unwatched' : (type === 'series' ? 'Mark whole series watched' : 'Mark watched')]);
829
829
  }
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) ? 'Remove from Stremio Library' : 'Add to Stremio Library']); }
830
833
  // Rate on Trakt (connected, a title with an IMDb id): yours shown once rated
831
834
  var canRate = typeof Trakt !== 'undefined' && Trakt.isConnected() && Trakt.rate && /^tt\d+$/.test(m.id);
832
835
  var mine = canRate ? Trakt.myRating(type, m.id) : null;
@@ -834,6 +837,7 @@ var ViewParts = {};
834
837
  return { name: m.name || m.title || '', items: opts, run: function (v) {
835
838
  if (v === 'details') { App.openDetail(type, m.id, meta); }
836
839
  else if (v === 'np') { toggleNowPlaying(type, m); }
840
+ else if (v === 'lib') { toggleLibrary(type, m); }
837
841
  else if (v === 'watched') { setTitleWatched(type, m, !watched); }
838
842
  else if (v === 'rate') { rateOnTrakt(type, m.id, m.name || m.title || ''); }
839
843
  } };
@@ -910,6 +914,7 @@ var ViewParts = {};
910
914
  function nowPlayingEntries(type, id) {
911
915
  var all = Player.continueList();
912
916
  if (typeof Trakt !== 'undefined' && Trakt.isConnected && Trakt.isConnected() && Trakt.continueList) { all = all.concat(Trakt.continueList()); }
917
+ if (typeof StremioSync !== 'undefined' && StremioSync.isConnected()) { all = all.concat(StremioSync.continueList()); } // (your Stremio account's)
913
918
  return all.filter(function (e) {
914
919
  return e.type === type && (e.id === id || e.parent === id || (type === 'series' && ('' + e.id).split(':')[0] === id));
915
920
  });
@@ -918,8 +923,9 @@ var ViewParts = {};
918
923
  function toggleNowPlaying(type, m) {
919
924
  var present = nowPlayingEntries(type, m.id);
920
925
  if (present.length) {
921
- present.forEach(function (e) { // (Trakt's: hidden from Watching, as Watching's own Remove does)
922
- if (e._trakt) { if (Trakt.dismiss) { Trakt.dismiss(e.type, e.id); } } else { Player.removeProgress(e.type, e.id); }
926
+ present.forEach(function (e) { // (Trakt's: hidden from Watching, as Watching's own Remove does; your Stremio account's: off there too)
927
+ if (e._trakt) { if (Trakt.dismiss) { Trakt.dismiss(e.type, e.id); } } else if (!e._stremio) { Player.removeProgress(e.type, e.id); }
928
+ if (typeof StremioSync !== 'undefined' && StremioSync.dismiss) { StremioSync.dismiss(e.type, e.id); }
923
929
  });
924
930
  U.toast('Removed from Continue Watching');
925
931
  } else if (type === 'movie') {
@@ -936,6 +942,14 @@ var ViewParts = {};
936
942
  // adds and removes by: the id the title's details came with, which can differ from the
937
943
  // one it was opened by, e.g. a TMDB id in Discover for an IMDb one).
938
944
  function nowPlayingLabel(type, id) { return inNowPlaying(type, id) ? '✓ In Continue Watching' : '+ Add to Continue Watching'; }
945
+ // 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) ? '✓ In Stremio Library' : '+ 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 ? 'Added to your Stremio Library' : 'Removed from your Stremio Library');
951
+ }
952
+ function libraryOn() { return typeof StremioSync !== 'undefined' && StremioSync.isConnected(); }
939
953
 
940
954
  // "Hold OK for more": shown while the focused item has a menu of its own behind a held OK
941
955
  // (a card, a season, an episode, a source, a file on the USB drive…), so those menus can
@@ -974,4 +988,7 @@ var ViewParts = {};
974
988
  V.scr = scr;
975
989
  V.showModal = showModal;
976
990
  V.toggleNowPlaying = toggleNowPlaying;
991
+ V.libraryLabel = libraryLabel;
992
+ V.toggleLibrary = toggleLibrary;
993
+ V.libraryOn = libraryOn;
977
994
  })(ViewParts);
package/js/view-detail.js CHANGED
@@ -17,6 +17,13 @@
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;
26
+ }
20
27
  function trimMeta() { return V.trimMeta.apply(null, arguments); } // home
21
28
  function searchFor() { return V.searchFor.apply(null, arguments); } // search
22
29
 
@@ -860,6 +867,8 @@
860
867
  np.__onselect = function () { toggleNowPlaying('series', _d.meta); _d._focusNp = true; drawDetail(); };
861
868
  if (_d._focusNp) { _d._epFocus = np; _d._focusNp = false; }
862
869
  row.appendChild(np);
870
+ var lp = libraryPill('series', _d.meta.id || _d.id);
871
+ if (lp) { row.appendChild(lp); }
863
872
  var tp = trailerPill();
864
873
  if (tp) { row.appendChild(tp); }
865
874
  var mp = morePill();
@@ -1883,6 +1892,8 @@
1883
1892
  var np = U.el('div', 'pill focusable', nowPlayingLabel('movie', npId));
1884
1893
  np.__onselect = function () { toggleNowPlaying('movie', _d.meta); np.textContent = nowPlayingLabel('movie', npId); };
1885
1894
  row.appendChild(np);
1895
+ var mlp = libraryPill('movie', npId);
1896
+ if (mlp) { row.appendChild(mlp); }
1886
1897
  var tp = trailerPill();
1887
1898
  if (tp) { row.appendChild(tp); }
1888
1899
  var mp = morePill();
package/js/view-home.js CHANGED
@@ -1036,6 +1036,7 @@
1036
1036
  [e].concat(e._dupes || []).forEach(function (d) { // (the show's other episodes too)
1037
1037
  Player.removeProgress(d.type, d.id);
1038
1038
  if (typeof Trakt !== 'undefined' && Trakt.dismiss) { Trakt.dismiss(d.type, d.id); }
1039
+ if (typeof StremioSync !== 'undefined' && StremioSync.dismiss) { StremioSync.dismiss(d.type, d.id); } // (off your Stremio account's too)
1039
1040
  });
1040
1041
  }
1041
1042
  remove.__onselect = function () {
@@ -1066,8 +1067,10 @@
1066
1067
  showModal(overlay, details || watched);
1067
1068
  }
1068
1069
 
1069
- // Local progress merged with Trakt playback (when connected), deduped, newest first; a
1070
- // place kept here that Trakt has you watching past since (another TV) left out.
1070
+ // Local progress merged with Trakt playback and your Stremio account's Continue Watching (when
1071
+ // connected), deduped, newest first; a place kept here that Trakt or the account has you
1072
+ // watching past since (another device) left out. A title both here and in the account: its
1073
+ // place from whichever is newer (the stream to resume it, this TV's).
1071
1074
  // One card per show: its furthest episode (highest season, then episode), placed by
1072
1075
  // the show's most recent activity. The others ride along as _dupes so Remove clears
1073
1076
  // the whole show.
@@ -1076,6 +1079,17 @@
1076
1079
  function continueEntries(byActivity) {
1077
1080
  var local = Player.continueList(), traktOn = typeof Trakt !== 'undefined' && Trakt.isConnected();
1078
1081
  if (traktOn && Trakt.watchedPast) { local = local.filter(function (e) { return !Trakt.watchedPast(e); }); }
1082
+ var stremioOn = typeof StremioSync !== 'undefined' && StremioSync.isConnected();
1083
+ if (stremioOn) {
1084
+ local = local.filter(function (e) { return !StremioSync.watchedPast(e); });
1085
+ var here = {};
1086
+ local.forEach(function (e, i) { here[e.type + ':' + e.id] = i; });
1087
+ StremioSync.continueList().forEach(function (s) {
1088
+ var i = here[s.type + ':' + s.id];
1089
+ if (i === undefined) { return; }
1090
+ if ((s.updated || 0) > (local[i].updated || 0) && s.position) { local[i] = Object.assign({}, local[i], { position: s.position, duration: s.duration || local[i].duration, updated: s.updated }); }
1091
+ });
1092
+ }
1079
1093
  var merged = local.slice();
1080
1094
  if (traktOn) {
1081
1095
  var seen = {};
@@ -1085,6 +1099,14 @@
1085
1099
  if (!seen[k]) { seen[k] = 1; merged.push(e); }
1086
1100
  });
1087
1101
  }
1102
+ if (stremioOn) {
1103
+ var had = {};
1104
+ merged.forEach(function (e) { had[e.type + ':' + e.id] = 1; });
1105
+ StremioSync.continueList().forEach(function (e) {
1106
+ var k = e.type + ':' + e.id;
1107
+ if (!had[k]) { had[k] = 1; merged.push(e); }
1108
+ });
1109
+ }
1088
1110
  var list = onePerShow(merged); // (the most recent activity first)
1089
1111
  return byActivity ? list : inYourOrder(list);
1090
1112
  }
@@ -639,7 +639,8 @@
639
639
  var an = U.el('div', 'a-name', 'Import addons from your Stremio account');
640
640
  an.appendChild(originBadge('stremio'));
641
641
  acct.appendChild(an);
642
- acct.appendChild(U.el('div', 'a-url', 'Sign in on your phone with a QR code, then tick the addons to add (StremioK signs out straight after)'));
642
+ acct.appendChild(U.el('div', 'a-url', typeof StremioSync !== 'undefined' && StremioSync.isConnected() ? 'From the account connected in Integrations: tick the addons to add'
643
+ : 'Sign in on your phone with a QR code, then tick the addons to add (StremioK signs out straight after)'));
643
644
  acct.__onselect = stremioImport;
644
645
  wrap.appendChild(acct);
645
646
  }
@@ -667,11 +668,53 @@
667
668
  // Import addons from your Stremio account (js/stremio-account.js): a QR code of Stremio's
668
669
  // sign-in link, asked until you approve on your phone; then the account's addons to tick
669
670
  // (none ticked; yours already shown as such); the account signed out as soon as it's read.
671
+ // Connected (Settings › Integrations): its kept sign-in used, and kept.
670
672
  function stremioImport() {
673
+ if (typeof StremioSync !== 'undefined' && StremioSync.isConnected() && !StremioSync.connectStatus().reconnect) {
674
+ U.spinner(true);
675
+ StremioAccount.addons(StremioSync.authKey()).then(function (list) { U.spinner(false); importPick(list); }, function (e) {
676
+ U.spinner(false);
677
+ U.toast('Couldn’t import: ' + ((e && e.message) || 'unknown'), 5000);
678
+ });
679
+ return;
680
+ }
681
+ stremioSignIn('Import addons from your Stremio account', function (key, body, gone, fail) {
682
+ U.clear(body);
683
+ body.appendChild(U.el('div', 'tc-line', 'Reading your addons…'));
684
+ var read = StremioAccount.addons(key);
685
+ read.then(function () { StremioAccount.signOut(key); }, function () { StremioAccount.signOut(key); }); // (signed out as soon as it's read)
686
+ return read.then(function (list) {
687
+ if (gone()) { return; }
688
+ if (!list.length) { fail(new Error('your account has no addons StremioK can use')); return; }
689
+ closeModal();
690
+ importPick(list);
691
+ });
692
+ });
693
+ }
694
+ function importPick(list) {
695
+ if (!list.length) { U.toast('Your Stremio account has no addons StremioK can use', 5000); return; }
696
+ var mine = Stremio.getAddonUrls();
697
+ var items = list.map(function (x, i) {
698
+ var have = mine.indexOf(x.url) !== -1 || mine.indexOf(Stremio.normalizeUrl ? Stremio.normalizeUrl(x.url) : x.url) !== -1;
699
+ return { key: '' + i, label: x.name + ' · ' + shortHost(x.url), have: have };
700
+ });
701
+ pickMany('Your Stremio addons: tick the ones to add', items, { button: function (n) { return 'Import ' + n + ' addon' + (n === 1 ? '' : 's'); } }, function (keys) {
702
+ var n = 0, last = null;
703
+ keys.forEach(function (k) { var added = Stremio.addAddon(list[+k].url); if (added) { n++; last = added; if (Stremio.setAddonOrigin) { Stremio.setAddonOrigin(added, 'stremio'); } } });
704
+ clearCatalogCache();
705
+ refreshAddonRows(last);
706
+ U.toast('Imported ' + n + ' addon' + (n === 1 ? '' : 's'), 3000);
707
+ renderSettings();
708
+ });
709
+ }
710
+ // Stremio's sign-in box: a code and a QR code of its link, asked until it's approved on your
711
+ // phone; then signedIn(key, body, gone, fail) (gone(): the box closed meanwhile: the key is
712
+ // given up).
713
+ function stremioSignIn(title, signedIn) {
671
714
  var existing = document.querySelector('.modal-overlay');
672
715
  if (existing) { existing.parentNode.removeChild(existing); }
673
716
  var overlay = U.el('div', 'modal-overlay'), box = U.el('div', 'modal-box');
674
- box.appendChild(U.el('div', 'modal-msg', 'Import addons from your Stremio account'));
717
+ box.appendChild(U.el('div', 'modal-msg', title));
675
718
  var body = U.el('div', 'trakt-connect');
676
719
  body.appendChild(U.el('div', 'tc-line', 'Asking Stremio for a code…'));
677
720
  box.appendChild(body);
@@ -688,7 +731,7 @@
688
731
  function fail(e) {
689
732
  if (gone) { return; }
690
733
  U.clear(body);
691
- body.appendChild(U.el('div', 'tc-line', 'Couldn’t import: ' + ((e && e.message) || 'unknown')));
734
+ body.appendChild(U.el('div', 'tc-line', 'Couldn’t ' + (/^Import/.test(title) ? 'import' : 'connect') + ': ' + ((e && e.message) || 'unknown')));
692
735
  }
693
736
  StremioAccount.start().then(function (c) {
694
737
  if (gone) { return; }
@@ -710,28 +753,7 @@
710
753
  body.appendChild(U.el('div', 'tc-line small', 'Sign in to Stremio there and approve. Waiting…'));
711
754
  return StremioAccount.wait(c.code, stopped).then(function (key) {
712
755
  if (gone) { StremioAccount.signOut(key); return; }
713
- U.clear(body);
714
- body.appendChild(U.el('div', 'tc-line', 'Reading your addons…'));
715
- var read = StremioAccount.addons(key);
716
- read.then(function () { StremioAccount.signOut(key); }, function () { StremioAccount.signOut(key); }); // (signed out as soon as it's read)
717
- return read.then(function (list) {
718
- if (gone) { return; }
719
- if (!list.length) { fail(new Error('your account has no addons StremioK can use')); return; }
720
- var mine = Stremio.getAddonUrls();
721
- var items = list.map(function (x, i) {
722
- var have = mine.indexOf(x.url) !== -1 || mine.indexOf(Stremio.normalizeUrl ? Stremio.normalizeUrl(x.url) : x.url) !== -1;
723
- return { key: '' + i, label: x.name + ' · ' + shortHost(x.url), have: have };
724
- });
725
- closeModal();
726
- pickMany('Your Stremio addons: tick the ones to add', items, { button: function (n) { return 'Import ' + n + ' addon' + (n === 1 ? '' : 's'); } }, function (keys) {
727
- var n = 0, last = null;
728
- keys.forEach(function (k) { var added = Stremio.addAddon(list[+k].url); if (added) { n++; last = added; if (Stremio.setAddonOrigin) { Stremio.setAddonOrigin(added, 'stremio'); } } });
729
- clearCatalogCache();
730
- refreshAddonRows(last);
731
- U.toast('Imported ' + n + ' addon' + (n === 1 ? '' : 's'), 3000);
732
- renderSettings();
733
- });
734
- });
756
+ return signedIn(key, body, stopped, fail);
735
757
  });
736
758
  }).then(null, function (e) { if (!e || e.message !== 'stopped') { fail(e); } });
737
759
  }
@@ -1480,6 +1502,13 @@
1480
1502
  'Your watched marks and Continue Watching then sync with Trakt.'));
1481
1503
  }
1482
1504
 
1505
+ // Your Stremio account, kept in step (js/stremio-sync.js)
1506
+ if (typeof StremioSync !== 'undefined' && typeof StremioAccount !== 'undefined') {
1507
+ wrap.appendChild(U.el('h2', null, 'Stremio account'));
1508
+ wrap.appendChild(stremioAccountRow());
1509
+ wrap.appendChild(U.el('div', 'hint', 'Connect your Stremio account (sign in on your phone): its Continue Watching, watched marks and Library then sync with StremioK, both ways.'));
1510
+ }
1511
+
1483
1512
  wrap.appendChild(U.el('div', 'hint',
1484
1513
  'Keys are stored on this TV only. OMDb gives real IMDb per-episode ratings (used first when set); TMDB adds episode images & ratings.'));
1485
1514
  focusSettings();
@@ -1564,6 +1593,52 @@
1564
1593
  return r;
1565
1594
  }
1566
1595
 
1596
+ // Your Stremio account: connected (who, when it last synced, OK for Sync now / Disconnect), or
1597
+ // not (OK to connect: Stremio's sign-in code, as the addon import).
1598
+ function stremioAccountRow() {
1599
+ var st = StremioSync.connectStatus(), r = U.el('div', 'addon-item focusable cfg-row');
1600
+ function two(x) { return (x < 10 ? '0' : '') + x; }
1601
+ var d = st.lastSync ? new Date(st.lastSync) : null;
1602
+ var bits = [];
1603
+ if (st.connected) {
1604
+ bits.push(d ? 'Last synced ' + (U.dayLabel ? U.dayLabel(st.lastSync) + ' ' : '') + two(d.getHours()) + ':' + two(d.getMinutes()) : 'Not synced yet');
1605
+ if (st.pending) { bits.push(st.pending + ' change' + (st.pending === 1 ? '' : 's') + ' waiting'); }
1606
+ if (st.err) { bits.push('⚠ ' + st.err); }
1607
+ }
1608
+ r.appendChild(U.el('div', 'a-name', 'Stremio account' + (st.connected && st.user ? ': ' + st.user : '')));
1609
+ r.appendChild(U.el('div', 'a-url', st.connected && st.reconnect ? 'Its sign-in no longer works — press OK to connect again'
1610
+ : st.connected ? bits.join(' · ') + ' · OK for options' : 'Not connected — press OK to connect'));
1611
+ r.__onselect = function () {
1612
+ if (!st.connected || st.reconnect) { stremioConnect(); return; }
1613
+ pickList('Stremio account', [['now', 'Sync now'], ['off', 'Disconnect']], null, function (v) {
1614
+ if (v === 'now') { U.toast('Syncing with your Stremio account…'); StremioSync.sync().then(function () { markHomeDirty(); renderSettings(); }); }
1615
+ else if (v === 'off') {
1616
+ confirm('Disconnect your Stremio account?', 'Disconnect', function () {
1617
+ StremioSync.disconnect();
1618
+ U.toast('Stremio account disconnected');
1619
+ markHomeDirty();
1620
+ renderSettings();
1621
+ });
1622
+ }
1623
+ });
1624
+ };
1625
+ return r;
1626
+ }
1627
+ // Stremio's sign-in code (a QR code): approved on your phone, the key kept (StremioSync.connect).
1628
+ function stremioConnect() {
1629
+ stremioSignIn('Connect your Stremio account', function (key, body, gone) {
1630
+ U.clear(body);
1631
+ body.appendChild(U.el('div', 'tc-line', 'Connecting…'));
1632
+ return StremioSync.connect(key).then(function (user) {
1633
+ if (gone()) { return; }
1634
+ U.clear(body);
1635
+ body.appendChild(U.el('div', 'tc-line', '✓ Connected' + (user ? ' as ' + user : '') + ': syncing'));
1636
+ markHomeDirty();
1637
+ setTimeout(function () { if (isModalOpen()) { onModalClose(null); closeModal(); renderSettings(); } }, 1500);
1638
+ });
1639
+ });
1640
+ }
1641
+
1567
1642
  // Device-code connect overlay: shows the code + URL, polls, updates on success.
1568
1643
  function traktConnect() {
1569
1644
  var existing = document.querySelector('.modal-overlay');
@@ -2161,6 +2236,7 @@
2161
2236
  if (key === 'stremiok.homecache') { return { name: 'Home’s saved rows' }; }
2162
2237
  if (key === 'stremiok.trakt.watched') { return { name: 'Trakt watched history' }; }
2163
2238
  if (key === 'stremiok.media.watched') { return { name: 'Media servers’ watched marks' }; }
2239
+ if (key === 'stremiok.stremio.items') { return { name: 'Your Stremio account’s library' }; }
2164
2240
  if ((m = key.match(/^stremiok\.iptv\.cache\.(.+)$/))) {
2165
2241
  var p = (typeof IPTV !== 'undefined' ? IPTV.getPlaylists() : []).filter(function (x) { return x.id === m[1]; })[0];
2166
2242
  return p ? { name: 'IPTV playlist copy: ' + (p.name || (('' + p.url).match(/^[a-z]+:\/\/(?:[^\/@]*@)?([^\/?#:]+)/i) || [])[1] || 'a playlist') }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stremiok",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",
package/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.3'.slice(3), l = location, rest = (l.search || '') + (l.hash || '');
13
+ var v = '?v=2.3.4'.slice(3), l = location, rest = (l.search || '') + (l.hash || '');
14
14
  var m = /^(\/module\/npm%2F[^\/%@]+)\//i.exec(l.pathname || '');
15
15
  l.replace(m ? m[1] + '%40' + v + '/index.html' + rest : 'index.html' + rest);
16
16
  })();