@stremio/stremio-video 0.0.51 → 0.0.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stremio/stremio-video",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "description": "Abstraction layer on top of different media players",
5
5
  "author": "Smart Code OOD",
6
6
  "main": "src/index.js",
@@ -20,6 +20,8 @@ var stremioToMPVProps = {
20
20
  'subtitlesTracks': 'subtitlesTracks',
21
21
  'selectedSubtitlesTrackId': 'sid',
22
22
  'subtitlesSize': 'sub-scale',
23
+ 'subtitlesOffset': 'sub-pos',
24
+ 'subtitlesDelay': 'sub-delay',
23
25
  'subtitlesTextColor': 'sub-color',
24
26
  'subtitlesBackgroundColor': 'sub-back-color',
25
27
  'subtitlesOutlineColor': 'sub-border-color',
@@ -77,6 +79,7 @@ function ShellVideo(options) {
77
79
  ipc.send('mpv-observe-prop', 'sid');
78
80
  ipc.send('mpv-observe-prop', 'sub-scale');
79
81
  ipc.send('mpv-observe-prop', 'sub-pos');
82
+ ipc.send('mpv-observe-prop', 'sub-delay');
80
83
  ipc.send('mpv-observe-prop', 'speed');
81
84
 
82
85
  ipc.send('mpv-observe-prop', 'mpv-version');
@@ -122,7 +125,6 @@ function ShellVideo(options) {
122
125
  break;
123
126
  }
124
127
  case 'duration': {
125
- setBackground(false);
126
128
  var intDuration = args.data | 0;
127
129
  // Accumulate average duration over time. if it is greater than minClipDuration
128
130
  // and equal to the currently reported duration, it is returned as video length.
@@ -137,7 +139,10 @@ function ShellVideo(options) {
137
139
  // which is around 34 years of playback time.
138
140
  avgDuration = avgDuration ? (avgDuration + intDuration) >> 1 : intDuration;
139
141
  props.loaded = intDuration > 0;
140
- if(props.loaded) onPropChanged('loaded');
142
+ if(props.loaded) {
143
+ setBackground(false);
144
+ onPropChanged('loaded');
145
+ }
141
146
  break;
142
147
  }
143
148
  case 'time-pos': {
@@ -148,6 +153,14 @@ function ShellVideo(options) {
148
153
  props[args.name] = Math.round(args.data / SUBS_SCALE_FACTOR);
149
154
  break;
150
155
  }
156
+ case 'sub-pos': {
157
+ props[args.name] = 100 - args.data;
158
+ break;
159
+ }
160
+ case 'sub-delay': {
161
+ props[args.name] = Math.round(args.data*1000);
162
+ break;
163
+ }
151
164
  case 'paused-for-cache':
152
165
  case 'seeking':
153
166
  {
@@ -304,10 +317,14 @@ function ShellVideo(options) {
304
317
  ipc.send('mpv-set-prop', [stremioToMPVProps[propName], propValue * SUBS_SCALE_FACTOR]);
305
318
  break;
306
319
  }
307
- case 'subtitlesOffset': {
320
+ case 'subtitlesDelay': {
308
321
  ipc.send('mpv-set-prop', [stremioToMPVProps[propName], propValue]);
309
322
  break;
310
323
  }
324
+ case 'subtitlesOffset': {
325
+ ipc.send('mpv-set-prop', [stremioToMPVProps[propName], 100 - propValue]);
326
+ break;
327
+ }
311
328
  case 'subtitlesTextColor':
312
329
  case 'subtitlesBackgroundColor':
313
330
  case 'subtitlesOutlineColor':
@@ -334,6 +351,10 @@ function ShellVideo(options) {
334
351
 
335
352
  ipc.send('mpv-set-prop', ['no-sub-ass']);
336
353
 
354
+ // Hardware decoding
355
+ var hwdecValue = commandArgs.hardwareDecoding ? 'auto-copy' : 'no';
356
+ ipc.send('mpv-set-prop', ['hwdec', hwdecValue]);
357
+
337
358
  // opengl-cb is an alias for the new name "libmpv", as shown in mpv's video/out/vo.c aliases
338
359
  // opengl is an alias for the new name "gpu"
339
360
  // When on Windows we use d3d for the rendering in separate window
@@ -342,7 +363,7 @@ function ShellVideo(options) {
342
363
  var separateWindow = options.mpvSeparateWindow ? 'yes' : 'no';
343
364
  ipc.send('mpv-set-prop', ['vo', videoOutput]);
344
365
  ipc.send('mpv-set-prop', ['osc', separateWindow]);
345
- ipc.send('mpv-set-prop', ['input-defalt-bindings', separateWindow]);
366
+ ipc.send('mpv-set-prop', ['input-default-bindings', separateWindow]);
346
367
  ipc.send('mpv-set-prop', ['input-vo-keyboard', separateWindow]);
347
368
 
348
369
  var startAt = Math.floor(parseInt(commandArgs.time, 10) / 1000) || 0;
@@ -66,6 +66,9 @@ function StremioVideo() {
66
66
  video.on('extraSubtitlesTrackLoaded', function(track) {
67
67
  events.emit('extraSubtitlesTrackLoaded', track);
68
68
  });
69
+ video.on('extraSubtitlesTrackAdded', function(track) {
70
+ events.emit('extraSubtitlesTrackAdded', track);
71
+ });
69
72
  if (Video.manifest.external) {
70
73
  video.on('implementationChanged', function(manifest) {
71
74
  events.emit('implementationChanged', manifest);
@@ -225,15 +225,34 @@ function withHTMLSubtitles(Video) {
225
225
  if (selectedTrack) {
226
226
  selectedTrackId = selectedTrack.id;
227
227
  delay = 0;
228
- function loadSubtitleFromUrl(url, isFallback) {
229
- fetch(url)
230
- .then(function(resp) {
231
- if (resp.ok) {
232
- return resp.text();
233
- }
234
228
 
235
- throw new Error(resp.status + ' (' + resp.statusText + ')');
236
- })
229
+ function getSubtitlesData(track) {
230
+ if (typeof track.url === 'string') {
231
+ return fetch(track.url)
232
+ .then(function(resp) {
233
+ if (resp.ok) {
234
+ return resp.text();
235
+ }
236
+
237
+ throw new Error(resp.status + ' (' + resp.statusText + ')');
238
+ });
239
+ }
240
+
241
+ if (track.buffer instanceof ArrayBuffer) {
242
+ try {
243
+ const uInt8Array = new Uint8Array(track.buffer);
244
+ const text = new TextDecoder().decode(uInt8Array);
245
+ return Promise.resolve(text);
246
+ } catch(e) {
247
+ return Promise.reject(e);
248
+ }
249
+ }
250
+
251
+ return Promise.reject('No `url` or `buffer` field available for this track');
252
+ }
253
+
254
+ function loadSubtitles(track, isFallback) {
255
+ getSubtitlesData(track)
237
256
  .then(function(text) {
238
257
  return subtitlesConverter.convert(text);
239
258
  })
@@ -255,7 +274,7 @@ function withHTMLSubtitles(Video) {
255
274
  }
256
275
 
257
276
  if (!isFallback && typeof selectedTrack.fallbackUrl === 'string') {
258
- loadSubtitleFromUrl(selectedTrack.fallbackUrl, true);
277
+ loadSubtitles(selectedTrack, true);
259
278
  return;
260
279
  }
261
280
 
@@ -266,7 +285,7 @@ function withHTMLSubtitles(Video) {
266
285
  }));
267
286
  });
268
287
  }
269
- loadSubtitleFromUrl(selectedTrack.url);
288
+ loadSubtitles(selectedTrack);
270
289
  }
271
290
  renderSubtitles();
272
291
  onPropChanged('selectedExtraSubtitlesTrackId');
@@ -374,7 +393,6 @@ function withHTMLSubtitles(Video) {
374
393
  .filter(function(track, index, tracks) {
375
394
  return track &&
376
395
  typeof track.id === 'string' &&
377
- typeof track.url === 'string' &&
378
396
  typeof track.lang === 'string' &&
379
397
  typeof track.label === 'string' &&
380
398
  typeof track.origin === 'string' &&
@@ -386,6 +404,31 @@ function withHTMLSubtitles(Video) {
386
404
 
387
405
  return true;
388
406
  }
407
+ case 'addLocalSubtitles': {
408
+ if (commandArgs && typeof commandArgs.filename === 'string' && commandArgs.buffer instanceof ArrayBuffer) {
409
+ var id = 'LOCAL_' + tracks
410
+ .filter(function(track) { return track.local; })
411
+ .length;
412
+
413
+ var track = {
414
+ id: id,
415
+ url: null,
416
+ buffer: commandArgs.buffer,
417
+ lang: 'local',
418
+ label: commandArgs.filename,
419
+ origin: 'LOCAL',
420
+ local: true,
421
+ embedded: false,
422
+ };
423
+
424
+ tracks.push(track);
425
+
426
+ onPropChanged('extraSubtitlesTracks');
427
+ events.emit('extraSubtitlesTrackAdded', track);
428
+ }
429
+
430
+ return true;
431
+ }
389
432
  case 'load': {
390
433
  command('unload');
391
434
  if (commandArgs.stream && Array.isArray(commandArgs.stream.subtitles)) {
@@ -485,9 +528,9 @@ function withHTMLSubtitles(Video) {
485
528
  external: Video.manifest.external,
486
529
  props: Video.manifest.props.concat(['extraSubtitlesTracks', 'selectedExtraSubtitlesTrackId', 'extraSubtitlesDelay', 'extraSubtitlesSize', 'extraSubtitlesOffset', 'extraSubtitlesTextColor', 'extraSubtitlesBackgroundColor', 'extraSubtitlesOutlineColor', 'extraSubtitlesOpacity'])
487
530
  .filter(function(value, index, array) { return array.indexOf(value) === index; }),
488
- commands: Video.manifest.commands.concat(['load', 'unload', 'destroy', 'addExtraSubtitlesTracks'])
531
+ commands: Video.manifest.commands.concat(['load', 'unload', 'destroy', 'addExtraSubtitlesTracks', 'addLocalSubtitles'])
489
532
  .filter(function(value, index, array) { return array.indexOf(value) === index; }),
490
- events: Video.manifest.events.concat(['propValue', 'propChanged', 'error', 'extraSubtitlesTrackLoaded'])
533
+ events: Video.manifest.events.concat(['propValue', 'propChanged', 'error', 'extraSubtitlesTrackLoaded', 'extraSubtitlesTrackAdded'])
491
534
  .filter(function(value, index, array) { return array.indexOf(value) === index; })
492
535
  };
493
536