stremiok 2.3.5 → 2.3.7
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/CHANGELOG.md +27 -0
- package/README.md +18 -15
- package/config.xml +2 -1
- package/css/style.css +1 -0
- package/index.html +43 -42
- package/js/lang/ar.js +94 -5
- package/js/lang/de.js +102 -13
- package/js/lang/es.js +92 -3
- package/js/lang/fi.js +98 -9
- package/js/lang/fr.js +102 -13
- package/js/lang/he.js +94 -5
- package/js/lang/hi.js +94 -5
- package/js/lang/it.js +94 -5
- package/js/lang/ja.js +94 -5
- package/js/lang/ko.js +92 -3
- package/js/lang/pl.js +118 -29
- package/js/lang/pt-BR.js +92 -3
- package/js/lang/ru.js +94 -5
- package/js/lang/tr.js +94 -5
- package/js/lang/zh-CN.js +96 -7
- package/js/local.js +63 -18
- package/js/netfolders.js +76 -8
- package/js/player-audio.js +16 -8
- package/js/player-controls.js +68 -0
- package/js/player-core.js +129 -9
- package/js/player-lang.js +16 -0
- package/js/player-store.js +7 -2
- package/js/player-subs.js +267 -17
- package/js/plugins.js +306 -0
- package/js/stremio.js +57 -8
- package/js/util.js +10 -1
- package/js/vendor/quickjs/LICENSES.md +412 -0
- package/js/vendor/quickjs/crypto-js.js +6659 -0
- package/js/vendor/quickjs/plugin-worker-legacy.js +1364 -0
- package/js/vendor/quickjs/plugin-worker.js +8774 -0
- package/js/vendor/quickjs/quickjs.wasm +0 -0
- package/js/view-core.js +2 -2
- package/js/view-detail.js +18 -7
- package/js/view-settings.js +251 -15
- package/js/ytplay.js +60 -7
- package/package.json +1 -1
- package/service/index.js +1884 -67
- package/tizenbrew.html +1 -1
package/js/player-core.js
CHANGED
|
@@ -95,10 +95,12 @@ var PlayerParts = {};
|
|
|
95
95
|
|
|
96
96
|
// Jumps ahead the player makes on its own (see checkJump): the last play time and when
|
|
97
97
|
// it came, and where one was last undone.
|
|
98
|
-
var JUMP_SLACK_SECS = 5;
|
|
98
|
+
var JUMP_SLACK_SECS = 5, JUMP_BACK_MS = 20000;
|
|
99
99
|
var _tick = null; // { pos (s), wall (ms) }
|
|
100
100
|
var _jumpUndone = null; // the position (s) a jump was last taken back to
|
|
101
101
|
var _pausedOnce = false; // paused since this was opened (it only happens after pauses)
|
|
102
|
+
var _pausedSince = 0; // when it was paused (Date.now), 0 playing: a long pause re-anchors the TV's player (play_)
|
|
103
|
+
var _jumpBack = null; // a jump taken back: { to (s), at (ms), tries }, checked on the next play times (checkJump)
|
|
102
104
|
|
|
103
105
|
function init() {
|
|
104
106
|
objEl = U.byId('av-player');
|
|
@@ -426,6 +428,60 @@ var PlayerParts = {};
|
|
|
426
428
|
play(ctx, _onExit);
|
|
427
429
|
}
|
|
428
430
|
|
|
431
|
+
// What's in the file playing, from its header (StremioK's service reads it: its container,
|
|
432
|
+
// codecs, HDR, every audio and subtitle track with its name; see the service's mediaInfo):
|
|
433
|
+
// asked once for the source as it opens, never for a list of them; the last MI_KEEP kept.
|
|
434
|
+
// S.mi: the answer for what's playing, else null (not asked yet, not read, or not a file:
|
|
435
|
+
// HLS, DASH, YouTube, a live channel, a trailer).
|
|
436
|
+
var MI_KEEP = 40, _miSeen = U.lru(MI_KEEP), _miLook = null;
|
|
437
|
+
function fileInfoAsk(ctx) {
|
|
438
|
+
if (!ctx || ctx.yt || ctx.trailer || S.isLive) { return null; }
|
|
439
|
+
// (Settings › Playback › Seeking & buffering › Read the file's details: a USB drive's only
|
|
440
|
+
// unless All files — the others are more requests to their server as playback starts)
|
|
441
|
+
var want = P.playerCfg().fileInfo;
|
|
442
|
+
if (want === 'off' || (want !== 'all' && !(ctx.localFile && !ctx.localFile.dav))) { return null; }
|
|
443
|
+
var url = '' + (ctx.url || ''), size = ctx.stream && ctx.stream.behaviorHints ? +ctx.stream.behaviorHints.videoSize || 0 : 0;
|
|
444
|
+
if (ctx.localFile) {
|
|
445
|
+
if (typeof LocalMedia === 'undefined' || !LocalMedia.fileInfo) { return null; }
|
|
446
|
+
return { key: 'file:' + (ctx.localFile.dav || '') + ':' + ctx.localFile.abs + ':' + (ctx.localFile.size || 0), ask: function (c) { return LocalMedia.fileInfo(ctx.localFile, c); } };
|
|
447
|
+
}
|
|
448
|
+
if (!/^https?:\/\//i.test(url) || /^http:\/\/(localhost|127\.0\.0\.1)[:\/]/i.test(url) || HLS_LINK.test(url) || /\.mpd(?:[?#]|$)/i.test(url)) { return null; }
|
|
449
|
+
if (ctx.formatInfo && ctx.formatInfo.container === 'hls') { return null; }
|
|
450
|
+
if (typeof YTPlay === 'undefined' || !YTPlay.mediaInfo || YTPlay.installMode() === 'browser') { return null; }
|
|
451
|
+
var lan = typeof Stremio !== 'undefined' && Stremio.getPrefs ? !!Stremio.getPrefs().allowLocal : false;
|
|
452
|
+
return { key: 'link:' + url.split(/[?#]/)[0] + ':' + (size || url), ask: function (c) { return YTPlay.mediaInfo(url, U.sanitizeHeaders(ctx._headers), lan, c); } }; // (the link without its query, and the file's size: a new token, the same file)
|
|
453
|
+
}
|
|
454
|
+
function startFileInfo(ctx) {
|
|
455
|
+
if (_miLook) { _miLook.cancel(); _miLook = null; }
|
|
456
|
+
S.mi = null;
|
|
457
|
+
var job = fileInfoAsk(ctx);
|
|
458
|
+
if (!job) { return; }
|
|
459
|
+
var known = _miSeen.get(job.key);
|
|
460
|
+
if (known) { fileInfoIn(ctx, known); return; }
|
|
461
|
+
var look = _miLook = U.cancelToken();
|
|
462
|
+
job.ask(look).then(function (mi) {
|
|
463
|
+
if (look.cancelled || !mi || typeof mi !== 'object' || !mi.container) { return; }
|
|
464
|
+
_miSeen.set(job.key, mi);
|
|
465
|
+
if (S.ctx === ctx && S.active) { fileInfoIn(ctx, mi); }
|
|
466
|
+
}, function (e) { if (!look.cancelled) { U.log('player', 'The file\'s details couldn\'t be read: ' + ((e && e.message) || 'unknown')); } });
|
|
467
|
+
}
|
|
468
|
+
// The answer in: S.mi, and the source's details corrected by it (Stremio.withFileInfo): what
|
|
469
|
+
// the player shows (its tags, Stream info) and what Formats learns from it are the file's.
|
|
470
|
+
function fileInfoIn(ctx, mi) {
|
|
471
|
+
S.mi = mi;
|
|
472
|
+
if (typeof Stremio !== 'undefined' && Stremio.withFileInfo) { ctx.formatInfo = Stremio.withFileInfo(ctx.formatInfo || (Stremio.streamInfo ? Stremio.streamInfo({ url: ctx.url, name: ctx.name }) : null), mi); }
|
|
473
|
+
if (!osdHidden()) { renderOSD(); }
|
|
474
|
+
}
|
|
475
|
+
// A start that failed for its format (not the network or the link), its file's header read:
|
|
476
|
+
// what's in the file said ("HEVC 10-bit · Dolby Vision 5 · Dolby TrueHD 7.1"), else why as given.
|
|
477
|
+
var NOT_FORMAT_ERR = /CONNECTION|NETWORK|DISCONNECT|INVALID_URI|TIMEOUT|TIMED_OUT|HTTP|license/i;
|
|
478
|
+
function formatFailText(why, err) {
|
|
479
|
+
if (!S.mi || !P.fileSummary || NOT_FORMAT_ERR.test('' + (err || '')) || (S.ctx && S.ctx._drmWhy)) { return why; }
|
|
480
|
+
var what = P.fileSummary(S.mi);
|
|
481
|
+
return what ? U.t('This TV didn’t play this file: {what}', { what: what }) : why;
|
|
482
|
+
}
|
|
483
|
+
P.fileInfoFor = function (ctx) { var j = fileInfoAsk(ctx); return j ? _miSeen.get(j.key) || null : null; };
|
|
484
|
+
|
|
429
485
|
function play(ctx, onExit) {
|
|
430
486
|
// Replacing a YouTube stream that's playing (CH+/CH− to the next channel): the TV's
|
|
431
487
|
// player can freeze on an open straight after closing it, so settle first (startAV).
|
|
@@ -463,7 +519,7 @@ var PlayerParts = {};
|
|
|
463
519
|
recoReset();
|
|
464
520
|
_prefetchedNext = false; S.playStarted = false; S.playing = false;
|
|
465
521
|
_segments = null; _creditsSec = null; _creditsHandled = false; _segmentsFor = null;
|
|
466
|
-
S.buffering = false; S.pendingSeek = null; S.lastSeekAt = 0; S.settleFrom = 0; _seekRecovering = false; _jumpUndone = null; _pausedOnce = false;
|
|
522
|
+
S.buffering = false; S.pendingSeek = null; S.lastSeekAt = 0; S.settleFrom = 0; _seekRecovering = false; _jumpUndone = null; _pausedOnce = false; _pausedSince = 0; _jumpBack = null;
|
|
467
523
|
updateHint();
|
|
468
524
|
|
|
469
525
|
U.byId('app').className = 'hidden';
|
|
@@ -474,7 +530,17 @@ var PlayerParts = {};
|
|
|
474
530
|
|
|
475
531
|
engineFor(ctx); // (the TV's player, or a ClearKey channel's own: see startShaka)
|
|
476
532
|
// (a TorrServer torrent that doesn't say which of its files: its file list asked for first)
|
|
477
|
-
var go = function () {
|
|
533
|
+
var go = function () {
|
|
534
|
+
if (fileViaService(ctx)) { startFileRelay(ctx, settle); return; }
|
|
535
|
+
if (useAV) { startLive(ctx, settle); } else { startHTML5(ctx.url); }
|
|
536
|
+
};
|
|
537
|
+
// (a network folder's file that plays through the service — Digest sign-in: its ticket
|
|
538
|
+
// first, LocalMedia.prepare; asked or not, it then plays)
|
|
539
|
+
var prep = ctx.localFile && typeof LocalMedia !== 'undefined' && LocalMedia.prepare ? LocalMedia.prepare(ctx.url) : null;
|
|
540
|
+
if (prep) {
|
|
541
|
+
var plain = go;
|
|
542
|
+
go = function () { prep.then(function () { if (S.ctx === ctx && S.active) { plain(); } }, function () { if (S.ctx === ctx && S.active) { plain(); } }); };
|
|
543
|
+
}
|
|
478
544
|
if (ctx.stream && ctx.stream._pickFile && typeof Stremio !== 'undefined' && Stremio.torrentFile) {
|
|
479
545
|
// (the source before stopped first: its callbacks are about it, not this one)
|
|
480
546
|
++_playToken; _openedAt = 0;
|
|
@@ -509,6 +575,8 @@ var PlayerParts = {};
|
|
|
509
575
|
}, function () {});
|
|
510
576
|
}
|
|
511
577
|
|
|
578
|
+
startFileInfo(ctx);
|
|
579
|
+
|
|
512
580
|
// A trailer is just watched: no skip segments, progress or watched state. Its subtitles
|
|
513
581
|
// (your language, else your second choice) from its own captions (see startSubtitles).
|
|
514
582
|
if (ctx.trailer) { startSubtitles(ctx); return; }
|
|
@@ -794,7 +862,7 @@ var PlayerParts = {};
|
|
|
794
862
|
if (!S.playing && (relayFailed() || tryFallback())) { return; }
|
|
795
863
|
reportStart(false, err); // (unless it had already played)
|
|
796
864
|
U.log('player', 'Playback error: ' + err + ' (' + where(S.ctx && S.ctx.url) + ')');
|
|
797
|
-
if (!S.playing) { failedStart(U.t('Playback error: {why}', { why: err })); return; }
|
|
865
|
+
if (!S.playing) { failedStart(formatFailText(U.t('Playback error: {why}', { why: err }), err)); return; }
|
|
798
866
|
U.toast(U.t('Playback error: {why}', { why: err }));
|
|
799
867
|
exitLater();
|
|
800
868
|
}
|
|
@@ -835,7 +903,7 @@ var PlayerParts = {};
|
|
|
835
903
|
if (tryFallback()) { return; }
|
|
836
904
|
U.log('player', 'Could not open: ' + (err && (err.name || err.message || err)) + ' (' + where(url) + ')');
|
|
837
905
|
reportStart(false, err && (err.name || err.message || err));
|
|
838
|
-
failedStart(S.ctx && S.ctx._drmWhy ? U.t('No license for this channel: {why}', { why: S.ctx._drmWhy }) : U.t('Could not open stream'));
|
|
906
|
+
failedStart(S.ctx && S.ctx._drmWhy ? U.t('No license for this channel: {why}', { why: S.ctx._drmWhy }) : formatFailText(U.t('Could not open stream'), err && (err.name || err.message || err)));
|
|
839
907
|
});
|
|
840
908
|
} catch (e) {
|
|
841
909
|
U.log('player', 'AVPlay failed: ' + (e && e.message));
|
|
@@ -1168,8 +1236,20 @@ var PlayerParts = {};
|
|
|
1168
1236
|
if (useAV) { return state() !== 'PLAYING'; }
|
|
1169
1237
|
return S.videoEl.paused;
|
|
1170
1238
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1239
|
+
// After a pause of LONG_PAUSE_MS or more the TV's player can jump ahead at its next buffering,
|
|
1240
|
+
// to where it would be had it never paused (its clock ran on: seen 115 s and 501 s on the Tizen
|
|
1241
|
+
// 6 TV): so it's set again at the paused place first (a jump to where it is), and plays on from
|
|
1242
|
+
// there. A short pause: as it is.
|
|
1243
|
+
var LONG_PAUSE_MS = 20000;
|
|
1244
|
+
function play_() {
|
|
1245
|
+
if (useAV) {
|
|
1246
|
+
if (_pausedSince && Date.now() - _pausedSince >= LONG_PAUSE_MS && !S.isLive && S.cur > 0) { doAVSeek(S.cur, 0); }
|
|
1247
|
+
_pausedSince = 0;
|
|
1248
|
+
try { avplay.play(); } catch (e) {}
|
|
1249
|
+
} else { S.videoEl.play(); }
|
|
1250
|
+
screenSaver(false);
|
|
1251
|
+
}
|
|
1252
|
+
function pause_() { _pausedOnce = true; _pausedSince = Date.now(); jfTell('pause'); if (useAV) { try { avplay.pause(); } catch (e) {} } else { S.videoEl.pause(); } screenSaver(true); }
|
|
1173
1253
|
|
|
1174
1254
|
// The TV's screensaver stays off while a video plays and is allowed again when it's
|
|
1175
1255
|
// paused or stopped. No-op where the Samsung appcommon API isn't available.
|
|
@@ -1187,7 +1267,7 @@ var PlayerParts = {};
|
|
|
1187
1267
|
// keep a small margin from the very end (seeking to EOF can error)
|
|
1188
1268
|
var maxT = S.dur ? Math.max(0, S.dur - 2) : 1e9;
|
|
1189
1269
|
var target = Math.max(0, Math.min(maxT, sec));
|
|
1190
|
-
S.cur = target;
|
|
1270
|
+
S.cur = target; _jumpBack = null; // (a jump you asked for: not taken back)
|
|
1191
1271
|
renderOSD();
|
|
1192
1272
|
showOSD(false);
|
|
1193
1273
|
if (useAV) {
|
|
@@ -1223,6 +1303,16 @@ var PlayerParts = {};
|
|
|
1223
1303
|
// Returns true when it took one back (that play time isn't shown).
|
|
1224
1304
|
function checkJump(pos) {
|
|
1225
1305
|
var now = Date.now(), t = _tick;
|
|
1306
|
+
// (a jump taken back: did the TV go back? One it ignored — asked while it buffered — is
|
|
1307
|
+
// asked again, twice at most, within JUMP_BACK_MS)
|
|
1308
|
+
var jb = _jumpBack;
|
|
1309
|
+
if (jb) {
|
|
1310
|
+
if (pos <= jb.to + JUMP_SLACK_SECS + 2 || now - jb.at > JUMP_BACK_MS) { _jumpBack = null; }
|
|
1311
|
+
else if (!S.buffering && S.pendingSeek == null && now - S.lastSeekAt > 1500) {
|
|
1312
|
+
if (jb.tries >= 2) { _jumpBack = null; U.log('player', 'Playback jumped ahead and didn\'t go back to ' + U.fmtTime(jb.to) + ': left at ' + U.fmtTime(pos)); }
|
|
1313
|
+
else { jb.tries++; _tick = { pos: jb.to, wall: now }; S.cur = jb.to; doAVSeek(jb.to, 0); return true; }
|
|
1314
|
+
} else { return true; } // (on its way back: that play time isn't shown)
|
|
1315
|
+
}
|
|
1226
1316
|
_tick = { pos: pos, wall: now };
|
|
1227
1317
|
if (!t || !_pausedOnce || S.isLive || !useAV || scrubbing() || S.pendingSeek != null || S.lastSeekAt >= t.wall) { return false; }
|
|
1228
1318
|
var ahead = (pos - t.pos) - (now - t.wall) / 1000;
|
|
@@ -1236,7 +1326,10 @@ var PlayerParts = {};
|
|
|
1236
1326
|
_jumpUndone = t.pos;
|
|
1237
1327
|
_tick = { pos: t.pos, wall: now };
|
|
1238
1328
|
S.cur = t.pos;
|
|
1239
|
-
|
|
1329
|
+
_jumpBack = { to: t.pos, at: now, tries: 0 };
|
|
1330
|
+
// (it jumps as it buffers, when the TV ignores a seek: then asked once the buffering's done,
|
|
1331
|
+
// as any seek made then)
|
|
1332
|
+
if (S.buffering) { S.pendingSeek = t.pos; } else { doAVSeek(t.pos, 0); }
|
|
1240
1333
|
return true;
|
|
1241
1334
|
}
|
|
1242
1335
|
|
|
@@ -1463,6 +1556,33 @@ var PlayerParts = {};
|
|
|
1463
1556
|
startAV(ctx.url, settle);
|
|
1464
1557
|
}, function () { if (S.ctx === ctx && S.active) { startAV(ctx.url, settle); } });
|
|
1465
1558
|
}
|
|
1559
|
+
// A file (not HLS) through the service's file relay (/live/file): when it needs headers the
|
|
1560
|
+
// TV's player can't send (Origin, Accept, Accept-Language; under TizenBrew the page's player
|
|
1561
|
+
// sends none), or hold OK on it (ctx.viaService). Each request goes on with its headers and the
|
|
1562
|
+
// player's byte range. Not YouTube, DRM, USB files or the service's own links; redirects into
|
|
1563
|
+
// the home network as Local-network links from internet addons says; the service not
|
|
1564
|
+
// answering: as it is.
|
|
1565
|
+
function fileViaService(ctx) {
|
|
1566
|
+
if (!ctx || ctx._relay || ctx.yt || ctx.trailer || ctx.localFile || (ctx.stream && ctx.stream._drm)) { return false; }
|
|
1567
|
+
if (typeof YTPlay === 'undefined' || !YTPlay.fileOpen || YTPlay.installMode() === 'browser') { return false; }
|
|
1568
|
+
var url = ctx.url || '';
|
|
1569
|
+
if (!/^https?:\/\//i.test(url) || /^http:\/\/(localhost|127\.0\.0\.1)[:\/]/i.test(url)) { return false; }
|
|
1570
|
+
if (HLS_LINK.test(url) || (ctx.formatInfo && ctx.formatInfo.container === 'hls') || /\.mpd(?:[?#]|$)/i.test(url)) { return false; }
|
|
1571
|
+
if (ctx.viaService) { return true; }
|
|
1572
|
+
var h = U.sanitizeHeaders(ctx._headers);
|
|
1573
|
+
return !!h && (!useAV || !!(h.origin || h.accept || h.lang));
|
|
1574
|
+
}
|
|
1575
|
+
function startFileRelay(ctx, settle) {
|
|
1576
|
+
var lan = typeof Stremio !== 'undefined' && Stremio.getPrefs ? !!Stremio.getPrefs().allowLocal : false;
|
|
1577
|
+
function go() {
|
|
1578
|
+
if (S.ctx !== ctx || !S.active) { return; }
|
|
1579
|
+
if (useAV) { startLive(ctx, settle); } else { startHTML5(ctx._relay && ctx._relayFor === ctx.url ? ctx._relay : ctx.url); }
|
|
1580
|
+
}
|
|
1581
|
+
YTPlay.fileOpen(ctx.url, U.sanitizeHeaders(ctx._headers), lan).then(function (r) {
|
|
1582
|
+
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) + ')'); }
|
|
1583
|
+
go();
|
|
1584
|
+
}, go);
|
|
1585
|
+
}
|
|
1466
1586
|
function startLive(ctx, settle) {
|
|
1467
1587
|
if (!ctx._relay && viaService(ctx)) { startViaService(ctx, settle); return; }
|
|
1468
1588
|
var known = liveFixable(ctx) ? liveKnown(ctx.url) : null, cc = ccOf(known);
|
package/js/player-lang.js
CHANGED
|
@@ -177,6 +177,22 @@
|
|
|
177
177
|
return ('' + (lang || '')).toLowerCase().trim();
|
|
178
178
|
}
|
|
179
179
|
|
|
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).
|
|
184
|
+
function fileTracks(kind, tracks) {
|
|
185
|
+
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; }
|
|
190
|
+
}
|
|
191
|
+
return list;
|
|
192
|
+
}
|
|
193
|
+
function fileTrack(kind, tracks, pos) { var l = fileTracks(kind, tracks); return l ? l[pos] || null : null; }
|
|
194
|
+
P.fileTracks = fileTracks; P.fileTrack = fileTrack;
|
|
195
|
+
|
|
180
196
|
// ----- for the other parts (and js/player.js) -----
|
|
181
197
|
P.trackInfo = trackInfo; P.infoLang = infoLang; P.trackLang = trackLang; P.langMatches = langMatches;
|
|
182
198
|
P.langName = langName; P.langRank = langRank; P.langKey = langKey;
|
package/js/player-store.js
CHANGED
|
@@ -97,7 +97,8 @@
|
|
|
97
97
|
font: subFontFamily(d.font) ? d.font : 'default', // an unknown font -> TV default
|
|
98
98
|
skip: skipWords(d.skip), // lines with one of these aren't shown (none by default: see player-subs' skipLines)
|
|
99
99
|
second: typeof d.second === 'string' && /^[a-z]{2,3}$/.test(d.second) ? d.second : 'off', // a second subtitle at the top (player-subs; Off by default)
|
|
100
|
-
only: d.only === 'on' ? 'on' : 'off'
|
|
100
|
+
only: d.only === 'on' ? 'on' : 'off', // the subtitle menu: only your languages (player-subs' langMenu; Off by default)
|
|
101
|
+
fileColors: d.fileColors === 'on' ? 'on' : 'off' }; // a file's own colors (ASS, <font color>) instead of yours (player-subs' drawCues; Off by default)
|
|
101
102
|
}
|
|
102
103
|
// Settings › Subtitles › Skip lines with: words (or bits, ".srt"), capitals or not; at most 20.
|
|
103
104
|
function skipWords(x) {
|
|
@@ -261,7 +262,11 @@
|
|
|
261
262
|
buffer: d.buffer === 'more' || d.buffer === 'most' ? d.buffer : 'normal',
|
|
262
263
|
reconnect: d.reconnect === 'off' || d.reconnect === 'always' ? d.reconnect : 'few',
|
|
263
264
|
phone: d.phone === 'infuse' || d.phone === 'link' ? d.phone : 'vlc', // (Continue on phone: what the QR opens)
|
|
264
|
-
hls: d.hls === 'headers' || d.hls === 'all' ? d.hls : 'off'
|
|
265
|
+
hls: d.hls === 'headers' || d.hls === 'all' ? d.hls : 'off', // (HLS through StremioK's service: see player-core's viaService)
|
|
266
|
+
// (the file's details read from its start: player-core's fileInfoAsk. A USB drive's by
|
|
267
|
+
// default, read off the drive itself; a link's or a network folder's are more requests
|
|
268
|
+
// as it starts, so only when chosen)
|
|
269
|
+
fileInfo: d.fileInfo === 'all' || d.fileInfo === 'off' ? d.fileInfo : 'usb' };
|
|
265
270
|
}
|
|
266
271
|
function setPlayerCfg(cfg) { // (what's given changes; the rest stays)
|
|
267
272
|
var d = U.store.get(PLAYERCFG_KEY, {}) || {};
|
package/js/player-subs.js
CHANGED
|
@@ -230,9 +230,85 @@
|
|
|
230
230
|
}
|
|
231
231
|
// A file's cues: CUES_MAX at most, CUE_TEXT_MAX characters of text each (a broken or hostile
|
|
232
232
|
// file can't hold the remote: the whole parse stays in time with the file's length).
|
|
233
|
+
// A cue: { start, end, text } (text: as read, plain), with runs when it has styling: [{ t, i, b,
|
|
234
|
+
// u, c }] (italic, bold, underline, a color '#rrggbb'), pieces drawn as text (drawCues).
|
|
235
|
+
// The format told by the file's content, whatever its name: ASS / SSA, SAMI, MicroDVD, MPL2,
|
|
236
|
+
// TMPlayer, else SRT / WebVTT.
|
|
233
237
|
var CUES_MAX = 20000, CUE_TEXT_MAX = 1000;
|
|
234
238
|
function parseCues(text) {
|
|
235
|
-
text = ('' + text).replace(/\r/g, '');
|
|
239
|
+
text = ('' + text).replace(/\r/g, '').replace(/^/, '');
|
|
240
|
+
var head = text.slice(0, 4096), cues;
|
|
241
|
+
if (/^\s*\[script info\]/i.test(head) || /^\[v4\+? styles\]/im.test(head) || /^dialogue\s*:/im.test(head)) { cues = parseAss(text); }
|
|
242
|
+
else if (/<sami[\s>]/i.test(head)) { cues = parseSami(text); }
|
|
243
|
+
else if (/^\s*\{\d+\}\{\d*\}/.test(head)) { cues = parseFramed(text); }
|
|
244
|
+
else if (/^\s*\[\d+\]\[\d*\]/.test(head)) { cues = parseMpl2(text); }
|
|
245
|
+
else if (/^\s*\d{1,2}:\d{2}:\d{2}[:=]/.test(head) && head.indexOf('-->') === -1) { cues = parseTmp(text); }
|
|
246
|
+
else { cues = parseSrt(text); }
|
|
247
|
+
cues.sort(function (a, b) { return a.start - b.start; });
|
|
248
|
+
return cues;
|
|
249
|
+
}
|
|
250
|
+
// A cue from its runs: neighbours styled alike joined, the ends' spaces trimmed; runs kept only
|
|
251
|
+
// when one is styled; Skip lines with applied (a line taken out: the cue plain).
|
|
252
|
+
function makeCue(start, end, runs, skip) {
|
|
253
|
+
var out = [];
|
|
254
|
+
runs.forEach(function (r) {
|
|
255
|
+
if (!r.t) { return; }
|
|
256
|
+
var last = out[out.length - 1];
|
|
257
|
+
if (last && !!last.i === !!r.i && !!last.b === !!r.b && !!last.u === !!r.u && (last.c || '') === (r.c || '')) { last.t += r.t; return; }
|
|
258
|
+
out.push(runOf(r.t, r));
|
|
259
|
+
});
|
|
260
|
+
while (out.length && !/\S/.test(out[0].t)) { out.shift(); }
|
|
261
|
+
while (out.length && !/\S/.test(out[out.length - 1].t)) { out.pop(); }
|
|
262
|
+
if (!out.length) { return null; }
|
|
263
|
+
out[0].t = out[0].t.replace(/^\s+/, '');
|
|
264
|
+
out[out.length - 1].t = out[out.length - 1].t.replace(/\s+$/, '');
|
|
265
|
+
var plain = out.map(function (r) { return r.t; }).join('').slice(0, CUE_TEXT_MAX);
|
|
266
|
+
var txt = skip(plain);
|
|
267
|
+
if (!txt) { return null; }
|
|
268
|
+
var cue = { start: start, end: end, text: txt };
|
|
269
|
+
if (txt === plain && out.some(function (r) { return r.i || r.b || r.u || r.c; })) { cue.runs = out; }
|
|
270
|
+
return cue;
|
|
271
|
+
}
|
|
272
|
+
function runOf(t, st) {
|
|
273
|
+
var r = { t: t };
|
|
274
|
+
if (st.i) { r.i = true; } if (st.b) { r.b = true; } if (st.u) { r.u = true; } if (st.c) { r.c = st.c; }
|
|
275
|
+
return r;
|
|
276
|
+
}
|
|
277
|
+
// A color as '#rrggbb': #rgb / #rrggbb, or a plain color name (red); else none.
|
|
278
|
+
function cssColor(x) {
|
|
279
|
+
x = ('' + (x || '')).trim().toLowerCase().replace(/^["']|["']$/g, '');
|
|
280
|
+
var m = /^#?([0-9a-f]{6})$/.exec(x);
|
|
281
|
+
if (m) { return '#' + m[1]; }
|
|
282
|
+
m = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(x);
|
|
283
|
+
if (m) { return '#' + m[1] + m[1] + m[2] + m[2] + m[3] + m[3]; }
|
|
284
|
+
return /^[a-z]{3,20}$/.test(x) ? x : '';
|
|
285
|
+
}
|
|
286
|
+
// HTML-like text (SRT, WebVTT, SAMI) as runs: <i> <b> <u> <font color> kept as styling, <br> a new
|
|
287
|
+
// line, other tags and a stray < left out (one pass, in time with the text's length), character
|
|
288
|
+
// codes read after (one written as < is the file's own text: "<b>" shown as written).
|
|
289
|
+
function tagRuns(t) {
|
|
290
|
+
var runs = [], st = { i: 0, b: 0, u: 0 }, colors = [], i = 0, n = t.length;
|
|
291
|
+
function add(s) { if (s) { runs.push(runOf(charCodes(s), { i: st.i > 0, b: st.b > 0, u: st.u > 0, c: colors[colors.length - 1] })); } }
|
|
292
|
+
while (i < n) {
|
|
293
|
+
var lt = t.indexOf('<', i);
|
|
294
|
+
if (lt === -1) { add(t.slice(i)); break; }
|
|
295
|
+
add(t.slice(i, lt));
|
|
296
|
+
var gt = t.indexOf('>', lt + 1);
|
|
297
|
+
if (gt === -1) { add(t.slice(lt + 1).split('<').join('')); break; } // (no tag ends after it: the rest, its < gone)
|
|
298
|
+
var m = /^\s*(\/?)\s*([a-zA-Z]+)([\s\S]*)$/.exec(t.slice(lt + 1, gt));
|
|
299
|
+
i = gt + 1;
|
|
300
|
+
if (!m) { continue; }
|
|
301
|
+
var close = m[1] === '/', name = m[2].toLowerCase();
|
|
302
|
+
if (name === 'i' || name === 'b' || name === 'u') { st[name] = close ? Math.max(0, st[name] - 1) : st[name] + 1; }
|
|
303
|
+
else if (name === 'font') {
|
|
304
|
+
if (close) { colors.pop(); }
|
|
305
|
+
else { var cm = /color\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/i.exec(m[3]); colors.push(cm ? cssColor(cm[1]) : colors[colors.length - 1]); }
|
|
306
|
+
}
|
|
307
|
+
else if (name === 'br' && !close) { runs.push({ t: '\n' }); }
|
|
308
|
+
}
|
|
309
|
+
return runs;
|
|
310
|
+
}
|
|
311
|
+
function parseSrt(text) {
|
|
236
312
|
var blocks = text.split(/\n\n+/);
|
|
237
313
|
var cues = [], skip = skipper(); // (Skip lines with: your words)
|
|
238
314
|
var re = /(?:(\d{1,3}):)?(\d{2}):(\d{2})[,.](\d{1,3})\s*-->\s*(?:(\d{1,3}):)?(\d{2}):(\d{2})[,.](\d{1,3})/;
|
|
@@ -247,40 +323,204 @@
|
|
|
247
323
|
if (!m) { continue; }
|
|
248
324
|
var start = (+(m[1] || 0)) * 3600 + (+m[2]) * 60 + (+m[3]) + ms(m[4]);
|
|
249
325
|
var end = (+(m[5] || 0)) * 3600 + (+m[6]) * 60 + (+m[7]) + ms(m[8]);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
326
|
+
var cue = makeCue(start, end, tagRuns(lines.slice(ti + 1).join('\n').slice(0, CUE_TEXT_MAX).replace(/\{\\[^}]*\}/g, '')), skip); // ({\an8}: an ASS position, not shown)
|
|
327
|
+
if (cue) { cues.push(cue); }
|
|
328
|
+
}
|
|
329
|
+
return cues;
|
|
330
|
+
}
|
|
331
|
+
// SAMI (.smi): <SYNC Start=ms> marks; a line shows until the next one (a blank one ends it).
|
|
332
|
+
function parseSami(text) {
|
|
333
|
+
var cues = [], skip = skipper(), re = /<sync[^>]*?start\s*=\s*["']?(\d+)[^>]*>/gi, marks = [], m;
|
|
334
|
+
while ((m = re.exec(text)) && marks.length < CUES_MAX) { marks.push({ at: +m[1] / 1000, from: re.lastIndex, to: text.length }); if (marks.length > 1) { marks[marks.length - 2].to = m.index; } }
|
|
335
|
+
for (var i = 0; i < marks.length; i++) {
|
|
336
|
+
var body = text.slice(marks[i].from, Math.min(marks[i].to, marks[i].from + CUE_TEXT_MAX * 4)).replace(/<\/(body|sami)>[\s\S]*$/i, '').replace(/\s*\n\s*/g, ' ');
|
|
337
|
+
var end = i + 1 < marks.length ? marks[i + 1].at : marks[i].at + 4;
|
|
338
|
+
var cue = makeCue(marks[i].at, end, tagRuns(body), skip);
|
|
339
|
+
if (cue) { cues.push(cue); }
|
|
340
|
+
}
|
|
341
|
+
return cues;
|
|
342
|
+
}
|
|
343
|
+
// A line's own styling in the frame-based formats: MicroDVD's {y:i} {y:b} {y:u} {c:$BBGGRR} at its
|
|
344
|
+
// start, a / starting a line for italics (MPL2, often MicroDVD); | between lines.
|
|
345
|
+
function slashRuns(body, st) {
|
|
346
|
+
var runs = [];
|
|
347
|
+
body.split('|').forEach(function (line, k) {
|
|
348
|
+
if (k) { runs.push({ t: '\n' }); }
|
|
349
|
+
var it = /^\s*\//.test(line);
|
|
350
|
+
runs.push(runOf(line.replace(/^\s*\//, '').replace(/\{[^}]*\}/g, ''), { i: st.i || it, b: st.b, u: st.u, c: st.c }));
|
|
351
|
+
});
|
|
352
|
+
return runs;
|
|
353
|
+
}
|
|
354
|
+
// MicroDVD (.sub, .txt): {start frame}{end frame}text, at the frame rate its first line gives
|
|
355
|
+
// ({1}{1}25.000), else 23.976.
|
|
356
|
+
function parseFramed(text) {
|
|
357
|
+
var lines = text.split('\n'), cues = [], skip = skipper(), fps = 23.976, re = /^\s*\{(\d+)\}\{(\d*)\}(.*)$/;
|
|
358
|
+
for (var i = 0; i < lines.length && cues.length < CUES_MAX; i++) {
|
|
359
|
+
var m = re.exec(lines[i]);
|
|
360
|
+
if (!m) { continue; }
|
|
361
|
+
var rate = /^\s*(\d{1,3}(?:\.\d+)?)\s*$/.exec(m[3]);
|
|
362
|
+
if (!cues.length && rate && +rate[1] >= 10 && +rate[1] <= 120 && +m[1] <= 1) { fps = +rate[1]; continue; }
|
|
363
|
+
var body = m[3].slice(0, CUE_TEXT_MAX), st = {}, code;
|
|
364
|
+
while ((code = /^\s*\{([a-zA-Z]):([^}]*)\}/.exec(body))) {
|
|
365
|
+
var k = code[1].toLowerCase(), v = code[2].toLowerCase();
|
|
366
|
+
if (k === 'y') { st.i = v.indexOf('i') !== -1; st.b = v.indexOf('b') !== -1; st.u = v.indexOf('u') !== -1; }
|
|
367
|
+
else if (k === 'c') { var hx = /\$?([0-9a-f]{6})/.exec(v); if (hx) { st.c = '#' + hx[1].slice(4, 6) + hx[1].slice(2, 4) + hx[1].slice(0, 2); } }
|
|
368
|
+
body = body.slice(code[0].length);
|
|
369
|
+
}
|
|
370
|
+
var start = +m[1] / fps, end = m[2] !== '' ? +m[2] / fps : start + 3;
|
|
371
|
+
var cue = makeCue(start, end, slashRuns(body, st), skip);
|
|
372
|
+
if (cue) { cues.push(cue); }
|
|
254
373
|
}
|
|
255
|
-
cues.sort(function (a, b) { return a.start - b.start; });
|
|
256
374
|
return cues;
|
|
257
375
|
}
|
|
376
|
+
// MPL2 (.txt): [start][end] in tenths of a second.
|
|
377
|
+
function parseMpl2(text) {
|
|
378
|
+
var lines = text.split('\n'), cues = [], skip = skipper(), re = /^\s*\[(\d+)\]\[(\d*)\](.*)$/;
|
|
379
|
+
for (var i = 0; i < lines.length && cues.length < CUES_MAX; i++) {
|
|
380
|
+
var m = re.exec(lines[i]);
|
|
381
|
+
if (!m) { continue; }
|
|
382
|
+
var start = +m[1] / 10, end = m[2] !== '' ? +m[2] / 10 : start + 3;
|
|
383
|
+
var cue = makeCue(start, end, slashRuns(m[3].slice(0, CUE_TEXT_MAX), {}), skip);
|
|
384
|
+
if (cue) { cues.push(cue); }
|
|
385
|
+
}
|
|
386
|
+
return cues;
|
|
387
|
+
}
|
|
388
|
+
// TMPlayer (.txt): hh:mm:ss:text, no end: each line until the next, TMP_MAX seconds at most.
|
|
389
|
+
var TMP_MAX = 5;
|
|
390
|
+
function parseTmp(text) {
|
|
391
|
+
var lines = text.split('\n'), marks = [], skip = skipper(), re = /^\s*(\d{1,2}):(\d{2}):(\d{2})[:=](.*)$/, cues = [];
|
|
392
|
+
for (var i = 0; i < lines.length && marks.length < CUES_MAX; i++) {
|
|
393
|
+
var m = re.exec(lines[i]);
|
|
394
|
+
if (m) { marks.push({ at: (+m[1]) * 3600 + (+m[2]) * 60 + (+m[3]), body: m[4].slice(0, CUE_TEXT_MAX) }); }
|
|
395
|
+
}
|
|
396
|
+
for (var j = 0; j < marks.length; j++) {
|
|
397
|
+
var next = j + 1 < marks.length ? marks[j + 1].at : Infinity;
|
|
398
|
+
var cue = makeCue(marks[j].at, Math.min(next, marks[j].at + TMP_MAX), slashRuns(marks[j].body, {}), skip);
|
|
399
|
+
if (cue) { cues.push(cue); }
|
|
400
|
+
}
|
|
401
|
+
return cues;
|
|
402
|
+
}
|
|
403
|
+
// ASS / SSA: its Dialogue lines, with each line's style (its color, bold, italic, underline) and
|
|
404
|
+
// the overrides in it ({\i1} {\b1} {\u1} {\c&HBBGGRR&} {\r}); drawings ({\p1}) and positions left out.
|
|
405
|
+
function assColor(x) {
|
|
406
|
+
x = ('' + (x || '')).trim();
|
|
407
|
+
var v = /^&h/i.test(x) ? parseInt(x.replace(/^&h/i, '').replace(/&$/, ''), 16) : parseInt(x, 10);
|
|
408
|
+
if (isNaN(v)) { return ''; }
|
|
409
|
+
var hex = function (n) { return ('0' + n.toString(16)).slice(-2); };
|
|
410
|
+
var c = '#' + hex(v & 0xFF) + hex((v >> 8) & 0xFF) + hex((v >> 16) & 0xFF);
|
|
411
|
+
return c === '#ffffff' ? '' : c; // (white: a file's usual color, yours shown instead)
|
|
412
|
+
}
|
|
413
|
+
function assTime(s) {
|
|
414
|
+
var m = /^\s*(\d+):(\d{2}):(\d{2})[.:](\d{1,3})\s*$/.exec(s || '');
|
|
415
|
+
return m ? (+m[1]) * 3600 + (+m[2]) * 60 + (+m[3]) + +((m[4] + '00').slice(0, 3)) / 1000 : null;
|
|
416
|
+
}
|
|
417
|
+
function parseAss(text) {
|
|
418
|
+
var lines = text.split('\n'), sect = '', sFmt = null, eFmt = null, styles = {}, cues = [], skip = skipper();
|
|
419
|
+
function on(v) { v = ('' + (v || '')).trim(); return v !== '' && v !== '0'; }
|
|
420
|
+
function fields(rest, fmt) {
|
|
421
|
+
var parts = rest.split(','), f = {}, n = fmt.length;
|
|
422
|
+
if (parts.length < n) { return null; }
|
|
423
|
+
for (var k = 0; k < n - 1; k++) { f[fmt[k]] = parts[k].trim(); }
|
|
424
|
+
f[fmt[n - 1]] = parts.slice(n - 1).join(',');
|
|
425
|
+
return f;
|
|
426
|
+
}
|
|
427
|
+
for (var i = 0; i < lines.length && cues.length < CUES_MAX; i++) {
|
|
428
|
+
var l = lines[i], h = /^\s*\[([^\]]+)\]\s*$/.exec(l), m;
|
|
429
|
+
if (h) { sect = h[1].toLowerCase(); continue; }
|
|
430
|
+
if ((m = /^\s*format\s*:\s*(.*)$/i.exec(l))) {
|
|
431
|
+
var fmt = m[1].split(',').map(function (x) { return x.trim().toLowerCase(); });
|
|
432
|
+
if (/styles/.test(sect)) { sFmt = fmt; } else if (sect === 'events') { eFmt = fmt; }
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if ((m = /^\s*style\s*:\s*(.*)$/i.exec(l)) && sFmt) {
|
|
436
|
+
var s = fields(m[1], sFmt);
|
|
437
|
+
if (s) { styles[(s.name || '').toLowerCase()] = { i: on(s.italic), b: on(s.bold), u: on(s.underline), c: assColor(s.primarycolour || s.primarycolor) }; }
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (!(m = /^\s*dialogue\s*:\s*(.*)$/i.exec(l))) { continue; }
|
|
441
|
+
var f = fields(m[1], eFmt || ['layer', 'start', 'end', 'style', 'name', 'marginl', 'marginr', 'marginv', 'effect', 'text']);
|
|
442
|
+
if (!f) { continue; }
|
|
443
|
+
var start = assTime(f.start), end = assTime(f.end);
|
|
444
|
+
if (start === null || end === null) { continue; }
|
|
445
|
+
var cue = makeCue(start, end, assRuns(('' + (f.text || '')).slice(0, CUE_TEXT_MAX * 2), styles, (f.style || '').replace(/^\*/, '').toLowerCase()), skip);
|
|
446
|
+
if (cue) { cues.push(cue); }
|
|
447
|
+
}
|
|
448
|
+
return cues;
|
|
449
|
+
}
|
|
450
|
+
function assRuns(t, styles, name) {
|
|
451
|
+
var base = styles[name] || styles['default'] || {}, st = runOf('', base), runs = [], draw = false, i = 0, n = t.length;
|
|
452
|
+
function add(s) {
|
|
453
|
+
if (!s || draw) { return; }
|
|
454
|
+
runs.push(runOf(s.replace(/\\[Nn]/g, '\n').replace(/\\h/g, ' '), st));
|
|
455
|
+
}
|
|
456
|
+
while (i < n) {
|
|
457
|
+
var ob = t.indexOf('{', i);
|
|
458
|
+
if (ob === -1) { add(t.slice(i)); break; }
|
|
459
|
+
add(t.slice(i, ob));
|
|
460
|
+
var cb = t.indexOf('}', ob + 1);
|
|
461
|
+
if (cb === -1) { break; }
|
|
462
|
+
var block = t.slice(ob + 1, cb), re = /\\(1c|c|[ibu]|r|p)([^\\]*)/g, m;
|
|
463
|
+
i = cb + 1;
|
|
464
|
+
while ((m = re.exec(block))) {
|
|
465
|
+
var k = m[1], v = m[2].trim();
|
|
466
|
+
if (k === 'i' || k === 'u') { if (/^[01]$/.test(v)) { st[k] = v === '1'; } }
|
|
467
|
+
else if (k === 'b') { if (/^\d+$/.test(v)) { st.b = v === '1' || +v >= 600; } }
|
|
468
|
+
else if (k === 'c' || k === '1c') { var c = /^&?h([0-9a-f]{1,8})&?$/i.exec(v); if (c || !v) { st.c = c ? assColor('&H' + c[1]) : base.c; } } // (\c alone: the style's; \clip isn't a color)
|
|
469
|
+
else if (k === 'r') { var to = (v && styles[v.toLowerCase()]) || base; st = runOf('', to); }
|
|
470
|
+
else if (k === 'p') { draw = /^\d+$/.test(v) && +v > 0; }
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return runs;
|
|
474
|
+
}
|
|
258
475
|
|
|
476
|
+
// Lines that overlap (dialogue and a sign) show together, up to SHOW_MAX, the earliest first.
|
|
477
|
+
var SHOW_MAX = 4;
|
|
259
478
|
function renderSubs() {
|
|
260
479
|
if (_embQueue.length) { flushEmbQueue(); }
|
|
261
480
|
renderSecond();
|
|
262
481
|
if (!_subOn || !_cues) { return; }
|
|
263
482
|
var t = S.cur - _subDelay; // timing adjustment: + shows later, − earlier
|
|
264
|
-
var show = '';
|
|
483
|
+
var show = [], key = '';
|
|
265
484
|
// Skip the prefix of cues that already ended (they can't show again unless we go
|
|
266
|
-
// back in time, which resets the index), then scan as before. Same
|
|
485
|
+
// back in time, which resets the index), then scan as before. Same cues as a full
|
|
267
486
|
// scan from 0, without walking the whole list late in a movie on every tick.
|
|
487
|
+
// (A long cue keeps the index at it: those after it that ended are passed over below.)
|
|
268
488
|
if (t < _cueT) { _cueIdx = 0; }
|
|
269
489
|
_cueT = t;
|
|
270
490
|
while (_cueIdx < _cues.length && _cues[_cueIdx].end < t) { _cueIdx++; }
|
|
271
|
-
for (var i = _cueIdx; i < _cues.length; i++) {
|
|
272
|
-
if (_cues[i].start <= t && t <= _cues[i].end) { show = _cues[i].text; break; }
|
|
491
|
+
for (var i = _cueIdx; i < _cues.length && show.length < SHOW_MAX; i++) {
|
|
273
492
|
if (_cues[i].start > t) { break; }
|
|
493
|
+
if (t <= _cues[i].end) { show.push(_cues[i]); key += i + ','; }
|
|
274
494
|
}
|
|
275
|
-
if (show) {
|
|
495
|
+
if (show.length) {
|
|
276
496
|
S.subsEl.className = '';
|
|
277
497
|
var span = S.subsEl.firstChild;
|
|
278
498
|
if (!span) { span = document.createElement('span'); S.subsEl.appendChild(span); styleSpan(span); }
|
|
279
|
-
|
|
499
|
+
key += P.subCfgVersion ? P.subCfgVersion() : '';
|
|
500
|
+
if (span.__cues !== key || span.__list !== _cues) { drawCues(span, show); span.__cues = key; span.__list = _cues; } // (drawn again only when what shows changes)
|
|
280
501
|
} else {
|
|
281
502
|
S.subsEl.className = 'hidden';
|
|
282
503
|
}
|
|
283
504
|
}
|
|
505
|
+
// The line's text, from its cues: each its own line; a styled cue's pieces each their own span,
|
|
506
|
+
// written as text (textContent: never markup). The file's colors only with Subtitles ›
|
|
507
|
+
// Appearance › The file's colors On (else yours: the line's own color).
|
|
508
|
+
function drawCues(span, cues) {
|
|
509
|
+
var colors = getSubCfg().fileColors === 'on';
|
|
510
|
+
U.clear(span);
|
|
511
|
+
cues.forEach(function (cue, k) {
|
|
512
|
+
var runs = (k ? [{ t: '\n' }] : []).concat(cue.runs || [{ t: cue.text }]); // (each cue its own line: the break unstyled)
|
|
513
|
+
runs.forEach(function (r) {
|
|
514
|
+
var piece = document.createElement('span');
|
|
515
|
+
piece.textContent = r.t;
|
|
516
|
+
if (r.i) { piece.style.fontStyle = 'italic'; }
|
|
517
|
+
if (r.b) { piece.style.fontWeight = 'bold'; }
|
|
518
|
+
if (r.u) { piece.style.textDecoration = 'underline'; }
|
|
519
|
+
if (r.c && colors) { piece.style.color = r.c; }
|
|
520
|
+
span.appendChild(piece);
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
}
|
|
284
524
|
|
|
285
525
|
// Each choice (a track, Off, a built-in one) is a new one: a download still on its way
|
|
286
526
|
// for an earlier choice is dropped when it comes, without a word (_subGen).
|
|
@@ -440,16 +680,25 @@
|
|
|
440
680
|
var w = _embWant; _embWant = null;
|
|
441
681
|
if (!w || _subOn) { return; } // an addon track was chosen meanwhile
|
|
442
682
|
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)
|
|
685
|
+
var own = P.fileTracks ? P.fileTracks('subs', tracks) : null;
|
|
686
|
+
function best(match) {
|
|
687
|
+
var c = tracks.filter(match);
|
|
688
|
+
if (!own || c.length < 2) { return c[0] || null; }
|
|
689
|
+
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];
|
|
691
|
+
}
|
|
443
692
|
if (w.index != null) {
|
|
444
693
|
pick = tracks.find(function (t) { return t.index === w.index && (!key || langKey(textLang(t)) === key); }) || null;
|
|
445
694
|
}
|
|
446
|
-
if (!pick && key) { pick =
|
|
695
|
+
if (!pick && key) { pick = best(function (t) { return langMatches(key, textLang(t)); }); }
|
|
447
696
|
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)
|
|
448
697
|
if (!pick && w.lang2) { // nothing in the default language anywhere: the second choice, a track to download first
|
|
449
698
|
var key2 = langKey(w.lang2);
|
|
450
699
|
var dl = _subTracks.find(function (t) { return langMatches(key2, t.lang); });
|
|
451
700
|
if (dl) { loadTrack(dl); return; }
|
|
452
|
-
pick =
|
|
701
|
+
pick = best(function (t) { return langMatches(key2, textLang(t)); });
|
|
453
702
|
}
|
|
454
703
|
if (pick) { selectEmbeddedSub(pick); _embNudge = { index: pick.index, at: Date.now() + EMB_NUDGE_MS }; }
|
|
455
704
|
}
|
|
@@ -512,7 +761,7 @@
|
|
|
512
761
|
S.subsEl.className = '';
|
|
513
762
|
var span = S.subsEl.firstChild;
|
|
514
763
|
if (!span) { span = document.createElement('span'); S.subsEl.appendChild(span); styleSpan(span); }
|
|
515
|
-
span.textContent = t;
|
|
764
|
+
span.textContent = t; span.__list = null;
|
|
516
765
|
_embTimer = setTimeout(function () { S.subsEl.className = 'hidden'; }, Math.max(500, (+duration) || 3000));
|
|
517
766
|
}
|
|
518
767
|
|
|
@@ -685,9 +934,10 @@
|
|
|
685
934
|
run: function () { closeMenu(); rememberSub(S.ctx.id, { embedded: true, nth: x.n, lang: c.lang }); P.ccOn(c); } };
|
|
686
935
|
}
|
|
687
936
|
if (x.emb) {
|
|
688
|
-
var tr = x.emb, l = textLang(tr);
|
|
937
|
+
var tr = x.emb, l = textLang(tr), own = P.fileTrack ? P.fileTrack('subs', getTextTracks(), x.n) : null;
|
|
689
938
|
if (_embSub === tr.index) { idx = i; }
|
|
690
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,
|
|
940
|
+
detail: own && P.fileTrackNote ? P.fileTrackNote(own) || undefined : undefined, // (its own name and marks, from the file's header)
|
|
691
941
|
run: function () {
|
|
692
942
|
_embDelay = 0; _embQueue = []; _embNudge = null; selectEmbeddedSub(tr); rememberSub(S.ctx.id, { embedded: true, index: tr.index, lang: l });
|
|
693
943
|
if (menuOpen()) { replaceTop(langTracksMenu(key, list)); }
|
|
@@ -770,7 +1020,7 @@
|
|
|
770
1020
|
}
|
|
771
1021
|
P.activeSub = activeSub;
|
|
772
1022
|
P.subsKey = subsKey;
|
|
773
|
-
P.fileHints = fileHints; P.parseCues = parseCues; P.loadTrack = loadTrack; P.subsOff = subsOff;
|
|
1023
|
+
P.fileHints = fileHints; P.parseCues = parseCues; P.drawCues = drawCues; P.loadTrack = loadTrack; P.subsOff = subsOff;
|
|
774
1024
|
P.resetSubs = resetSubs; P.closeSubs = closeSubs; P.startSubtitles = startSubtitles;
|
|
775
1025
|
P.subsBeforeOpen = subsBeforeOpen; P.subsOnTick = subsOnTick; P.subtitleSummary = subtitleSummary;
|
|
776
1026
|
P.wantEmbedded = wantEmbedded;
|