dasha 2.2.5 → 2.3.1
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/README.md +1 -1
- package/lib/manifest.js +12 -5
- package/lib/utils.js +14 -9
- package/package.json +6 -6
package/README.md
CHANGED
package/lib/manifest.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { parseXml } = require('./xml');
|
|
4
4
|
const { processManifest } = require('./processor');
|
|
5
|
-
const { getQualityLabel } = require('./utils');
|
|
5
|
+
const { getQualityLabel, getHeightByWidth } = require('./utils');
|
|
6
6
|
const { CONTENT_TYPE, KEY_SYSTEMS } = require('./constants');
|
|
7
7
|
|
|
8
8
|
const isUrl = (value) => {
|
|
@@ -18,6 +18,11 @@ class Manifest {
|
|
|
18
18
|
for (const key of Object.keys(manifest)) this[key] = manifest[key];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
addBaseUrl(value) {
|
|
22
|
+
if (Array.isArray(this.baseUrls)) this.baseUrls.push({ value });
|
|
23
|
+
else this.baseUrls = [{ value }];
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
getVideoTrack(height) {
|
|
22
27
|
const isVideoAdaptationSet = (adaptationSet) =>
|
|
23
28
|
adaptationSet.contentType === CONTENT_TYPE.video ||
|
|
@@ -29,7 +34,7 @@ class Manifest {
|
|
|
29
34
|
.flat(1)
|
|
30
35
|
.filter(isVideoAdaptationSet);
|
|
31
36
|
const representations = adaptationSets.map((a) => a.representations).flat(2);
|
|
32
|
-
const matchesInHeight = representations.filter((r) => r.
|
|
37
|
+
const matchesInHeight = representations.filter((r) => getHeightByWidth(r.width) === height);
|
|
33
38
|
const matchesInId = representations.filter((r) => r.id.includes(height));
|
|
34
39
|
const matches = matchesInHeight?.length ? matchesInHeight : matchesInId;
|
|
35
40
|
const representation = this.findBestRepresentation(matches.length ? matches : representations);
|
|
@@ -44,7 +49,7 @@ class Manifest {
|
|
|
44
49
|
size: Math.ceil((representation.bandwidth / 8e6) * this.mediaPresentationDuration), // MB
|
|
45
50
|
width: representation.width,
|
|
46
51
|
height: representation.height,
|
|
47
|
-
|
|
52
|
+
qualityLabel: getQualityLabel(representation.width),
|
|
48
53
|
};
|
|
49
54
|
}
|
|
50
55
|
|
|
@@ -55,7 +60,7 @@ class Manifest {
|
|
|
55
60
|
adaptationSet.representations.some((r) => r.mimeType?.includes('audio'))) &&
|
|
56
61
|
!adaptationSet.maxWidth;
|
|
57
62
|
const filterLanguages = (adaptationSet) =>
|
|
58
|
-
languages ? languages.some((lang) => adaptationSet.lang.includes(lang)) : true;
|
|
63
|
+
languages?.length ? languages.some((lang) => adaptationSet.lang.includes(lang)) : true;
|
|
59
64
|
const adaptationSets = this.periods
|
|
60
65
|
.map((p) => p.adaptationSets)
|
|
61
66
|
.flat(1)
|
|
@@ -94,7 +99,9 @@ class Manifest {
|
|
|
94
99
|
.filter(isSubtitleAdaptationSet);
|
|
95
100
|
|
|
96
101
|
const representations = adaptationSets.map((a) => a.representations).flat(2);
|
|
97
|
-
const matches = representations.filter((r) =>
|
|
102
|
+
const matches = representations.filter((r) =>
|
|
103
|
+
languages?.length ? languages?.some((lang) => r.lang.includes(lang)) : true
|
|
104
|
+
);
|
|
98
105
|
const selectedRepresentations = matches?.length ? matches : representations;
|
|
99
106
|
|
|
100
107
|
const tracks = [];
|
package/lib/utils.js
CHANGED
|
@@ -34,16 +34,21 @@ const parseDuration = (durationString) => {
|
|
|
34
34
|
return isFinite(d) ? d : null;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const getHeightByWidth = (videoWidth) => {
|
|
38
38
|
const width = typeof videoWidth === 'number' ? videoWidth : parseInt(videoWidth);
|
|
39
39
|
if (isNaN(width)) return;
|
|
40
|
-
let
|
|
41
|
-
if (width >=
|
|
42
|
-
if (width >=
|
|
43
|
-
if (width >=
|
|
44
|
-
if (width >=
|
|
45
|
-
if (width >=
|
|
46
|
-
|
|
40
|
+
let height = 144;
|
|
41
|
+
if (width >= 426) height = 240;
|
|
42
|
+
if (width >= 640) height = 360;
|
|
43
|
+
if (width >= 854) height = 480;
|
|
44
|
+
if (width >= 1024) height = 576;
|
|
45
|
+
if (width >= 1280) height = 720;
|
|
46
|
+
if (width >= 1920) height = 1080;
|
|
47
|
+
if (width >= 3840) height = 2160;
|
|
48
|
+
if (width >= 7680) height = 4320;
|
|
49
|
+
return height;
|
|
47
50
|
};
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
const getQualityLabel = (videoWidth) => getHeightByWidth(videoWidth) + 'p';
|
|
53
|
+
|
|
54
|
+
module.exports = { parseDuration, getHeightByWidth, getQualityLabel };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dasha",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"author": "
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"author": "Vitaly Gashkov <vitalygashkov@bk.ru>",
|
|
5
|
+
"description": "MPD-manifest parser for MPEG DASH",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"mpeg",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/vitalygashkov/dasha.git"
|
|
23
23
|
},
|
|
24
24
|
"funding": {
|
|
25
|
-
"type": "
|
|
26
|
-
"url": "https://
|
|
25
|
+
"type": "individual",
|
|
26
|
+
"url": "https://boosty.to/vitalygashkov"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"test": "jest",
|