stremiok 2.4.1 → 2.4.3

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-core.js CHANGED
@@ -325,7 +325,12 @@ var PlayerParts = {};
325
325
  function renderOSD() {
326
326
  U.byId('osd-title').textContent = S.ctx ? S.ctx.name : '';
327
327
  var ck = U.byId('osd-clock'); // (the time of day, top right while the bar is on screen)
328
- if (ck) { ck.textContent = clock(Date.now() / 1000); }
328
+ if (ck) {
329
+ ck.textContent = clock(Date.now() / 1000);
330
+ // (under it, when what plays has a length: when it ends, at this pace — later while paused)
331
+ var left = !S.isLive && S.dur > 0 ? S.dur - S.cur : 0;
332
+ if (left > 30) { ck.appendChild(U.el('div', 'osd-ends', U.t('Ends {time}', { time: clock(Date.now() / 1000 + left) }))); }
333
+ }
329
334
  renderTags();
330
335
  renderChapters();
331
336
  if (S.isLive) {
@@ -435,12 +440,13 @@ var PlayerParts = {};
435
440
  // S.mi: the answer for what's playing, else null (not asked yet, not read, or not a file:
436
441
  // HLS, DASH, YouTube, a live channel, a trailer).
437
442
  var MI_KEEP = 40, _miSeen = U.lru(MI_KEEP), _miLook = null;
438
- function fileInfoAsk(ctx) {
443
+ function fileInfoAsk(ctx, force) {
439
444
  if (!ctx || ctx.yt || ctx.trailer || S.isLive) { return null; }
440
445
  // (Settings › Playback › Seeking & buffering › Read the file's details: a USB drive's only
441
- // unless All files — the others are more requests to their server as playback starts)
446
+ // unless All files — the others are more requests to their server as playback starts;
447
+ // force: asked whatever it says, for a jump in an MKV, see blankFirst)
442
448
  var want = P.playerCfg().fileInfo;
443
- if (want === 'off' || (want !== 'all' && !(ctx.localFile && !ctx.localFile.dav))) { return null; }
449
+ if (!force && (want === 'off' || (want !== 'all' && !(ctx.localFile && !ctx.localFile.dav)))) { return null; }
444
450
  var url = '' + (ctx.url || ''), size = ctx.stream && ctx.stream.behaviorHints ? +ctx.stream.behaviorHints.videoSize || 0 : 0;
445
451
  if (ctx.localFile) {
446
452
  if (typeof LocalMedia === 'undefined' || !LocalMedia.fileInfo) { return null; }
@@ -460,11 +466,13 @@ var PlayerParts = {};
460
466
  var known = _miSeen.get(job.key);
461
467
  if (known) { fileInfoIn(ctx, known); return; }
462
468
  var look = _miLook = U.cancelToken();
469
+ // (meanwhile a built-in subtitle pick waits for it when the TV states no language: P.miPending)
470
+ function over() { if (_miLook === look) { _miLook = null; } if (P.subsMiIn && S.ctx === ctx && S.active) { P.subsMiIn(); } }
463
471
  job.ask(look).then(function (mi) {
464
- if (look.cancelled || !mi || typeof mi !== 'object' || !mi.container) { return; }
465
- _miSeen.set(job.key, mi);
466
- if (S.ctx === ctx && S.active) { fileInfoIn(ctx, mi); }
467
- }, function (e) { if (!look.cancelled) { U.log('player', 'The file\'s details couldn\'t be read: ' + ((e && e.message) || 'unknown')); } });
472
+ if (look.cancelled) { return; }
473
+ if (mi && typeof mi === 'object' && mi.container) { _miSeen.set(job.key, mi); if (S.ctx === ctx && S.active) { S.mi = mi; fileInfoIn(ctx, mi); } }
474
+ over();
475
+ }, function (e) { if (!look.cancelled) { U.log('player', 'The file\'s details couldn\'t be read: ' + ((e && e.message) || 'unknown')); over(); } });
468
476
  }
469
477
  // The answer in: S.mi, and the source's details corrected by it (Stremio.withFileInfo): what
470
478
  // the player shows (its tags, Stream info) and what Formats learns from it are the file's.
@@ -481,6 +489,7 @@ var PlayerParts = {};
481
489
  var what = P.fileSummary(S.mi);
482
490
  return what ? U.t('This TV didn’t play this file: {what}', { what: what }) : why;
483
491
  }
492
+ P.miPending = function () { return !!_miLook && !_miLook.cancelled && !S.mi; };
484
493
  P.fileInfoFor = function (ctx) { var j = fileInfoAsk(ctx); return j ? _miSeen.get(j.key) || null : null; };
485
494
 
486
495
  function play(ctx, onExit) {
@@ -531,10 +540,12 @@ var PlayerParts = {};
531
540
 
532
541
  engineFor(ctx); // (the TV's player, or a ClearKey channel's own: see startShaka)
533
542
  // (a TorrServer torrent that doesn't say which of its files: its file list asked for first)
534
- var go = function () {
543
+ var go = function () { blankBefore(ctx, function () {
544
+ var bj = !ctx._blank && fileInfoAsk(ctx, true), bmi = bj && _miSeen.get(bj.key); // (its tracks known: see blankFits)
545
+ if (bmi && blankFits(ctx, bmi)) { setBlank(ctx, bmi); }
535
546
  if (fileViaService(ctx)) { startFileRelay(ctx, settle); return; }
536
547
  if (useAV) { startLive(ctx, settle); } else { startHTML5(ctx.url); }
537
- };
548
+ }); };
538
549
  // (a network folder's file that plays through the service — Digest sign-in: its ticket
539
550
  // first, LocalMedia.prepare; asked or not, it then plays)
540
551
  var prep = ctx.localFile && typeof LocalMedia !== 'undefined' && LocalMedia.prepare ? LocalMedia.prepare(ctx.url) : null;
@@ -1274,7 +1285,7 @@ var PlayerParts = {};
1274
1285
  if (useAV) {
1275
1286
  // Don't seek while buffering — queue it until buffering completes.
1276
1287
  if (S.buffering) { S.pendingSeek = target; U.spinner(true); return; }
1277
- doAVSeek(target, 0);
1288
+ if (!blankFirst(target)) { doAVSeek(target, 0); }
1278
1289
  } else {
1279
1290
  try { S.videoEl.currentTime = target; } catch (e2) {}
1280
1291
  }
@@ -1295,6 +1306,102 @@ var PlayerParts = {};
1295
1306
 
1296
1307
  function seekBy(delta) { seekTo(S.cur + delta); }
1297
1308
 
1309
+ // ---------- an MKV with dozens of subtitle tracks ----------
1310
+ // The 2017 TV's player breaks after a forward jump in one (the picture stutters and loses
1311
+ // frames, subtitles on or off), and plays the same file clean with only its video and audio.
1312
+ // So such a file plays through the service's file relay with its other subtitle tracks blanked
1313
+ // (the service's mkvBlanker: nothing moves, seeking stays the file's). When (Settings ›
1314
+ // Playback › Seeking & buffering › Leave out other subtitle tracks): Always, or with more than
1315
+ // BLANK_MIN, from the start (its tracks read first, BLANK_ASK_MS at most); After a jump (the
1316
+ // default: more than BLANK_MIN, from the first jump, which reads them and reopens there);
1317
+ // Never. A file whose tracks are known plays through it from the start in the first three.
1318
+ // Kept: your subtitle languages' tracks (a choice made for the title first), BLANK_KEEP at
1319
+ // most. Not USB files, network folders, YouTube, DRM or live.
1320
+ var BLANK_MIN = 5, BLANK_KEEP = 4, BLANK_ASK_MS = 6000, _blankAsk = null;
1321
+ function blankKeep(ctx, mi) {
1322
+ var cfg = P.getSubCfg(), mine = P.recallSub ? P.recallSub(ctx.id) : null;
1323
+ var keys = [mine && mine.lang, cfg.lang, cfg.lang2].filter(function (l) { return l && l !== 'off' && l !== 'none'; }).map(P.langKey);
1324
+ // (in the order wanted: the service puts them first in that order, so the TV's first text
1325
+ // track is yours. A language's: plain, then SDH, then forced, then pictures)
1326
+ var keep = [], subs = mi.subs || [];
1327
+ var rank = function (t) { return t.text === false ? 3 : t.forced ? 2 : t.hi ? 1 : 0; };
1328
+ keys.forEach(function (k) {
1329
+ subs.map(function (t, i) { return i; }).filter(function (i) { return keep.indexOf(i) === -1 && P.langMatches(k, subs[i].lang || ''); })
1330
+ .sort(function (a, b) { return rank(subs[a]) - rank(subs[b]) || a - b; })
1331
+ .forEach(function (i) { if (keep.length < BLANK_KEEP) { keep.push(i); } });
1332
+ });
1333
+ return keep;
1334
+ }
1335
+ function blankFits(ctx, mi) {
1336
+ var mode = P.playerCfg().blank;
1337
+ if (mode === 'never' || !useAV || !ctx || !mi || mi.container !== 'mkv' || !mi.subs || mi.subs.length <= (mode === 'always' ? 0 : BLANK_MIN)) { return false; }
1338
+ if (ctx.localFile || ctx.yt || ctx.trailer || S.isLive || (ctx.stream && ctx.stream._drm)) { return false; }
1339
+ var url = ctx.url || '';
1340
+ if (!/^https?:\/\//i.test(url) || /^http:\/\/(localhost|127\.0\.0\.1)[:\/]/i.test(url)) { return false; }
1341
+ if (blankKeep(ctx, mi).length >= mi.subs.length) { return false; } // (every one kept: nothing to leave out)
1342
+ return typeof YTPlay !== 'undefined' && !!YTPlay.fileOpen && YTPlay.installMode() !== 'browser';
1343
+ }
1344
+ // The audio tracks in the order wanted (a choice made for the title, your language, your second
1345
+ // choice; commentaries last): the service puts them so, the first is the one the TV starts on.
1346
+ function audioOrder(ctx, mi) {
1347
+ var cfg = P.getAudioCfg ? P.getAudioCfg() : {}, mine = P.recallAudio ? P.recallAudio(ctx.id) : null, aud = mi.audio || [];
1348
+ var keys = [mine && mine.lang, cfg.lang, cfg.lang2].filter(function (l) { return l && l !== 'default' && l !== 'none'; }).map(P.langKey);
1349
+ var out = [];
1350
+ keys.forEach(function (k) {
1351
+ aud.forEach(function (t, i) { if (out.indexOf(i) === -1 && !t.commentary && P.langMatches(k, t.lang || '')) { out.push(i); } });
1352
+ });
1353
+ return out;
1354
+ }
1355
+ function setBlank(ctx, mi) { ctx._blank = blankKeep(ctx, mi); ctx._blankOf = mi.subs.length; ctx._audioOrder = audioOrder(ctx, mi); }
1356
+ // Always / More than 5: an MKV's tracks read before it starts (when not known yet); then(): on.
1357
+ function blankBefore(ctx, then) {
1358
+ var mode = P.playerCfg().blank;
1359
+ if ((mode !== 'always' && mode !== 'many') || ctx._blank || ctx._blankChecked || !useAV || !maybeMkv(ctx)) { then(); return; }
1360
+ var job = fileInfoAsk(ctx, true);
1361
+ if (!job || _miSeen.get(job.key)) { then(); return; }
1362
+ ctx._blankChecked = true;
1363
+ var done = false, look = U.cancelToken();
1364
+ function on(m) { if (done) { return; } done = true; if (m && m.container) { _miSeen.set(job.key, m); } if (S.ctx === ctx && S.active) { then(); } }
1365
+ job.ask(look).then(on, function () { on(null); });
1366
+ setTimeout(function () { look.cancel(); on(null); }, BLANK_ASK_MS);
1367
+ }
1368
+ function maybeMkv(ctx) {
1369
+ var bh = (ctx.stream && ctx.stream.behaviorHints) || {};
1370
+ return /\.mkv(?:[?#]|$)/i.test(ctx.url || '') || /\.mkv$/i.test(bh.filename || '') || !!(ctx.formatInfo && /mkv/i.test(ctx.formatInfo.container || '')) || !!(S.mi && S.mi.container === 'mkv');
1371
+ }
1372
+ // A jump: true when it's taken care of here (reopened through the relay, or once its tracks
1373
+ // are read); false: seek as usual. Asked once a playback.
1374
+ function blankFirst(target) {
1375
+ var ctx = S.ctx;
1376
+ if (!ctx || ctx._blank || ctx._blankChecked || P.playerCfg().blank === 'never' || !maybeMkv(ctx)) { return false; }
1377
+ if (_blankAsk) { _blankAsk.target = target; return true; }
1378
+ var job = fileInfoAsk(ctx, true), mi = S.mi || (job && _miSeen.get(job.key)) || null;
1379
+ if (mi || !job) { ctx._blankChecked = true; if (mi && blankFits(ctx, mi)) { reopenBlank(ctx, mi, target); return true; } return false; }
1380
+ var ask = _blankAsk = { target: target, done: false }, tok = _playToken, look = U.cancelToken();
1381
+ U.spinner(true);
1382
+ function finish(m) {
1383
+ if (ask.done) { return; }
1384
+ ask.done = true; _blankAsk = null; ctx._blankChecked = true;
1385
+ if (!S.active || S.ctx !== ctx || tok !== _playToken) { return; }
1386
+ if (m && blankFits(ctx, m)) { reopenBlank(ctx, m, ask.target); return; }
1387
+ U.spinner(false); doAVSeek(ask.target, 0);
1388
+ }
1389
+ job.ask(look).then(function (m) {
1390
+ if (m && typeof m === 'object' && m.container) { _miSeen.set(job.key, m); if (!S.mi && S.ctx === ctx) { fileInfoIn(ctx, m); } finish(m); } else { finish(null); }
1391
+ }, function () { finish(null); });
1392
+ setTimeout(function () { look.cancel(); finish(null); }, BLANK_ASK_MS);
1393
+ return true;
1394
+ }
1395
+ function reopenBlank(ctx, mi, target) {
1396
+ setBlank(ctx, mi);
1397
+ ctx._relay = null; ctx._relayFor = null;
1398
+ ctx.resumeSec = Math.floor(target); S.cur = target;
1399
+ _stall.t = -1; _stall.since = 0; _stall.bufSince = 0;
1400
+ clearStartNote();
1401
+ U.spinner(true);
1402
+ startFileRelay(ctx, false);
1403
+ }
1404
+
1298
1405
  // ---------- jumps ahead on its own ----------
1299
1406
  // At normal speed, play time can't move ahead faster than the clock. After pauses, this
1300
1407
  // TV's player sometimes jumps forward at the next buffering, to where it would be had it
@@ -1569,7 +1676,7 @@ var PlayerParts = {};
1569
1676
  var url = ctx.url || '';
1570
1677
  if (!/^https?:\/\//i.test(url) || /^http:\/\/(localhost|127\.0\.0\.1)[:\/]/i.test(url)) { return false; }
1571
1678
  if (HLS_LINK.test(url) || (ctx.formatInfo && ctx.formatInfo.container === 'hls') || /\.mpd(?:[?#]|$)/i.test(url)) { return false; }
1572
- if (ctx.viaService) { return true; }
1679
+ if (ctx.viaService || ctx._blank) { return true; } // (its other subtitle tracks blanked: blankFits)
1573
1680
  var h = U.sanitizeHeaders(ctx._headers);
1574
1681
  return !!h && (!useAV || !!(h.origin || h.accept || h.lang));
1575
1682
  }
@@ -1579,8 +1686,10 @@ var PlayerParts = {};
1579
1686
  if (S.ctx !== ctx || !S.active) { return; }
1580
1687
  if (useAV) { startLive(ctx, settle); } else { startHTML5(ctx._relay && ctx._relayFor === ctx.url ? ctx._relay : ctx.url); }
1581
1688
  }
1582
- YTPlay.fileOpen(ctx.url, U.sanitizeHeaders(ctx._headers), lan).then(function (r) {
1583
- if (S.ctx === ctx && S.active && relayed(ctx, r, null, false)) { U.log('player', 'Through StremioK\'s service, with the source\'s headers (' + where(ctx.url) + ')'); }
1689
+ YTPlay.fileOpen(ctx.url, U.sanitizeHeaders(ctx._headers), lan, ctx._blank || null, ctx._blank ? ctx._audioOrder : null).then(function (r) {
1690
+ if (S.ctx === ctx && S.active && relayed(ctx, r, null, false)) {
1691
+ U.log('player', ctx._blank ? 'Through StremioK\'s service: ' + ctx._blankOf + ' subtitle tracks, ' + ctx._blank.length + ' kept, the others left out (jumps stay clean; ' + where(ctx.url) + ')' : 'Through StremioK\'s service, with the source\'s headers (' + where(ctx.url) + ')');
1692
+ }
1584
1693
  go();
1585
1694
  }, go);
1586
1695
  }
package/js/player-lang.js CHANGED
@@ -34,7 +34,7 @@
34
34
  fre: ['fre', 'fra', 'fr', 'french', 'français', 'francais'],
35
35
  ger: ['ger', 'deu', 'de', 'german', 'deutsch'],
36
36
  ita: ['ita', 'it', 'italian', 'italiano'],
37
- por: ['por', 'pob', 'pom', 'pt', 'portuguese', 'português', 'portugues'],
37
+ por: ['por', 'pob', 'pom', 'pt', 'po', 'portuguese', 'português', 'portugues'], // ("po": the 2017 TV's)
38
38
  dut: ['dut', 'nld', 'nl', 'dutch', 'nederlands'],
39
39
  rus: ['rus', 'ru', 'russian'],
40
40
  ara: ['ara', 'ar', 'arabic'],
@@ -178,17 +178,65 @@
178
178
  }
179
179
 
180
180
  // The file's own track (its header's, S.mi: see player-core's startFileInfo) for each of the
181
- // TV player's tracks of a kind ('audio' | 'subs'): by position, when the header lists as many
182
- // and every language it states agrees with the player's; else null (an odd file: the player's
183
- // list as it is).
181
+ // TV player's tracks of a kind ('audio' | 'subs'), in the TV's order; else null (the player's
182
+ // list as it is). As many in both, every language either states agreeing: by position. The
183
+ // file listing more (the TV leaves some out, often picture subtitles): its text ones only, if
184
+ // that makes as many; else matched in order by language, each of the TV's tracks to the next
185
+ // of the file's in its language (every one stating one). Not matched: said once in
186
+ // Diagnostics › Logs, with how many each lists.
187
+ function agrees(tr, ft) {
188
+ var tv = langKey(trackLang(tr)), fl = langKey(ft.lang || '');
189
+ if (!tv || !fl || P.langUnstated(tv) || P.langUnstated(fl)) { return null; } // (one says nothing)
190
+ return tv === fl || langKey(('' + ft.lang).split('-')[0]) === tv;
191
+ }
192
+ function byPosition(list, tracks) {
193
+ if (list.length !== tracks.length) { return null; }
194
+ for (var i = 0; i < list.length; i++) { if (agrees(tracks[i], list[i]) === false) { return null; } }
195
+ return list;
196
+ }
197
+ function inOrder(list, tracks) {
198
+ var out = [], j = 0;
199
+ for (var i = 0; i < tracks.length; i++) {
200
+ while (j < list.length && agrees(tracks[i], list[j]) !== true) {
201
+ if (agrees(tracks[i], list[j]) === null) { return null; } // (a language unstated: too unsure)
202
+ j++;
203
+ }
204
+ if (j >= list.length) { return null; }
205
+ out.push(list[j++]);
206
+ }
207
+ return out;
208
+ }
209
+ // The 2017 TV with an MKV's many subtitle tracks: it lists the first 30 only (32 tracks in all),
210
+ // states no language for any, and numbers them in the file's order, on from its video and audio
211
+ // (2, 3, 4…). Those: the file's first ones, in order. Anything else stays unmatched.
212
+ function firstOnes(list, tracks) {
213
+ var mi = P.S.mi, before = (mi && mi.video ? 1 : 0) + ((mi && mi.audio) || []).length;
214
+ for (var i = 0; i < tracks.length; i++) {
215
+ if (agrees(tracks[i], list[i]) !== null || +tracks[i].index !== before + i) { return null; }
216
+ }
217
+ return list.slice(0, tracks.length);
218
+ }
219
+ var _ftMemo = { mi: null, said: {} };
184
220
  function fileTracks(kind, tracks) {
185
221
  var list = P.S.mi && P.S.mi[kind];
186
- if (!list || !tracks || list.length !== tracks.length || !list.length) { return null; }
187
- for (var i = 0; i < list.length; i++) {
188
- var tv = langKey(trackLang(tracks[i])), fl = langKey(list[i].lang || '');
189
- if (tv && fl && !P.langUnstated(tv) && !P.langUnstated(fl) && tv !== fl && langKey(('' + list[i].lang).split('-')[0]) !== tv) { return null; }
222
+ if (!list || !tracks || !list.length || !tracks.length) { return null; }
223
+ var bl = kind === 'subs' && P.S.ctx && P.S.ctx._relay && P.S.ctx._blank; // (the others blanked by the service: the kept ones, in order)
224
+ if (bl) { list = bl.map(function (i) { return list[i]; }).filter(Boolean); } // (in the order the service put them in)
225
+ var ao = kind === 'audio' && P.S.ctx && P.S.ctx._relay && P.S.ctx._blank && P.S.ctx._audioOrder; // (the audio reordered by the service too: yours first)
226
+ if (ao && ao.length) { var all = list; list = ao.map(function (i) { return all[i]; }).filter(Boolean).concat(all.filter(function (t, i) { return ao.indexOf(i) === -1; })); }
227
+ var got = byPosition(list, tracks);
228
+ if (!got && list.length > tracks.length) {
229
+ got = byPosition(list.filter(function (t) { return t.text !== false; }), tracks) || inOrder(list, tracks) || firstOnes(list, tracks);
190
230
  }
191
- return list;
231
+ if (!got) {
232
+ if (_ftMemo.mi !== P.S.mi) { _ftMemo = { mi: P.S.mi, said: {} }; }
233
+ if (!_ftMemo.said[kind]) {
234
+ _ftMemo.said[kind] = 1;
235
+ U.log('player', (kind === 'audio' ? 'Audio' : 'Subtitle') + ' tracks: the TV lists ' + tracks.length + ', the file ' + list.length + ' (' +
236
+ tracks.map(function (t) { return trackLang(t) || '?'; }).join(' ') + ' / ' + list.map(function (t) { return t.lang || '?'; }).join(' ') + '): not matched, the TV\'s names shown');
237
+ }
238
+ }
239
+ return got;
192
240
  }
193
241
  function fileTrack(kind, tracks, pos) { var l = fileTracks(kind, tracks); return l ? l[pos] || null : null; }
194
242
  P.fileTracks = fileTracks; P.fileTrack = fileTrack;
@@ -270,7 +270,9 @@
270
270
  // (the file's details read from its start: player-core's fileInfoAsk. A USB drive's by
271
271
  // default, read off the drive itself; a link's or a network folder's are more requests
272
272
  // as it starts, so only when chosen)
273
- fileInfo: d.fileInfo === 'all' || d.fileInfo === 'off' ? d.fileInfo : 'usb' };
273
+ fileInfo: d.fileInfo === 'all' || d.fileInfo === 'off' ? d.fileInfo : 'usb',
274
+ // (an MKV's other subtitle tracks left out through the service: player-core's blankFits)
275
+ blank: d.blank === 'always' || d.blank === 'many' || d.blank === 'never' ? d.blank : 'jump' };
274
276
  }
275
277
  function setPlayerCfg(cfg) { // (what's given changes; the rest stays)
276
278
  var d = U.store.get(PLAYERCFG_KEY, {}) || {};
package/js/player-subs.js CHANGED
@@ -90,8 +90,13 @@
90
90
  ? LocalMedia.ensure().then(function () { return LocalMedia.ready(); }).then(function () { return LocalMedia.subsForTitle(ctx.type, ctx.id); }).then(null, function () { return []; })
91
91
  : Promise.resolve([]);
92
92
  if (localSubs.length) { localReady.then(function () { early = pickSubs(localSubs, true); }); }
93
+ // (your default language built into the file: on as soon as it plays, not after the addons)
94
+ var cfg0 = getSubCfg();
95
+ if (!recallSub(ctx.id) && cfg0.lang && cfg0.lang !== 'off' && P.useAV) { wantEmbedded({ lang: cfg0.lang, early: true }); }
93
96
  Promise.all([fromAddons, fromYouTube, localReady, usbSubs]).then(function (r) {
94
- var all = localSubs.concat(ctx.sourceSubs || [], r[0] || [], r[1], r[3] || []); // (a source's own: made for its file, so first after a USB file's)
97
+ // (in the order they're picked in: a source's own, made for its file, then the addons' in
98
+ // their order, then a USB drive's, then YouTube's; built-in tracks before all: applyEmbeddedWant)
99
+ var all = (ctx.sourceSubs || []).concat(r[0] || [], localSubs, r[3] || [], r[1] || []);
95
100
  if (!S.active || S.ctx !== ctx) { return; } // (another playback started meanwhile: not its tracks)
96
101
  if (early || _subOn || _embSub != null) { _subTracks = all; updateHint(); startSecond(); return; }
97
102
  pickSubs(all, false);
@@ -128,16 +133,13 @@
128
133
  if (partial) { return false; }
129
134
  }
130
135
 
131
- // 2) Otherwise the default language: an addon track, else one built into the file;
132
- // then the second choice, the same way (see applyEmbeddedWant: once the file's own
133
- // tracks are known, so the default language built into it comes first).
136
+ // 2) Otherwise your default language: built into the file, else an addon's (in their
137
+ // order), a USB drive's, YouTube's; then the second choice, the same way. Decided in
138
+ // applyEmbeddedWant, once the file's own tracks are known (all the files in by then).
134
139
  var cfg = getSubCfg();
135
140
  if (!cfg.lang || cfg.lang === 'off') { return !partial; }
136
- // "spa" also matches "es", "es-419", "Spanish", "Español"...
137
- var match = _subTracks.find(function (t) { return langMatches(cfg.lang, t.lang); });
138
- if (match) { loadTrack(match); return true; }
139
141
  if (partial) { return false; }
140
- wantEmbedded({ lang: cfg.lang, lang2: (cfg.lang2 && cfg.lang2 !== 'none' && cfg.lang2 !== cfg.lang) ? cfg.lang2 : null });
142
+ wantEmbedded({ lang: cfg.lang, lang2: (cfg.lang2 && cfg.lang2 !== 'none' && cfg.lang2 !== cfg.lang) ? cfg.lang2 : null, auto: true });
141
143
  return true;
142
144
  }
143
145
  }
@@ -178,17 +180,39 @@
178
180
  // screen; picking it again by hand works). So it's picked once more when playback has run
179
181
  // a moment: through another text track first (or off and on, with only one), since picking
180
182
  // the track the TV already reports is ignored.
181
- var EMB_NUDGE_MS = 2500, _embNudge = null;
183
+ // The way back after a moment (EMB_NUDGE_GAP_MS: the 2017 TV ignores two switches in a row,
184
+ // as with audio; its lines meanwhile not shown), then a look at what the TV reports a few
185
+ // seconds on (EMB_CHECK_MS): not the track picked, picked once more.
186
+ var EMB_NUDGE_MS = 2500, EMB_NUDGE_GAP_MS = 1000, EMB_CHECK_MS = 4000, _embNudge = null, _embQuiet = 0;
187
+ function selectText(index) {
188
+ try { avplay.setSelectTrack('TEXT', index); }
189
+ catch (e) { try { avplay.setSelectTrack('TEXT', '' + index); } catch (e2) {} }
190
+ }
191
+ function textNow() { // the text track the TV reports playing, or null
192
+ try { var l = avplay.getCurrentStreamInfo() || []; for (var i = 0; i < l.length; i++) { if (('' + l[i].type).toUpperCase() === 'TEXT') { return '' + l[i].index; } } } catch (e) {}
193
+ return null;
194
+ }
182
195
  function nudgeEmbedded() {
183
196
  var n = _embNudge; _embNudge = null;
184
197
  if (!n || _subOn || _embSub !== n.index) { return; } // (another choice meanwhile)
185
198
  var other = getTextTracks().filter(function (t) { return t.index !== n.index; })[0];
186
- if (other) { try { avplay.setSelectTrack('TEXT', other.index); } catch (e1) {} }
199
+ _embQuiet = Date.now() + EMB_NUDGE_GAP_MS + 500;
200
+ if (other) { selectText(other.index); }
187
201
  else { try { avplay.setSilentSubtitle(true); } catch (e2) {} }
188
- try { avplay.setSilentSubtitle(false); } catch (e3) {}
189
- try { avplay.setSelectTrack('TEXT', n.index); }
190
- catch (e4) { try { avplay.setSelectTrack('TEXT', '' + n.index); } catch (e5) {} }
202
+ setTimeout(function () {
203
+ if (_subOn || _embSub !== n.index || !S.active) { return; }
204
+ try { avplay.setSilentSubtitle(false); } catch (e3) {}
205
+ selectText(n.index);
206
+ setTimeout(function () {
207
+ if (_subOn || _embSub !== n.index || !S.active) { return; }
208
+ var now = textNow();
209
+ if (now !== null && now !== '' + n.index) { U.log('player', 'Built-in subtitle: the TV played track ' + now + ', not ' + n.index + ': picked again'); selectText(n.index); }
210
+ }, EMB_CHECK_MS);
211
+ }, EMB_NUDGE_GAP_MS);
191
212
  }
213
+ // An audio switch: the 2017 TV goes back to its first text track meanwhile (the one picked
214
+ // still ticked; a pause and play brings it back): picked once more, the same way, a moment on.
215
+ P.subsAfterAudio = function () { if (_embSub != null && !_subOn) { _embNudge = { index: _embSub, at: Date.now() + EMB_NUDGE_MS }; } };
192
216
  // Stream info's "Subtitles" line.
193
217
  function subtitleSummary() {
194
218
  return _subOn ? (_subLabel + (_subDelay ? ' (' + fmtDelay(_subDelay) + ')' : '')) : (_embSub != null ? (_embLang || U.t('on')) + ' ' + U.t('(built-in)') : U.t('Off'));
@@ -673,32 +697,54 @@
673
697
  return out;
674
698
  } catch (e) { return []; }
675
699
  }
676
- function textLang(tr) { return trackLang(tr); }
700
+ // A built-in track's language: the TV's, else the file's own for it (the 2017 TV states none
701
+ // for an MKV's subtitle tracks: P.fileTrack).
702
+ function textLang(tr) {
703
+ var l = trackLang(tr);
704
+ if (l && !P.langUnstated(l)) { return l; }
705
+ var tracks = getTextTracks(), i = -1;
706
+ for (var k = 0; k < tracks.length; k++) { if (tracks[k].index === tr.index) { i = k; break; } }
707
+ var own = i >= 0 && P.fileTrack ? P.fileTrack('subs', tracks, i) : null;
708
+ return own && own.lang ? own.lang : l;
709
+ }
677
710
 
678
- function wantEmbedded(w) { _embWant = w; if (_ticked) { applyEmbeddedWant(); } }
711
+ // (applied once playback runs and the TV lists its tracks; at once when there can be none to
712
+ // wait for: no TV player, a YouTube video, a file whose details list no subtitle track)
713
+ function noBuiltIn() { return !P.useAV || !!(S.ctx && S.ctx.yt) || !!(S.mi && S.mi.container && !(S.mi.subs || []).length); }
714
+ function wantEmbedded(w) { _embWant = w; if (_ticked || noBuiltIn()) { applyEmbeddedWant(); } }
715
+ // The file's details in (or not to be had): a pick that waited for them, now.
716
+ P.subsMiIn = function () { if (_embWant && _ticked) { try { applyEmbeddedWant(); } catch (e) {} } };
679
717
  function applyEmbeddedWant() {
680
718
  var w = _embWant; _embWant = null;
681
719
  if (!w || _subOn) { return; } // an addon track was chosen meanwhile
682
720
  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)
721
+ // (of a language's tracks, by the file's header: a plain one in text, then SDH, then a
722
+ // forced one — a picture one, PGS, shows nothing here, so last)
685
723
  var own = P.fileTracks ? P.fileTracks('subs', tracks) : null;
686
724
  function best(match) {
687
725
  var c = tracks.filter(match);
688
726
  if (!own || c.length < 2) { return c[0] || null; }
689
727
  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];
728
+ var rank = function (t) { var f = o(t); return f.text === false ? 3 : f.forced ? 2 : f.hi ? 1 : 0; };
729
+ return c.slice().sort(function (x, y) { return rank(x) - rank(y) || c.indexOf(x) - c.indexOf(y); })[0];
691
730
  }
692
731
  if (w.index != null) {
693
732
  pick = tracks.find(function (t) { return t.index === w.index && (!key || langKey(textLang(t)) === key); }) || null;
694
733
  }
695
734
  if (!pick && key) { pick = best(function (t) { return langMatches(key, textLang(t)); }); }
735
+ // (no language from the TV, the file's details still being read: picked once they're in,
736
+ // subsMiIn, so your language built into the file isn't passed over)
737
+ if (!pick && P.miPending && P.miPending() && tracks.length && tracks.every(function (t) { return P.langUnstated(trackLang(t)); })) { _embWant = w; return; }
738
+ if (!pick && w.early) { return; } // (only a built-in one, early: the rest once the files are in)
739
+ // (your default language not built in: a subtitle file in it, in the list's order)
740
+ var file = !pick && key && w.auto ? _subTracks.find(function (t) { return langMatches(key, t.lang); }) : null;
741
+ if (file) { loadTrack(file); return; }
696
742
  if (!pick && w.nth != null && S.ctx && S.ctx._relayCc) { pick = tracks[w.nth] || null; } // (a live channel's closed captions: in the order asked for)
697
- if (!pick && w.lang2) { // nothing in the default language anywhere: the second choice, a track to download first
743
+ if (!pick && w.lang2) { // nothing in the default language anywhere: the second choice, the same way
698
744
  var key2 = langKey(w.lang2);
699
- var dl = _subTracks.find(function (t) { return langMatches(key2, t.lang); });
700
- if (dl) { loadTrack(dl); return; }
701
745
  pick = best(function (t) { return langMatches(key2, textLang(t)); });
746
+ var dl = pick ? null : _subTracks.find(function (t) { return langMatches(key2, t.lang); });
747
+ if (dl) { loadTrack(dl); return; }
702
748
  }
703
749
  if (pick) { selectEmbeddedSub(pick); _embNudge = { index: pick.index, at: Date.now() + EMB_NUDGE_MS }; }
704
750
  }
@@ -734,7 +780,7 @@
734
780
  };
735
781
  }
736
782
  function showEmbeddedText(text, duration) {
737
- if (_embSub == null || _subOn) { return; }
783
+ if (_embSub == null || _subOn || Date.now() < _embQuiet) { return; } // (the other track's, while nudging)
738
784
  text = skipper()('' + (text || ''));
739
785
  if (!text) { return; }
740
786
  if (_embDelay > 0) {
@@ -936,7 +982,8 @@
936
982
  if (x.emb) {
937
983
  var tr = x.emb, l = textLang(tr), own = P.fileTrack ? P.fileTrack('subs', getTextTracks(), x.n) : null;
938
984
  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,
985
+ var named = l && !P.langUnstated(l) ? langName(langKey(l)) : ''; // ("English", as the audio list says it)
986
+ 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
987
  detail: own && P.fileTrackNote ? P.fileTrackNote(own) || undefined : undefined, // (its own name and marks, from the file's header)
941
988
  run: function () {
942
989
  _embDelay = 0; _embQueue = []; _embNudge = null; selectEmbeddedSub(tr); rememberSub(S.ctx.id, { embedded: true, index: tr.index, lang: l });
@@ -2475,15 +2475,18 @@
2475
2475
  // (an HLS source through the service, with its own headers on every piece: see player-core's viaService)
2476
2476
  var HLS_ROUTES = [['off', U.t('Off')], ['headers', U.t('Sources that need headers')], ['all', U.t('All HLS sources')]];
2477
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')]];
2478
2480
  function settingsSeeking(wrap) {
2479
2481
  wrap.appendChild(U.el('h2', null, U.t('Seeking & buffering')));
2480
- var store = { get: function () { var c = Player.playerCfg(); return { seek: '' + c.seek, buffer: c.buffer, reconnect: c.reconnect, hls: c.hls, fileInfo: c.fileInfo }; },
2481
- 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 }); } };
2482
2484
  wrap.appendChild(subPickRow(U.t('Seek step'), [['5', '5 s'], ['10', '10 s'], ['15', '15 s'], ['30', '30 s']], 'seek', store));
2483
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));
2484
2486
  wrap.appendChild(subPickRow(U.t('Reconnect live channels'), RECONNECTS, 'reconnect', store));
2485
2487
  wrap.appendChild(subPickRow(U.t('HLS through StremioK’s service'), HLS_ROUTES, 'hls', store));
2486
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));
2487
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.'));
2488
2491
  focusSettings();
2489
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, audio) {
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(',') + (audio && audio.length ? '&audio=' + audio.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.1",
3
+ "version": "2.4.3",
4
4
  "description": "StremioK streaming client for Tizen 3.0+ Samsung TVs (TizenBrew app module).",
5
5
  "packageType": "app",
6
6
  "appName": "StremioK",