stremiok 2.2.9 → 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;
@@ -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);
@@ -1020,8 +1035,15 @@ var PlayerParts = {};
1020
1035
  if (S.cur >= end - PREFETCH_LEAD) { _prefetchedNext = true; try { S.ctx.prefetchNext(); } catch (e) {} }
1021
1036
  }
1022
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
+ }
1023
1044
  function onProgress() {
1024
1045
  maybePrefetchNext();
1046
+ jfTell('progress');
1025
1047
  // The bar is redrawn on every time update only while it's on screen (showOSD
1026
1048
  // brings it up to date when it appears); hidden, it would just be wasted layout work.
1027
1049
  if (!osdHidden() || scrubbing()) { renderOSD(); }
@@ -1122,6 +1144,7 @@ var PlayerParts = {};
1122
1144
  // way (stopped past 85%: a finished scrobble), so not as a separate "watched" too.
1123
1145
  function markFinished(quiet) {
1124
1146
  setWatched(S.ctx.type, S.ctx.id, true, quiet); // (and to Trakt, when connected)
1147
+ jfTell('watched');
1125
1148
  removeProgress(S.ctx.type, S.ctx.id);
1126
1149
  if (S.ctx.nextEpisode && !(S.ctx.nextEpisode.airs > Date.now())) { // (not one that hasn't aired)
1127
1150
  var ne = S.ctx.nextEpisode;
@@ -1140,7 +1163,7 @@ var PlayerParts = {};
1140
1163
  return S.videoEl.paused;
1141
1164
  }
1142
1165
  function play_() { if (useAV) { try { avplay.play(); } catch (e) {} } else { S.videoEl.play(); } screenSaver(false); }
1143
- 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); }
1144
1167
 
1145
1168
  // The TV's screensaver stays off while a video plays and is allowed again when it's
1146
1169
  // paused or stopped. No-op where the Samsung appcommon API isn't available.
@@ -1549,6 +1572,7 @@ var PlayerParts = {};
1549
1572
  if (U.crumb) { U.crumb('player closed'); }
1550
1573
  if (P.sleepClear) { P.sleepClear(); } // (the sleep timer: this playback's)
1551
1574
  saveProgress();
1575
+ jfTell('stop');
1552
1576
  // Record partial progress to Trakt (unfinished VOD) so it shows in Continue Watching. Past
1553
1577
  // 85% (Trakt connected): finished, Trakt's way (it marks it watched), and here as at the credits.
1554
1578
  if (!S.isLive && !_creditsHandled && S.ctx && !S.ctx.trailer && !S.ctx.private && !isNotice() && S.cur > 60 && typeof Trakt !== 'undefined' && Trakt.onProgress) {