stremiok 2.2.8 → 2.3.0

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.
@@ -225,7 +225,7 @@
225
225
  function renderScrub() {
226
226
  var mark = U.byId('osd-scrub'), range = U.byId('osd-scrub-range'), tip = U.byId('osd-scrub-time');
227
227
  if (!mark || !range || !tip) { return; }
228
- if (!_scrub || !(S.dur > 0)) { mark.className = 'hidden'; range.className = 'hidden'; return; }
228
+ if (!_scrub || !(S.dur > 0)) { mark.className = 'hidden'; range.className = 'hidden'; scrubPicture(null); return; }
229
229
  var pT = _scrub.target / S.dur * 100, pC = Math.min(100, S.cur / S.dur * 100);
230
230
  mark.className = pT < 8 ? 'edge-l' : (pT > 92 ? 'edge-r' : '');
231
231
  mark.style.left = pT + '%';
@@ -236,6 +236,34 @@
236
236
  var ci = chapterAt(_scrub.target), ch = ci >= 0 ? chapters()[ci].title : ''; // (the chapter it lands in)
237
237
  if (ch.length > 40) { ch = ch.slice(0, 39) + '…'; }
238
238
  tip.textContent = U.fmtTime(_scrub.target) + ' ' + (d < 0 ? '−' : '+') + U.fmtTime(Math.abs(d)) + (ch ? ' · ' + ch : '');
239
+ scrubPicture(_scrub.target);
240
+ }
241
+ // A Jellyfin file's seek picture above the marker (its trickplay: a tile of 10 × 10, the one
242
+ // under the marker shown by moving the tile behind a 320-wide window).
243
+ var _picTile = '', _picAhead = [];
244
+ function scrubPicture(sec) {
245
+ var pic = U.byId('osd-scrub-pic'), jf = S.ctx && S.ctx.stream && S.ctx.stream._jf;
246
+ var at = (sec != null && jf && jf.tp && typeof Jellyfin !== 'undefined' && Jellyfin.trickplayAt) ? Jellyfin.trickplayAt(jf.tp, sec) : null;
247
+ if (!pic) { return; }
248
+ if (!at) { pic.className = 'hidden'; return; }
249
+ var scale = 320 / at.w;
250
+ pic.className = '';
251
+ pic.style.width = '320px';
252
+ pic.style.height = Math.round(at.h * scale) + 'px';
253
+ if (_picTile !== at.url) { _picTile = at.url; pic.style.backgroundImage = 'url("' + at.url + '")'; }
254
+ // (the tiles either side read ahead: moving into one shows it at once, not black first)
255
+ var span = jf.tp.cols * jf.tp.rows * jf.tp.every / 1000;
256
+ [sec - span, sec + span].forEach(function (t) {
257
+ var near = t >= 0 ? Jellyfin.trickplayAt(jf.tp, t) : null;
258
+ if (!near || typeof Image === 'undefined' || _picAhead.some(function (im) { return im.__url === near.url; })) { return; }
259
+ var im = new Image();
260
+ im.__url = near.url;
261
+ im.src = near.url;
262
+ _picAhead.push(im);
263
+ if (_picAhead.length > 4) { _picAhead.shift(); } // (kept: the last few, so they stay decoded)
264
+ });
265
+ pic.style.backgroundSize = Math.round(at.cols * at.w * scale) + 'px ' + Math.round(at.rows * at.h * scale) + 'px';
266
+ pic.style.backgroundPosition = '-' + Math.round(at.x * scale) + 'px -' + Math.round(at.y * scale) + 'px';
239
267
  }
240
268
 
241
269
  // ---------- in-player menu (stack of levels) ----------
package/js/player-core.js CHANGED
@@ -214,8 +214,13 @@ var PlayerParts = {};
214
214
  function hideOSD() { U.byId('player-osd').className = 'hidden'; liftSubs(0); }
215
215
  function osdHidden() { return U.byId('player-osd').className.indexOf('hidden') !== -1; }
216
216
 
217
- // ---------- chapters (a YouTube video's, from the service: S.ytInfo.chapters) ----------
218
- function chapters() { return (!S.isLive && S.ytInfo && S.ytInfo.chapters) || []; }
217
+ // ---------- chapters (a YouTube video's, from the service: S.ytInfo.chapters; a Jellyfin
218
+ // file's named ones: its source's _jf.chapters) ----------
219
+ function chapters() {
220
+ if (S.isLive) { return []; }
221
+ var jf = S.ctx && S.ctx.stream && S.ctx.stream._jf;
222
+ return (S.ytInfo && S.ytInfo.chapters) || (jf && Array.isArray(jf.chapters) ? jf.chapters : []);
223
+ }
219
224
  // The chapter playing at `sec`: its index, or -1 (no chapters, or before the first).
220
225
  function chapterAt(sec) {
221
226
  var list = chapters(), at = -1;
@@ -396,7 +401,7 @@ var PlayerParts = {};
396
401
  // is what's learned from it (s.stream, through ctx.learnFor); the title, its episodes and
397
402
  // whether it's private stay.
398
403
  var SOURCE_FIELDS = ['url', 'variantUrl', 'initialQualityHeight', 'yt', 'ytLang', '_headers', 'localSubs', 'localFile', 'subExtra', 'sourceSubs', 'formatInfo', 'onStarted', 'onFailed', 'stream',
399
- '_reported', 'fromStart', 'resumeSec', 'switching'];
404
+ '_reported', 'fromStart', 'resumeSec', 'switching', 'viaService', '_relay', '_relayFor', '_relayCc'];
400
405
  // keep: a source that didn't start gives way to the next (nextSourceOnFail): the same place to
401
406
  // resume, and Play from the start as it was.
402
407
  function replaceSource(s, keep) {
@@ -439,6 +444,14 @@ var PlayerParts = {};
439
444
  if (S.isLive) { vodCheck(ctx); } // (one whose manifest says it's a film: not live after all)
440
445
  formatStart(ctx);
441
446
  S.ctx.resumeSec = (ctx.trailer || ctx.fromStart) ? 0 : (ctx.resumeSec || getResume(ctx.type, ctx.id)); // (Play from start: 0:00)
447
+ // (a Jellyfin source: where Jellyfin last had it, when that's later than StremioK's place)
448
+ if (!ctx.trailer && !ctx.fromStart && !ctx.switching && ctx.stream && ctx.stream._jf && typeof Jellyfin !== 'undefined' && Jellyfin.resumeFor) {
449
+ var jfAt = Jellyfin.resumeFor(ctx.stream._jf, P.progressFor ? P.progressFor(ctx.type, ctx.id) : null, S.ctx.resumeSec);
450
+ if (jfAt !== S.ctx.resumeSec) {
451
+ S.ctx.resumeSec = jfAt;
452
+ if (jfAt > 5) { U.toast('Carrying on from where ' + (Jellyfin.sourceKind ? Jellyfin.sourceKind(ctx.stream._jf) : 'Jellyfin') + ' had it: ' + U.fmtTime(jfAt), 3500); }
453
+ }
454
+ }
442
455
 
443
456
  // reset subtitle + audio + quality + on-screen controls state
444
457
  resetSubs();
@@ -529,7 +542,9 @@ var PlayerParts = {};
529
542
  if (!ctx || ctx.trailer || S.isLive || !(S.dur > 0) || _segmentsFor === ctx) { return; }
530
543
  _segmentsFor = ctx;
531
544
  var dur = S.dur, asked = [];
532
- Stremio.getIntroSegments(ctx.type, ctx.id, Math.round(dur * 1000), asked, ctx.titleIds).then(function (seg) {
545
+ // (a Jellyfin source: its server's own media segments first, the services fill the rest)
546
+ var own = (ctx.stream && ctx.stream._jf && typeof Jellyfin !== 'undefined' && Jellyfin.segments) ? Jellyfin.segments(ctx.stream._jf, asked) : Promise.resolve(null);
547
+ own.then(function (start) { return Stremio.getIntroSegments(ctx.type, ctx.id, Math.round(dur * 1000), asked, ctx.titleIds, start); }).then(function (seg) {
533
548
  if (!S.active || S.ctx !== ctx) { return; }
534
549
  var notes = [];
535
550
  _segments = checkedSegments(seg, S.dur || dur, notes);
@@ -881,6 +896,28 @@ var PlayerParts = {};
881
896
  else { shakaStop(); try { S.videoEl.pause(); S.videoEl.removeAttribute('src'); } catch (e2) {} S.videoEl.className = ''; }
882
897
  useAV = av; P.useAV = av;
883
898
  }
899
+ // A key server, and a DASH manifest naming only other systems (Widevine, PlayReady): Shaka asks
900
+ // a key server only for a system the manifest names (else its error 6012), so ClearKey is
901
+ // named after each group of them, its key ids the manifest's own (their default_KID). One
902
+ // naming it already (or its common key-id system), an HLS playlist: as they are.
903
+ var CK_URI = 'urn:uuid:e2719d58-a985-b3c9-781a-b030af78d30e';
904
+ var CP_RUN = /(?:<((?:[\w.-]+:)?)ContentProtection\b[^>]*?(?:\/>|>[\s\S]*?<\/(?:[\w.-]+:)?ContentProtection>)\s*)+/g;
905
+ var CK_NAMED = /e2719d58-a985-b3c9-781a-b030af78d30e|1077efec-c0b2-4d02-ace3-3c1e52e2fb4b/i;
906
+ function ckNamed(text) {
907
+ if (!/<(?:[\w.-]+:)?MPD\b/.test(text) || CK_NAMED.test(text)) { return text; }
908
+ return text.replace(CP_RUN, function (run, pre) { return run + '<' + pre + 'ContentProtection schemeIdUri="' + CK_URI + '" value="ClearKey1.0"/>'; });
909
+ }
910
+ function ckManifests(pl) {
911
+ var said = false, SU = shaka.util && shaka.util.StringUtils;
912
+ if (!SU) { return; }
913
+ pl.getNetworkingEngine().registerResponseFilter(function (type, resp) {
914
+ if (type !== shaka.net.NetworkingEngine.RequestType.MANIFEST || !resp || !resp.data) { return; }
915
+ var text = SU.fromUTF8(resp.data), out = ckNamed(text);
916
+ if (out === text) { return; }
917
+ resp.data = SU.toUTF8(out);
918
+ if (!said) { said = true; U.log('player', 'ClearKey named in the manifest beside its other DRM, for the playlist’s key server'); }
919
+ });
920
+ }
884
921
  function shakaLoadInto(url, drm, token, fail) {
885
922
  loadShaka().then(function () {
886
923
  if (!S.active || token !== _playToken) { return; }
@@ -890,6 +927,7 @@ var PlayerParts = {};
890
927
  var pl = _shakaPl = new shaka.Player(), cfg = { streaming: { bufferingGoal: 10 } };
891
928
  cfg.drm = drm.keys ? { clearKeys: drm.keys } : { servers: { 'org.w3.clearkey': drm.url } };
892
929
  pl.configure(cfg);
930
+ if (!drm.keys) { ckManifests(pl); }
893
931
  var h = drm.h || {};
894
932
  if (!drm.keys && Object.keys(h).length) { // (the key server's own headers: those a page may send)
895
933
  pl.getNetworkingEngine().registerRequestFilter(function (type, req) {
@@ -997,8 +1035,15 @@ var PlayerParts = {};
997
1035
  if (S.cur >= end - PREFETCH_LEAD) { _prefetchedNext = true; try { S.ctx.prefetchNext(); } catch (e) {} }
998
1036
  }
999
1037
 
1038
+ // A Jellyfin server's file: what you play told to it (Jellyfin.onPlayer: progress, pause,
1039
+ // stop, watched; never during private viewing).
1040
+ function jfTell(ev) {
1041
+ if (!S.ctx || !S.ctx.stream || !S.ctx.stream._jf || typeof Jellyfin === 'undefined' || !Jellyfin.onPlayer) { return; }
1042
+ try { Jellyfin.onPlayer(ev, S.ctx, S.cur, S.dur, ev === 'pause' || (ev === 'progress' && isPaused())); } catch (e) {}
1043
+ }
1000
1044
  function onProgress() {
1001
1045
  maybePrefetchNext();
1046
+ jfTell('progress');
1002
1047
  // The bar is redrawn on every time update only while it's on screen (showOSD
1003
1048
  // brings it up to date when it appears); hidden, it would just be wasted layout work.
1004
1049
  if (!osdHidden() || scrubbing()) { renderOSD(); }
@@ -1099,6 +1144,7 @@ var PlayerParts = {};
1099
1144
  // way (stopped past 85%: a finished scrobble), so not as a separate "watched" too.
1100
1145
  function markFinished(quiet) {
1101
1146
  setWatched(S.ctx.type, S.ctx.id, true, quiet); // (and to Trakt, when connected)
1147
+ jfTell('watched');
1102
1148
  removeProgress(S.ctx.type, S.ctx.id);
1103
1149
  if (S.ctx.nextEpisode && !(S.ctx.nextEpisode.airs > Date.now())) { // (not one that hasn't aired)
1104
1150
  var ne = S.ctx.nextEpisode;
@@ -1117,7 +1163,7 @@ var PlayerParts = {};
1117
1163
  return S.videoEl.paused;
1118
1164
  }
1119
1165
  function play_() { if (useAV) { try { avplay.play(); } catch (e) {} } else { S.videoEl.play(); } screenSaver(false); }
1120
- function pause_() { _pausedOnce = true; if (useAV) { try { avplay.pause(); } catch (e) {} } else { S.videoEl.pause(); } screenSaver(true); }
1166
+ function pause_() { _pausedOnce = true; jfTell('pause'); if (useAV) { try { avplay.pause(); } catch (e) {} } else { S.videoEl.pause(); } screenSaver(true); }
1121
1167
 
1122
1168
  // The TV's screensaver stays off while a video plays and is allowed again when it's
1123
1169
  // paused or stopped. No-op where the Samsung appcommon API isn't available.
@@ -1345,7 +1391,32 @@ var PlayerParts = {};
1345
1391
  ctx._relay = r.url; ctx._relayFor = ctx.url; ctx._relayCc = cc || null; ctx._ccOffer = cc ? null : ctx._ccOffer;
1346
1392
  return true;
1347
1393
  }
1394
+ // HLS through StremioK's service (Settings › Playback › Seeking & buffering: 'off' | 'headers':
1395
+ // sources with their own User-Agent, Referer or Cookie | 'all'; or ctx.viaService, hold OK on a
1396
+ // source): the relay without the look, so every playlist and piece is fetched with the source's
1397
+ // headers (the TV's player can't always send them). A film's relay keeps every link (film=1).
1398
+ // Not YouTube, DRM, USB files or the service's own links; the service not answering: as it is.
1399
+ var HLS_LINK = /\.m3u8?(?:[?#]|$)/i;
1400
+ function viaService(ctx) {
1401
+ if (!useAV || !ctx || ctx.yt || ctx.trailer || ctx.localFile || (ctx.stream && ctx.stream._drm)) { return false; }
1402
+ if (typeof YTPlay === 'undefined' || !YTPlay.liveOpen || YTPlay.installMode() === 'browser') { return false; }
1403
+ var url = ctx.url || '';
1404
+ if (!/^https?:\/\//i.test(url) || /^http:\/\/(localhost|127\.0\.0\.1)[:\/]/i.test(url)) { return false; }
1405
+ if (!HLS_LINK.test(url) && !(ctx.formatInfo && ctx.formatInfo.container === 'hls')) { return false; }
1406
+ if (ctx.viaService) { return true; }
1407
+ var mode = P.playerCfg().hls;
1408
+ return mode === 'all' || (mode === 'headers' && !!U.sanitizeHeaders(ctx._headers));
1409
+ }
1410
+ function startViaService(ctx, settle) {
1411
+ var live = !!S.isLive, known = live && liveFixable(ctx) ? liveKnown(ctx.url) : null;
1412
+ YTPlay.liveOpen(ctx.url, ctx._headers, true, { fix: !!(known && known.fix), film: !live }).then(function (r) {
1413
+ if (S.ctx !== ctx || !S.active) { return; }
1414
+ relayed(ctx, r, null);
1415
+ startAV(ctx.url, settle);
1416
+ }, function () { if (S.ctx === ctx && S.active) { startAV(ctx.url, settle); } });
1417
+ }
1348
1418
  function startLive(ctx, settle) {
1419
+ if (!ctx._relay && viaService(ctx)) { startViaService(ctx, settle); return; }
1349
1420
  var known = liveFixable(ctx) ? liveKnown(ctx.url) : null, cc = ccOf(known);
1350
1421
  if (cc && cc.length) { ctx._ccOffer = cc; }
1351
1422
  var withCc = ccWanted(ctx, cc) ? cc : null;
@@ -1404,7 +1475,7 @@ var PlayerParts = {};
1404
1475
  // The relay didn't start (StremioK's service gone): the channel as it is.
1405
1476
  function relayFailed() {
1406
1477
  if (S.playStarted || !S.ctx || !S.ctx._relay) { return false; }
1407
- U.log('player', 'Live sound relay failed: playing the channel as it is');
1478
+ U.log('player', 'StremioK’s service relay didn’t start: playing the stream as it is');
1408
1479
  S.ctx._relay = null;
1409
1480
  startAV(S.ctx.url);
1410
1481
  return true;
@@ -1501,6 +1572,7 @@ var PlayerParts = {};
1501
1572
  if (U.crumb) { U.crumb('player closed'); }
1502
1573
  if (P.sleepClear) { P.sleepClear(); } // (the sleep timer: this playback's)
1503
1574
  saveProgress();
1575
+ jfTell('stop');
1504
1576
  // Record partial progress to Trakt (unfinished VOD) so it shows in Continue Watching. Past
1505
1577
  // 85% (Trakt connected): finished, Trakt's way (it marks it watched), and here as at the credits.
1506
1578
  if (!S.isLive && !_creditsHandled && S.ctx && !S.ctx.trailer && !S.ctx.private && !isNotice() && S.cur > 60 && typeof Trakt !== 'undefined' && Trakt.onProgress) {
@@ -248,7 +248,8 @@
248
248
  return { aspect: d.aspect || 'fit', seek: SEEK_STEPS.indexOf(+d.seek) !== -1 ? +d.seek : 10,
249
249
  buffer: d.buffer === 'more' || d.buffer === 'most' ? d.buffer : 'normal',
250
250
  reconnect: d.reconnect === 'off' || d.reconnect === 'always' ? d.reconnect : 'few',
251
- phone: d.phone === 'infuse' || d.phone === 'link' ? d.phone : 'vlc' }; // (Continue on phone: what the QR opens)
251
+ phone: d.phone === 'infuse' || d.phone === 'link' ? d.phone : 'vlc', // (Continue on phone: what the QR opens)
252
+ hls: d.hls === 'headers' || d.hls === 'all' ? d.hls : 'off' }; // (HLS through StremioK's service: see player-core's viaService)
252
253
  }
253
254
  function setPlayerCfg(cfg) { // (what's given changes; the rest stays)
254
255
  var d = U.store.get(PLAYERCFG_KEY, {}) || {};