stremiok 2.4.0 → 2.4.2

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/player-subs.js CHANGED
@@ -673,21 +673,31 @@
673
673
  return out;
674
674
  } catch (e) { return []; }
675
675
  }
676
- function textLang(tr) { return trackLang(tr); }
676
+ // A built-in track's language: the TV's, else the file's own for it (the 2017 TV states none
677
+ // for an MKV's subtitle tracks: P.fileTrack).
678
+ function textLang(tr) {
679
+ var l = trackLang(tr);
680
+ if (l && !P.langUnstated(l)) { return l; }
681
+ var tracks = getTextTracks(), i = -1;
682
+ for (var k = 0; k < tracks.length; k++) { if (tracks[k].index === tr.index) { i = k; break; } }
683
+ var own = i >= 0 && P.fileTrack ? P.fileTrack('subs', tracks, i) : null;
684
+ return own && own.lang ? own.lang : l;
685
+ }
677
686
 
678
687
  function wantEmbedded(w) { _embWant = w; if (_ticked) { applyEmbeddedWant(); } }
679
688
  function applyEmbeddedWant() {
680
689
  var w = _embWant; _embWant = null;
681
690
  if (!w || _subOn) { return; } // an addon track was chosen meanwhile
682
691
  var tracks = getTextTracks(), pick = null, key = w.lang ? langKey(w.lang) : '';
683
- // (of a language's tracks, by the file's header: a full one in text, then any in text — a
684
- // picture one, PGS, shows nothing here — then a forced one)
692
+ // (of a language's tracks, by the file's header: a plain one in text, then SDH, then a
693
+ // forced one — a picture one, PGS, shows nothing here, so last)
685
694
  var own = P.fileTracks ? P.fileTracks('subs', tracks) : null;
686
695
  function best(match) {
687
696
  var c = tracks.filter(match);
688
697
  if (!own || c.length < 2) { return c[0] || null; }
689
698
  var o = function (t) { return own[tracks.indexOf(t)] || {}; };
690
- return c.filter(function (t) { return o(t).text !== false && !o(t).forced; })[0] || c.filter(function (t) { return o(t).text !== false; })[0] || c[0];
699
+ var rank = function (t) { var f = o(t); return f.text === false ? 3 : f.forced ? 2 : f.hi ? 1 : 0; };
700
+ return c.slice().sort(function (x, y) { return rank(x) - rank(y) || c.indexOf(x) - c.indexOf(y); })[0];
691
701
  }
692
702
  if (w.index != null) {
693
703
  pick = tracks.find(function (t) { return t.index === w.index && (!key || langKey(textLang(t)) === key); }) || null;
@@ -936,7 +946,8 @@
936
946
  if (x.emb) {
937
947
  var tr = x.emb, l = textLang(tr), own = P.fileTrack ? P.fileTrack('subs', getTextTracks(), x.n) : null;
938
948
  if (_embSub === tr.index) { idx = i; }
939
- return { label: (S.ctx && S.ctx._relayCc ? U.t('Closed captions') : U.t('Built into the file')) + (l ? ' (' + l + ')' : ' · ' + U.t('track {n}', { n: x.n + 1 })), sel: _embSub === tr.index,
949
+ var named = l && !P.langUnstated(l) ? langName(langKey(l)) : ''; // ("English", as the audio list says it)
950
+ return { label: (S.ctx && S.ctx._relayCc ? U.t('Closed captions') : U.t('Built into the file')) + (named ? ' · ' + named : l ? ' (' + l + ')' : ' · ' + U.t('track {n}', { n: x.n + 1 })), sel: _embSub === tr.index,
940
951
  detail: own && P.fileTrackNote ? P.fileTrackNote(own) || undefined : undefined, // (its own name and marks, from the file's header)
941
952
  run: function () {
942
953
  _embDelay = 0; _embQueue = []; _embNudge = null; selectEmbeddedSub(tr); rememberSub(S.ctx.id, { embedded: true, index: tr.index, lang: l });
package/js/profiles.js CHANGED
@@ -38,6 +38,12 @@ var Profiles = (function () {
38
38
  try { var d = JSON.parse(window.localStorage.getItem(KEY) || 'null'); return valid(d) ? d : null; } catch (e) { return null; }
39
39
  }
40
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
+ }
41
47
  function active() {
42
48
  if (!_data) { return null; }
43
49
  for (var i = 0; i < _data.list.length; i++) { if (_data.list[i].id === _data.active) { return _data.list[i]; } }
@@ -102,9 +108,24 @@ var Profiles = (function () {
102
108
  }
103
109
  function rename(id, name) { var p = find(id); if (p && cleanName(name)) { p.name = cleanName(name); save(); } }
104
110
  function recolor(id, color) { var p = find(id); if (p && COLORS.indexOf(color) !== -1) { p.color = color; save(); } }
105
- function setAsk(on) { if (_data) { _data.ask = !!on; 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
+ }
106
119
  // The profile StremioK starts in next time (switching: then started again, see setActive's caller).
107
- function setActive(id) { if (find(id)) { _data.active = id; save(); } }
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
+ }
108
129
  // A profile's own keys in the settings storage: [physical key].
109
130
  function keysOf(slot) {
110
131
  var out = [];
@@ -139,6 +160,7 @@ var Profiles = (function () {
139
160
  keysOf(p.slot).forEach(function (k) { try { window.localStorage.removeItem(k); } catch (e) {} });
140
161
  if (bigRemove) { BIG.forEach(function (k) { bigRemove(keyFor(p.slot, 'stremiok.' + k)); }); }
141
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)
142
164
  save();
143
165
  return true;
144
166
  }
@@ -150,9 +172,10 @@ var Profiles = (function () {
150
172
  list: list,
151
173
  active: function () { var a = active(); return a ? { id: a.id, name: a.name, color: a.color, slot: a.slot } : null; },
152
174
  count: function () { return _data ? _data.list.length : 1; },
175
+ justSwitched: justSwitched,
153
176
  ask: function () { return !!(_data && _data.list.length > 1 && _data.ask !== false); },
154
177
  askSetting: function () { return !_data || _data.ask !== false; },
155
- ensure: function (firstName) { ensure(firstName); save(); }, add: add, rename: rename, recolor: recolor, setAsk: setAsk, setActive: setActive, remove: remove, copyInto: copyInto, keysOf: keysOf, COPY: COPY,
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,
156
179
  __data: function () { return _data; }, __reload: function () { _data = read(); _slot = (active() || { slot: '' }).slot; }
157
180
  };
158
181
  })();
package/js/view-core.js CHANGED
@@ -253,7 +253,7 @@ var ViewParts = {};
253
253
  try { if (typeof StremioSync !== 'undefined' && StremioSync.isConnected() && StremioSync.sync) { waits.push(StremioSync.sync()); } } catch (e2) {}
254
254
  try { if (typeof NuvioSync !== 'undefined' && NuvioSync.isConnected()) { waits.push(NuvioSync.sync()); } } catch (e4) {}
255
255
  var gone = false;
256
- function go() { if (gone) { return; } gone = true; Profiles.setActive(id); try { window.location.reload(); } catch (e3) {} }
256
+ function go() { if (gone) { return; } gone = true; Profiles.setActive(id, true); try { window.location.reload(); } catch (e3) {} }
257
257
  setTimeout(go, SWITCH_WAIT);
258
258
  Promise.all(waits.map(function (w) { return Promise.resolve(w).then(null, function () {}); })).then(go);
259
259
  }
package/js/view-home.js CHANGED
@@ -1083,8 +1083,17 @@
1083
1083
  // the whole show.
1084
1084
  // byActivity: the most recent activity first, whatever order you gave the row (Move): the
1085
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
+ }
1086
1095
  function continueEntries(byActivity) {
1087
- var local = Player.continueList(), traktOn = typeof Trakt !== 'undefined' && Trakt.isConnected();
1096
+ var local = Player.continueList().filter(sound), traktOn = typeof Trakt !== 'undefined' && Trakt.isConnected();
1088
1097
  if (traktOn && Trakt.watchedPast) { local = local.filter(function (e) { return !Trakt.watchedPast(e); }); }
1089
1098
  var stremioOn = typeof StremioSync !== 'undefined' && StremioSync.isConnected();
1090
1099
  if (stremioOn) {
@@ -1114,6 +1123,7 @@
1114
1123
  if (!had[k]) { had[k] = 1; merged.push(e); }
1115
1124
  });
1116
1125
  }
1126
+ merged = merged.filter(sound);
1117
1127
  var list = onePerShow(merged); // (the most recent activity first)
1118
1128
  return byActivity ? list : inYourOrder(list);
1119
1129
  }
@@ -562,11 +562,14 @@
562
562
  nv.__onselect = nuvioImport;
563
563
  wrap.appendChild(nv);
564
564
  }
565
- if (Profiles.count() > 1) {
566
- var askOn = Profiles.askSetting(), ask = U.el('div', 'addon-item focusable cfg-row');
567
- ask.appendChild(U.el('div', 'a-name', U.t('Ask who’s watching when StremioK opens:') + ' ' + (askOn ? U.t('On') : U.t('Off'))));
568
- ask.appendChild(U.el('div', 'a-url', askOn ? U.t('Each time it opens, before anything else') : U.t('It opens in the last profile used; switch from the top menu')));
569
- ask.__onselect = function () { Profiles.setAsk(!askOn); _focusChild = 'pf:ask'; renderSettings(); };
565
+ if (Profiles.count() > 1) { // When StremioK opens: ask, the last profile used, or one always
566
+ var startList = [['ask', U.t('Ask who’s watching')], ['last', U.t('The last profile used')]].concat(list.map(function (p) { return [p.id, U.t('Always “{name}”', { name: p.name })]; }));
567
+ var ask = U.el('div', 'addon-item focusable cfg-row'), choice = Profiles.startChoice();
568
+ ask.appendChild(U.el('div', 'a-name', U.t('When StremioK opens:') + ' ' + labelFor(startList, choice)));
569
+ ask.appendChild(U.el('div', 'a-url', choice === 'ask' ? U.t('Each time it opens, before anything else') : (choice === 'last' ? U.t('It opens in the last profile used; switch from the top menu') : U.t('It opens in that profile, whichever was used last; switch from the top menu'))));
570
+ ask.__onselect = function () {
571
+ pickList(U.t('When StremioK opens'), startList, choice, function (v) { Profiles.setStart(v); _focusChild = 'pf:ask'; renderSettings(); });
572
+ };
570
573
  if (_focusChild === 'pf:ask') { focus = ask; }
571
574
  wrap.appendChild(ask);
572
575
  }
@@ -2472,15 +2475,18 @@
2472
2475
  // (an HLS source through the service, with its own headers on every piece: see player-core's viaService)
2473
2476
  var HLS_ROUTES = [['off', U.t('Off')], ['headers', U.t('Sources that need headers')], ['all', U.t('All HLS sources')]];
2474
2477
  var FILE_INFOS = [['usb', U.t('USB drives only')], ['all', U.t('All files')], ['off', U.t('Off')]];
2478
+ // (an MKV's other subtitle tracks left out through the service: player-core's blankFits)
2479
+ var BLANKS = [['always', U.t('Always')], ['many', U.t('More than 5 subtitle tracks')], ['jump', U.t('After a jump (more than 5)')], ['never', U.t('Never')]];
2475
2480
  function settingsSeeking(wrap) {
2476
2481
  wrap.appendChild(U.el('h2', null, U.t('Seeking & buffering')));
2477
- var store = { get: function () { var c = Player.playerCfg(); return { seek: '' + c.seek, buffer: c.buffer, reconnect: c.reconnect, hls: c.hls, fileInfo: c.fileInfo }; },
2478
- set: function (cfg) { Player.setPlayerCfg({ seek: +cfg.seek || 10, buffer: cfg.buffer, reconnect: cfg.reconnect, hls: cfg.hls, fileInfo: cfg.fileInfo }); } };
2482
+ var store = { get: function () { var c = Player.playerCfg(); return { seek: '' + c.seek, buffer: c.buffer, reconnect: c.reconnect, hls: c.hls, fileInfo: c.fileInfo, blank: c.blank }; },
2483
+ set: function (cfg) { Player.setPlayerCfg({ seek: +cfg.seek || 10, buffer: cfg.buffer, reconnect: cfg.reconnect, hls: cfg.hls, fileInfo: cfg.fileInfo, blank: cfg.blank }); } };
2479
2484
  wrap.appendChild(subPickRow(U.t('Seek step'), [['5', '5 s'], ['10', '10 s'], ['15', '15 s'], ['30', '30 s']], 'seek', store));
2480
2485
  wrap.appendChild(subPickRow(U.t('Buffer'), [['normal', U.t('Normal (the TV’s own)')], ['more', U.t('More')], ['most', U.t('Most')]], 'buffer', store));
2481
2486
  wrap.appendChild(subPickRow(U.t('Reconnect live channels'), RECONNECTS, 'reconnect', store));
2482
2487
  wrap.appendChild(subPickRow(U.t('HLS through StremioK’s service'), HLS_ROUTES, 'hls', store));
2483
2488
  wrap.appendChild(subPickRow(U.t('Read the file’s details'), FILE_INFOS, 'fileInfo', store)); // (its codec, HDR, tracks and their names: player-core's fileInfoAsk)
2489
+ wrap.appendChild(subPickRow(U.t('Leave out other subtitle tracks'), BLANKS, 'blank', store));
2484
2490
  wrap.appendChild(U.el('div', 'hint', 'Seek step: FF / REW jump three. Buffer: More or Most starts slower but stops less on a slow connection. Reconnect: a live channel that drops opens again (BACK stops it). HLS through StremioK’s service: for a host that wants headers the TV’s player can’t send; a step more before it starts.'));
2485
2491
  focusSettings();
2486
2492
  }
package/js/ytplay.js CHANGED
@@ -112,10 +112,12 @@ var YTPlay = (function () {
112
112
  // A file (not HLS) through the service's file relay, with its headers and the player's byte
113
113
  // range: { url } the player opens. lan: redirects into the home network allowed
114
114
  // (Settings › Content › Addons › Local-network links from internet addons).
115
- function fileOpen(url, h, lan) {
115
+ // keep: an MKV's subtitle tracks to keep, by their place among its subtitle tracks; the others
116
+ // are blanked (the service's mkvBlanker); none: the file as it is.
117
+ function fileOpen(url, h, lan, keep) {
116
118
  if (MODE === 'browser') { return Promise.reject(new Error('no service')); }
117
119
  return ensureService().then(entryAuth).then(function (a) {
118
- return U.getJSON(PROXY + '/live/file?u=' + encodeURIComponent(url) + headerQuery(h) + (lan ? '&lan=1' : '') + a.q, 5000, 65536, null, a.h);
120
+ return U.getJSON(PROXY + '/live/file?u=' + encodeURIComponent(url) + headerQuery(h) + (lan ? '&lan=1' : '') + (keep ? '&blank=1&keep=' + keep.join(',') : '') + a.q, 5000, 65536, null, a.h);
119
121
  });
120
122
  }
121
123
  // What's in a source's file, from its header (the service's /live/mi: its container, codecs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stremiok",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",
package/service/index.js CHANGED
@@ -3325,7 +3325,7 @@ function plugControl(res, query, text, leaving) {
3325
3325
  // headers and its byte range (seeking works), the answer streamed back as it comes, nothing kept.
3326
3326
  // Shares the relays' count (LIVE_MAX); dropped after LIVE_FILM_IDLE_MS unused. Redirects: the
3327
3327
  // downloads' host rule (never the TV itself), and into the home network only when allowed (lan).
3328
- function liveFileSession(u, who, lan) {
3328
+ function liveFileSession(u, who, lan, keep) {
3329
3329
  var ids = Object.keys(_live);
3330
3330
  if (ids.length >= LIVE_MAX) {
3331
3331
  ids.sort(function (x, y) { return _live[x].last - _live[y].last; });
@@ -3333,10 +3333,202 @@ function liveFileSession(u, who, lan) {
3333
3333
  delete _live[ids[0]];
3334
3334
  }
3335
3335
  var s = { id: crypto.randomBytes(16).toString('hex'), file: u, ua: who.ua, ref: who.ref, cookie: who.cookie || '', origin: who.origin || '', accept: who.accept || '', lang: who.lang || '',
3336
- lan: !!lan, film: true, links: {}, last: Date.now() };
3336
+ lan: !!lan, film: true, links: {}, last: Date.now(), keep: keep || null };
3337
3337
  _live[s.id] = s;
3338
3338
  return s;
3339
3339
  }
3340
+
3341
+ // ---- An MKV's other subtitle tracks left out, as the file passes (blank: /live/file?blank=1) ----
3342
+ // The 2017 TV's player breaks after a forward jump in an MKV with dozens of subtitle tracks (the
3343
+ // picture stutters and loses frames; the same file with video and audio only plays clean), even
3344
+ // with subtitles off. So such a file can come through the relay with those tracks blanked: each
3345
+ // one's TrackEntry, each of its blocks (SimpleBlock or BlockGroup) and its Cues entries get the
3346
+ // one-byte ID of a Void element, which every reader skips. Nothing changes size: every offset
3347
+ // (Cues, SeekHead, cluster sizes, the player's byte ranges) stays the file's own. keep: the
3348
+ // subtitle tracks kept, by their place among the file's subtitle tracks (the app's choice: your
3349
+ // languages). The plan (blankPlan) is read once per session from the header and the Cues.
3350
+ var EBML_VOID = 0xEC, BLANK_BACK_MAX = 64 * 1048576, BLANK_HOLD_MAX = 262144;
3351
+ var MKV_TOP = { 0x1F43B675: 1, 0x1C53BB6B: 1, 0x1254C367: 1, 0x1043A770: 1, 0x1941A469: 1, 0x114D9B74: 1, 0x1549A966: 1, 0x1654AE6B: 1 };
3352
+ // cb(err, plan | null): { segData, firstCluster, clustersEnd, clusters: [abs], blank: { trackNo: 1 },
3353
+ // patches: [abs offsets of IDs made Void], subs, blanked }; null: nothing to blank (not an MKV,
3354
+ // too few subtitle tracks, or all kept).
3355
+ function blankPlan(s, cb) {
3356
+ cb = once(cb);
3357
+ var stops = [], r = miReader(miHttpReader(s.file, s, s.lan, stops)), I = MKV_IDS;
3358
+ var plan = { segData: 0, firstCluster: -1, clustersEnd: Infinity, clusters: [], blank: {}, patches: [], subs: 0, blanked: 0 };
3359
+ var seek = {}, steps = 0, keep = {};
3360
+ (s.keep || []).forEach(function (k) { keep[k] = 1; });
3361
+ var timer = setTimeout(function () { stops.forEach(function (f) { f(); }); cb(upError('timed out', 504)); }, MI_MS);
3362
+ function done(err, p) { clearTimeout(timer); cb(err, p); }
3363
+ r.get(0, 64, function (e, b) {
3364
+ var id = !e && ebmlId(b, 0), sz = id && ebmlSize(b, id.n);
3365
+ if (!sz || sz.v < 0 || id.v !== 0x1A45DFA3) { done(null, null); return; }
3366
+ var at = id.n + sz.n + sz.v;
3367
+ r.get(at, 16, function (e2, b2) {
3368
+ var sid = !e2 && ebmlId(b2, 0), ssz = sid && ebmlSize(b2, sid.n);
3369
+ if (!ssz || sid.v !== I.SEGMENT) { done(null, null); return; }
3370
+ plan.segData = at + sid.n + ssz.n;
3371
+ walk(plan.segData);
3372
+ });
3373
+ });
3374
+ // Each child of b[o..end) with its element's start: fn(id, start, dataStart, dataSize).
3375
+ function children(b, o, end, fn) {
3376
+ for (var n = 0; o < end && n < 65536; n++) {
3377
+ var id = ebmlId(b, o), sz = id && ebmlSize(b, o + id.n);
3378
+ if (!id || !sz) { return; }
3379
+ var d = o + id.n + sz.n, z = sz.v < 0 ? end - d : Math.min(sz.v, end - d);
3380
+ fn(id.v, o, d, z);
3381
+ o = d + z;
3382
+ }
3383
+ }
3384
+ function tracks(b, abs) { // abs: where b[0] is in the file
3385
+ var subs = 0;
3386
+ children(b, 0, b.length, function (id, st, d, z) {
3387
+ if (id !== 0xAE) { return; }
3388
+ var no = 0, type = 0;
3389
+ children(b, d, d + z, function (cid, cst, cd, cz) { if (cid === 0xD7) { no = ebmlUint(b, cd, cz); } else if (cid === 0x83) { type = ebmlUint(b, cd, cz); } });
3390
+ if (type !== 17 || !no) { return; }
3391
+ if (!keep[subs]) { plan.blank[no] = 1; plan.patches.push(abs + st); plan.blanked++; }
3392
+ subs++;
3393
+ });
3394
+ plan.subs = subs;
3395
+ }
3396
+ function cues(b, abs) {
3397
+ children(b, 0, b.length, function (id, st, d, z) {
3398
+ if (id !== 0xBB) { return; }
3399
+ children(b, d, d + z, function (cid, cst, cd, cz) {
3400
+ if (cid !== 0xB7) { return; }
3401
+ var tr = 0, pos = -1;
3402
+ children(b, cd, cd + cz, function (x, xs, xd, xz) { if (x === 0xF7) { tr = ebmlUint(b, xd, xz); } else if (x === 0xF1) { pos = ebmlUint(b, xd, xz); } });
3403
+ if (plan.blank[tr]) { plan.patches.push(abs + cst); }
3404
+ if (pos >= 0) { plan.clusters.push(plan.segData + pos); }
3405
+ });
3406
+ });
3407
+ }
3408
+ function element(at, then) {
3409
+ r.get(at, 16, function (e, b) {
3410
+ var id = !e && ebmlId(b, 0), sz = id && ebmlSize(b, id.n);
3411
+ if (!sz) { then(-1, 0, 0); return; }
3412
+ var d = at + id.n + sz.n;
3413
+ if (id.v === I.CLUSTER) { then(-1, id.v, d); return; }
3414
+ if (sz.v < 0) { then(-1, 0, 0); return; }
3415
+ if ((id.v === I.TRACKS || id.v === I.SEEKHEAD || id.v === I.CUES) && sz.v <= MI_ELEMENT_MAX) {
3416
+ r.get(d, sz.v, function (e2, body) {
3417
+ if (!e2) {
3418
+ if (id.v === I.TRACKS) { tracks(body, d); seek.gotTracks = true; }
3419
+ else if (id.v === I.CUES) { cues(body, d); seek.gotCues = true; }
3420
+ else if (!seek.head) {
3421
+ seek.head = true;
3422
+ children(body, 0, body.length, function (cid, st, cd, cz) {
3423
+ if (cid !== I.SEEK) { return; }
3424
+ var sid = 0, pos = -1;
3425
+ children(body, cd, cd + cz, function (x, xs, xd, xz) { if (x === I.SEEKID) { sid = ebmlUint(body, xd, xz); } else if (x === I.SEEKPOS) { pos = ebmlUint(body, xd, xz); } });
3426
+ if (pos < 0) { return; }
3427
+ if (sid === I.TRACKS) { seek.tracks = pos; } else if (sid === I.CUES) { seek.cues = pos; }
3428
+ else if (sid === 0x1254C367 || sid === 0x1043A770 || sid === 0x1941A469) { seek.after = Math.min(seek.after === undefined ? Infinity : seek.after, pos); }
3429
+ });
3430
+ }
3431
+ }
3432
+ then(d + sz.v, id.v, d);
3433
+ });
3434
+ return;
3435
+ }
3436
+ then(d + sz.v, id.v, d);
3437
+ });
3438
+ }
3439
+ function walk(at) {
3440
+ if (at < 0 || steps++ > 64 || (r.size() !== null && at >= r.size())) { finish(); return; }
3441
+ element(at, function (next, id) {
3442
+ if (id === I.CLUSTER) { plan.firstCluster = at; finish(); return; }
3443
+ walk(next);
3444
+ });
3445
+ }
3446
+ function finish() {
3447
+ if (plan.firstCluster < 0) { done(null, null); return; }
3448
+ if (!seek.gotTracks && seek.tracks >= 0) { var t = seek.tracks; seek.tracks = -1; element(plan.segData + t, function () { finish(); }); return; }
3449
+ if (!seek.gotTracks || !plan.blanked) { done(null, null); return; }
3450
+ if (!seek.gotCues && seek.cues >= 0) { var c = seek.cues; seek.cues = -1; element(plan.segData + c, function () { finish(); }); return; }
3451
+ var ends = [seek.cues >= 0 ? plan.segData + seek.cues : Infinity];
3452
+ if (seek.after !== undefined) { ends.push(plan.segData + seek.after); }
3453
+ ends.forEach(function (x) { if (x > plan.firstCluster && x < plan.clustersEnd) { plan.clustersEnd = x; } });
3454
+ if (seek.cuesAt > plan.firstCluster && seek.cuesAt < plan.clustersEnd) { plan.clustersEnd = seek.cuesAt; }
3455
+ plan.clusters.push(plan.firstCluster);
3456
+ plan.clusters = plan.clusters.filter(function (x) { return x >= plan.firstCluster && x < plan.clustersEnd; }).sort(function (a, b) { return a - b; });
3457
+ plan.patches.sort(function (a, b) { return a - b; });
3458
+ done(null, plan);
3459
+ }
3460
+ }
3461
+ // Where to start reading for a range from x: a cluster's start at or before it (the blocks are
3462
+ // read from there), else as asked (before the clusters, or past them: offsets only).
3463
+ function blankFrom(plan, x) {
3464
+ if (x < plan.firstCluster || x >= plan.clustersEnd) { return x; }
3465
+ var lo = 0, hi = plan.clusters.length - 1, best = plan.firstCluster;
3466
+ while (lo <= hi) { var mid = (lo + hi) >> 1; if (plan.clusters[mid] <= x) { best = plan.clusters[mid]; lo = mid + 1; } else { hi = mid - 1; } }
3467
+ return x - best > BLANK_BACK_MAX ? x : best;
3468
+ }
3469
+ // The bytes from start, blanked as they pass: { push(buf) -> Buffer, end() -> Buffer }, what's
3470
+ // returned following on from what came before. start: a cluster's start, or anywhere outside
3471
+ // the clusters (blankFrom); else only the offsets (TrackEntries, Cues) are blanked.
3472
+ function mkvBlanker(plan, start) {
3473
+ var pend = allocBuffer(0), base = start, mode, skipTo = 0, afterSkip = '', clusterEnd = Infinity, pi = 0, ended = false;
3474
+ while (pi < plan.patches.length && plan.patches[pi] < start) { pi++; }
3475
+ if (start < plan.firstCluster) { mode = 'skip'; skipTo = plan.firstCluster; afterSkip = 'seg'; }
3476
+ else if (start >= plan.clustersEnd || plan.clusters.indexOf(start) === -1) { mode = 'skip'; skipTo = Infinity; afterSkip = ''; }
3477
+ else { mode = 'seg'; }
3478
+ var out = [];
3479
+ function emit(n) {
3480
+ if (n <= 0) { return; }
3481
+ var piece = pend.slice(0, n);
3482
+ while (pi < plan.patches.length && plan.patches[pi] < base + n) { piece[plan.patches[pi] - base] = EBML_VOID; pi++; }
3483
+ out.push(piece);
3484
+ pend = pend.slice(n); base += n;
3485
+ }
3486
+ function giveUp() { mode = 'skip'; skipTo = Infinity; afterSkip = ''; }
3487
+ function step() { // true: went on; false: needs more bytes
3488
+ if (mode === 'skip') {
3489
+ var n = Math.min(skipTo - base, pend.length);
3490
+ emit(n);
3491
+ if (base >= skipTo && afterSkip) { mode = afterSkip; return true; }
3492
+ return false;
3493
+ }
3494
+ if (mode === 'clu' && base >= clusterEnd) { mode = 'seg'; }
3495
+ if (base >= plan.clustersEnd) { giveUp(); return true; }
3496
+ var id = ebmlId(pend, 0), sz = id && ebmlSize(pend, id.n);
3497
+ if (!id || !sz) {
3498
+ if (pend.length >= 12 || (ended && pend.length)) { giveUp(); return true; }
3499
+ return false;
3500
+ }
3501
+ var hdr = id.n + sz.n;
3502
+ if (mode === 'seg' || (clusterEnd === Infinity && MKV_TOP[id.v])) {
3503
+ if (id.v === MKV_IDS.CLUSTER) { clusterEnd = sz.v < 0 ? Infinity : base + hdr + sz.v; emit(hdr); mode = 'clu'; return true; }
3504
+ if (sz.v < 0) { giveUp(); return true; }
3505
+ mode = 'skip'; skipTo = base + hdr + sz.v; afterSkip = 'seg'; return true;
3506
+ }
3507
+ if (sz.v < 0) { giveUp(); return true; }
3508
+ var tn = -1;
3509
+ if (id.v === 0xA3) {
3510
+ var t = ebmlSize(pend, hdr);
3511
+ if (!t) { if (ended || pend.length > BLANK_HOLD_MAX) { tn = 0; } else { return false; } } else { tn = t.v; }
3512
+ } else if (id.v === 0xA0) {
3513
+ var o = hdr, gEnd = hdr + sz.v;
3514
+ while (o < gEnd) {
3515
+ var cid = ebmlId(pend, o), csz = cid && ebmlSize(pend, o + cid.n);
3516
+ if (!cid || !csz) { break; }
3517
+ if (cid.v === 0xA1) { var bt = ebmlSize(pend, o + cid.n + csz.n); if (bt) { tn = bt.v; } break; }
3518
+ if (csz.v < 0) { tn = 0; break; }
3519
+ o += cid.n + csz.n + csz.v;
3520
+ }
3521
+ if (tn < 0 && o < gEnd) { if (ended || pend.length > BLANK_HOLD_MAX) { tn = 0; } else { return false; } }
3522
+ }
3523
+ if (tn > 0 && plan.blank[tn]) { pend[0] = EBML_VOID; }
3524
+ mode = 'skip'; skipTo = base + hdr + sz.v; afterSkip = 'clu'; return true;
3525
+ }
3526
+ function run() { while (pend.length && step()) { /* on */ } }
3527
+ return {
3528
+ push: function (buf) { pend = pend.length ? Buffer.concat([pend, buf]) : buf; out = []; run(); return out.length === 1 ? out[0] : Buffer.concat(out); },
3529
+ end: function () { ended = true; out = []; run(); if (pend.length) { mode = 'skip'; skipTo = Infinity; emit(pend.length); } return Buffer.concat(out); }
3530
+ };
3531
+ }
3340
3532
  // A host in the home network (by its name or address): a private, link-local or carrier-grade
3341
3533
  // address, a name without a dot, or a .local / .lan / .home.arpa / .internal one.
3342
3534
  function isLanName(host) {
@@ -3355,8 +3547,24 @@ function isLanName(host) {
3355
3547
  // outside it, unless Local-network links from internet addons allows it.
3356
3548
  function fileHopOk(firstHost, nextHost, lan) { return lan || isLanName(firstHost) || !isLanName(nextHost); }
3357
3549
  function liveFile(s, req, res) {
3550
+ if (s.keep && s.plan === undefined) { // (blanking: the plan first, once; meanwhile the player's requests wait)
3551
+ if (s.planWait) { s.planWait.push(function () { liveFile(s, req, res); }); return; }
3552
+ s.planWait = [function () { liveFile(s, req, res); }];
3553
+ blankPlan(s, function (err, plan) {
3554
+ s.plan = err ? null : plan;
3555
+ if (err) { log('file relay: the subtitle tracks couldn\'t be read, the file as it is (' + err.message + ')'); }
3556
+ else if (plan) { log('file relay: ' + plan.blanked + ' of ' + plan.subs + ' subtitle tracks left out'); }
3557
+ var w = s.planWait; s.planWait = null;
3558
+ w.forEach(function (f) { f(); });
3559
+ });
3560
+ return;
3561
+ }
3358
3562
  var r = null, gone = false, hops = 0, firstHost = '';
3359
3563
  var range = /^bytes=\d*-\d*(,\s*\d*-\d*)*$/.test(String(req.headers.range || '')) ? String(req.headers.range) : '';
3564
+ // (blanked: one range, read from a cluster's start at or before it: blankFrom)
3565
+ var plan = s.plan || null, want = plan ? /^bytes=(\d*)-(\d*)$/.exec(range || 'bytes=0-') : null, x = 0, y = '';
3566
+ if (plan && (!want || want[1] === '')) { plan = null; }
3567
+ if (plan) { x = +want[1]; y = want[2]; range = 'bytes=' + blankFrom(plan, x) + '-' + y; }
3360
3568
  function stop() { gone = true; try { if (r) { r.abort(); } } catch (e) {} }
3361
3569
  res.on('close', stop);
3362
3570
  function fail(code, why) { if (gone) { return; } if (!res.headersSent) { send(res, code, 'text/plain', 'failed: ' + why); } else { try { res.end(); } catch (e) {} } stop(); }
@@ -3378,6 +3586,7 @@ function liveFile(s, req, res) {
3378
3586
  if (sc >= 300 && sc < 400 && resp.headers.location && hops < 5) { resp.resume(); hops++; get(urllib.resolve(url, resp.headers.location)); return; }
3379
3587
  if (sc !== 200 && sc !== 206) { resp.resume(); clearTimeout(timer); fail(sc >= 400 && sc < 600 ? sc : 502, 'HTTP ' + sc); return; }
3380
3588
  clearTimeout(timer);
3589
+ if (plan) { blanked(resp, sc); return; }
3381
3590
  var out = { 'Content-Type': String(resp.headers['content-type'] || 'application/octet-stream'), 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Accept-Ranges': 'bytes' };
3382
3591
  if (resp.headers['content-length']) { out['Content-Length'] = resp.headers['content-length']; }
3383
3592
  if (resp.headers['content-range']) { out['Content-Range'] = resp.headers['content-range']; }
@@ -3394,6 +3603,31 @@ function liveFile(s, req, res) {
3394
3603
  r.on('error', function (e) { clearTimeout(timer); fail(502, (e && e.message) || 'network error'); });
3395
3604
  } catch (e) { clearTimeout(timer); fail(400, 'bad link'); }
3396
3605
  }
3606
+ // The answer blanked (mkvBlanker) from where it starts, the player given its own range.
3607
+ function blanked(resp, sc) {
3608
+ var cr = /^bytes (\d+)-\d+\/(\d+)$/.exec(String(resp.headers['content-range'] || ''));
3609
+ var from = sc === 206 && cr ? +cr[1] : 0, total = cr ? +cr[2] : +(resp.headers['content-length'] || 0);
3610
+ if (from > x || !(total > 0)) { resp.resume(); fail(502, 'the host sent another part of the file'); return; }
3611
+ var last = y !== '' ? Math.min(+y, total - 1) : total - 1;
3612
+ var out = { 'Content-Type': String(resp.headers['content-type'] || 'application/octet-stream'), 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Accept-Ranges': 'bytes', 'Content-Length': String(last - x + 1) };
3613
+ if (req.headers.range) { out['Content-Range'] = 'bytes ' + x + '-' + last + '/' + total; }
3614
+ res.writeHead(req.headers.range ? 206 : 200, out);
3615
+ var bl = mkvBlanker(plan, from), at = from;
3616
+ function give(b) { // (what comes before x, read only to follow the blocks: not sent)
3617
+ var n = b.length;
3618
+ if (at + n <= x) { at += n; return true; }
3619
+ if (at < x) { b = b.slice(x - at); }
3620
+ at += n;
3621
+ return b.length ? res.write(b) : true;
3622
+ }
3623
+ resp.on('data', function (c) {
3624
+ if (gone) { return; }
3625
+ s.last = Date.now();
3626
+ if (!give(bl.push(c))) { resp.pause(); res.once('drain', function () { if (!gone) { resp.resume(); } }); }
3627
+ });
3628
+ resp.on('end', function () { if (!gone) { give(bl.end()); try { res.end(); } catch (e) {} } });
3629
+ resp.on('error', function () { fail(502, 'the host stopped sending'); });
3630
+ }
3397
3631
  get(s.file);
3398
3632
  }
3399
3633
  function liveHeader(v, max) { v = String(v || ''); return v.length <= (max || 300) && /^[\x20-\x7e]+$/.test(v) ? v : ''; }
@@ -3461,7 +3695,8 @@ function liveControl(req, res, path, query, leaving) {
3461
3695
  if (!entryAllowed(req, query)) { send(res, 403, 'text/plain', 'not allowed (token)'); return; }
3462
3696
  var fu = q.u || '';
3463
3697
  if (!/^https?:\/\/[^\s]+$/i.test(fu) || fu.length > 2000) { send(res, 400, 'text/plain', 'bad link'); return; }
3464
- var fsn = liveFileSession(fu, liveWho(q), q.lan === '1');
3698
+ var keep = q.blank === '1' ? String(q.keep || '').split(',').filter(function (k) { return /^\d{1,3}$/.test(k); }).map(Number).slice(0, 16) : null;
3699
+ var fsn = liveFileSession(fu, liveWho(q), q.lan === '1', keep);
3465
3700
  send(res, 200, 'application/json', JSON.stringify({ url: liveBase(fsn) + 'f' }));
3466
3701
  return;
3467
3702
  }
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.4.0'.slice(3), l = location, rest = (l.search || '') + (l.hash || '');
13
+ var v = '?v=2.4.2'.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
  })();