@stremio/stremio-video 0.0.25-rc.5 → 0.0.26

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.25-rc.5",
3
+ "version": "0.0.26",
4
4
  "description": "Abstraction layer on top of different media players",
5
5
  "author": "Smart Code OOD",
6
6
  "main": "src/index.js",
@@ -20,7 +20,6 @@
20
20
  "hat": "0.0.3",
21
21
  "hls.js": "https://github.com/Stremio/hls.js/releases/download/v1.2.3-patch1/hls.js-1.2.3-patch1.tgz",
22
22
  "lodash.clonedeep": "4.5.0",
23
- "lodash.mergewith": "4.6.2",
24
23
  "magnet-uri": "6.2.0",
25
24
  "url": "0.11.0",
26
25
  "video-name-parser": "1.4.6",
@@ -1,94 +1,51 @@
1
- var MP4_CONFIG = {
2
- VIDEO_CODECS: [
3
- {
4
- codec: 'h264',
5
- force: window.chrome || window.cast,
6
- mime: 'video/mp4; codecs="avc1.42E01E"',
7
- },
8
- {
9
- codec: 'h265',
10
- force: window.chrome || window.cast,
11
- mime: 'video/mp4; codecs="hev1.1.6.L150.B0"',
12
- aliases: ['hevc'],
13
- },
14
- {
15
- codec: 'vp8',
16
- mime: 'video/mp4; codecs="vp8"',
17
- },
18
- {
19
- codec: 'vp9',
20
- mime: 'video/mp4; codecs="vp9"',
21
- },
22
- ],
23
- AUDIO_CODEC: [
24
- {
25
- codec: 'aac',
26
- force: window.chrome || window.cast,
27
- mime: 'audio/mp4; codecs="mp4a.40.2"',
28
- },
29
- {
30
- codec: 'mp3',
31
- force: window.chrome || window.cast,
32
- mime: 'audio/mp4; codecs="mp3"',
33
- },
34
- {
35
- codec: 'ac3',
36
- mime: 'audio/mp4; codecs="ac-3"',
37
- },
38
- {
39
- codec: 'eac3',
40
- mime: 'audio/mp4; codecs="ec-3"',
41
- },
42
- {
43
- codec: 'vorbis',
44
- mime: 'audio/mp4; codecs="vorbis"',
45
- },
46
- {
47
- codec: 'opus',
48
- mime: 'audio/mp4; codecs="opus"',
49
- },
50
- ],
51
- };
1
+ var VIDEO_CODEC_CONFIGS = [
2
+ {
3
+ codec: 'h264',
4
+ force: window.chrome || window.cast,
5
+ mime: 'video/mp4; codecs="avc1.42E01E"',
6
+ },
7
+ {
8
+ codec: 'h265',
9
+ force: window.chrome || window.cast,
10
+ mime: 'video/mp4; codecs="hev1.1.6.L150.B0"',
11
+ aliases: ['hevc']
12
+ },
13
+ {
14
+ codec: 'vp8',
15
+ mime: 'video/mp4; codecs="vp8"'
16
+ },
17
+ {
18
+ codec: 'vp9',
19
+ mime: 'video/mp4; codecs="vp9"'
20
+ }
21
+ ];
52
22
 
53
- var MATROSKA_CONFIG = {
54
- VIDEO_CODECS: [
55
- {
56
- codec: 'h264',
57
- force: window.chrome || window.cast,
58
- },
59
- {
60
- codec: 'h265',
61
- force: window.chrome || window.cast,
62
- aliases: ['hevc'],
63
- },
64
- {
65
- codec: 'vp8',
66
- mime: 'video/webm; codecs="vp8"',
67
- },
68
- {
69
- codec: 'vp9',
70
- mime: 'video/webm; codecs="vp9"',
71
- },
72
- ],
73
- AUDIO_CODEC: [
74
- {
75
- codec: 'aac',
76
- force: window.chrome || window.cast,
77
- },
78
- {
79
- codec: 'mp3',
80
- force: window.chrome || window.cast,
81
- },
82
- {
83
- codec: 'vorbis',
84
- mime: 'audio/webm; codecs="vorbis"',
85
- },
86
- {
87
- codec: 'opus',
88
- mime: 'audio/webm; codecs="opus"',
89
- },
90
- ],
91
- };
23
+ var AUDIO_CODEC_CONFIGS = [
24
+ {
25
+ codec: 'aac',
26
+ mime: 'audio/mp4; codecs="mp4a.40.2"'
27
+ },
28
+ {
29
+ codec: 'mp3',
30
+ mime: 'audio/mp4; codecs="mp3"'
31
+ },
32
+ {
33
+ codec: 'ac3',
34
+ mime: 'audio/mp4; codecs="ac-3"'
35
+ },
36
+ {
37
+ codec: 'eac3',
38
+ mime: 'audio/mp4; codecs="ec-3"'
39
+ },
40
+ {
41
+ codec: 'vorbis',
42
+ mime: 'audio/mp4; codecs="vorbis"'
43
+ },
44
+ {
45
+ codec: 'opus',
46
+ mime: 'audio/mp4; codecs="opus"'
47
+ }
48
+ ];
92
49
 
93
50
  function canPlay(config, options) {
94
51
  return config.force || options.mediaElement.canPlayType(config.mime)
@@ -111,34 +68,30 @@ function getMaxAudioChannels() {
111
68
 
112
69
  function getMediaCapabilities() {
113
70
  var mediaElement = document.createElement('video');
71
+ var formats = ['mp4'];
72
+ if (window.chrome || window.cast) {
73
+ formats.push('matroska,webm');
74
+ }
75
+ var videoCodecs = VIDEO_CODEC_CONFIGS
76
+ .map(function(config) {
77
+ return canPlay(config, { mediaElement: mediaElement });
78
+ })
79
+ .reduce(function(result, value) {
80
+ return result.concat(value);
81
+ }, []);
82
+ var audioCodecs = AUDIO_CODEC_CONFIGS
83
+ .map(function(config) {
84
+ return canPlay(config, { mediaElement: mediaElement });
85
+ })
86
+ .reduce(function(result, value) {
87
+ return result.concat(value);
88
+ }, []);
114
89
  var maxAudioChannels = getMaxAudioChannels();
115
90
  return {
116
- mp4: {
117
- videoCodecs: MP4_CONFIG.VIDEO_CODECS.map(function(config) {
118
- return canPlay(config, { mediaElement: mediaElement });
119
- }).reduce(function(result, value) {
120
- return result.concat(value);
121
- }, []),
122
- audioCodecs: MP4_CONFIG.AUDIO_CODEC.map(function(config) {
123
- return canPlay(config, { mediaElement: mediaElement });
124
- }).reduce(function(result, value) {
125
- return result.concat(value);
126
- }, []),
127
- maxAudioChannels: maxAudioChannels
128
- },
129
- 'matroska,webm': {
130
- videoCodecs: MATROSKA_CONFIG.VIDEO_CODECS.map(function(config) {
131
- return canPlay(config, { mediaElement: mediaElement });
132
- }).reduce(function(result, value) {
133
- return result.concat(value);
134
- }, []),
135
- audioCodecs: MATROSKA_CONFIG.AUDIO_CODEC.map(function(config) {
136
- return canPlay(config, { mediaElement: mediaElement });
137
- }).reduce(function(result, value) {
138
- return result.concat(value);
139
- }, []),
140
- maxAudioChannels: maxAudioChannels
141
- },
91
+ formats: formats,
92
+ videoCodecs: videoCodecs,
93
+ audioCodecs: audioCodecs,
94
+ maxAudioChannels: maxAudioChannels
142
95
  };
143
96
  }
144
97
 
@@ -1,10 +1,9 @@
1
1
  var EventEmitter = require('eventemitter3');
2
2
  var url = require('url');
3
3
  var hat = require('hat');
4
- var mergeWith = require('lodash.mergewith');
5
4
  var cloneDeep = require('lodash.clonedeep');
6
5
  var deepFreeze = require('deep-freeze');
7
- var deviceMediaCapabilities = require('../mediaCapabilities');
6
+ var mediaCapabilities = require('../mediaCapabilities');
8
7
  var convertStream = require('./convertStream');
9
8
  var fetchVideoParams = require('./fetchVideoParams');
10
9
  var ERROR = require('../error');
@@ -108,9 +107,27 @@ function withStreamingServer(Video) {
108
107
  var mediaURL = result.url;
109
108
  var infoHash = result.infoHash;
110
109
  var fileIdx = result.fileIdx;
111
- var mediaCapabilities = mergeWith({}, deviceMediaCapabilities, commandArgs.mediaCapabilities);
110
+ var formats = Array.isArray(commandArgs.formats) ?
111
+ commandArgs.formats
112
+ :
113
+ mediaCapabilities.formats;
114
+ var videoCodecs = Array.isArray(commandArgs.videoCodecs) ?
115
+ commandArgs.videoCodecs
116
+ :
117
+ mediaCapabilities.videoCodecs;
118
+ var audioCodecs = Array.isArray(commandArgs.audioCodecs) ?
119
+ commandArgs.audioCodecs
120
+ :
121
+ mediaCapabilities.audioCodecs;
122
+ var maxAudioChannels = commandArgs.maxAudioChannels !== null && isFinite(commandArgs.maxAudioChannels) ?
123
+ commandArgs.maxAudioChannels
124
+ :
125
+ mediaCapabilities.maxAudioChannels;
112
126
  var canPlayStreamOptions = Object.assign({}, commandArgs, {
113
- mediaCapabilities: mediaCapabilities
127
+ formats: formats,
128
+ videoCodecs: videoCodecs,
129
+ audioCodecs: audioCodecs,
130
+ maxAudioChannels: maxAudioChannels
114
131
  });
115
132
  return (commandArgs.forceTranscoding ? Promise.resolve(false) : VideoWithStreamingServer.canPlayStream({ url: mediaURL }, canPlayStreamOptions))
116
133
  .catch(function(error) {
@@ -135,23 +152,14 @@ function withStreamingServer(Video) {
135
152
  queryParams.set('forceTranscoding', '1');
136
153
  }
137
154
 
138
- var videoCodecs = Object.keys(mediaCapabilities).reduce(function(result, format) {
139
- return result.concat(mediaCapabilities[format].videoCodecs);
140
- }, []);
141
155
  videoCodecs.forEach(function(videoCodec) {
142
156
  queryParams.append('videoCodecs', videoCodec);
143
157
  });
144
158
 
145
- var audioCodecs = Object.keys(mediaCapabilities).reduce(function(result, format) {
146
- return result.concat(mediaCapabilities[format].audioCodecs);
147
- }, []);
148
159
  audioCodecs.forEach(function(audioCodec) {
149
160
  queryParams.append('audioCodecs', audioCodec);
150
161
  });
151
162
 
152
- var maxAudioChannels = Object.keys(mediaCapabilities).reduce(function(result, format) {
153
- return Math.max(result, mediaCapabilities[format].maxAudioChannels);
154
- }, 2);
155
163
  queryParams.set('maxAudioChannels', maxAudioChannels);
156
164
 
157
165
  return {
@@ -348,25 +356,20 @@ function withStreamingServer(Video) {
348
356
  return resp.json();
349
357
  })
350
358
  .then(function(probe) {
351
- var format = options.mediaCapabilities[probe.format.name];
352
- if (!format) {
353
- return false;
354
- }
355
-
356
- var videoStreams = probe.streams.filter(function(stream) {
357
- return stream.track === 'video';
358
- });
359
- var areVideoStreamsSupported = videoStreams.length === 0 || videoStreams.some(function(stream) {
360
- return format.videoCodecs.indexOf(stream.codec) !== -1;
359
+ var isFormatSupported = options.formats.some(function(format) {
360
+ return probe.format.name.indexOf(format) !== -1;
361
361
  });
362
- var audioStreams = probe.streams.filter(function(stream) {
363
- return stream.track === 'audio';
364
- });
365
- var areAudioStreamsSupported = audioStreams.length === 0 || audioStreams.some(function(stream) {
366
- return stream.channels <= format.maxAudioChannels &&
367
- format.audioCodecs.indexOf(stream.codec) !== -1;
362
+ var areStreamsSupported = probe.streams.every(function(stream) {
363
+ if (stream.track === 'audio') {
364
+ return stream.channels <= options.maxAudioChannels &&
365
+ options.audioCodecs.indexOf(stream.codec) !== -1;
366
+ } else if (stream.track === 'video') {
367
+ return options.videoCodecs.indexOf(stream.codec) !== -1;
368
+ }
369
+
370
+ return true;
368
371
  });
369
- return areVideoStreamsSupported && areAudioStreamsSupported;
372
+ return isFormatSupported && areStreamsSupported;
370
373
  });
371
374
  });
372
375
  };