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 CHANGED
@@ -37,7 +37,7 @@ type VideoTrack = {
37
37
  size: number; // MB
38
38
  width: number;
39
39
  height: number;
40
- quality: 'SD' | 'HD' | 'Full HD' | '4K' : '8K';
40
+ qualityLabel: '144p' | '240p' | '360p' | '480p' | '576p' | '720p' | '1080p' | '2160p';
41
41
  };
42
42
 
43
43
  type AudioTrack = {
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.height === height);
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
- quality: getQualityLabel(representation.width),
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) => languages?.some((lang) => r.lang.includes(lang)));
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 getQualityLabel = (videoWidth) => {
37
+ const getHeightByWidth = (videoWidth) => {
38
38
  const width = typeof videoWidth === 'number' ? videoWidth : parseInt(videoWidth);
39
39
  if (isNaN(width)) return;
40
- let label = 'SD';
41
- if (width >= 1280) label = 'HD';
42
- if (width >= 1920) label = 'Full HD';
43
- if (width >= 3840) label = 'UHD';
44
- if (width >= 4096) label = '4K';
45
- if (width >= 7680) label = '8K';
46
- return label;
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
- module.exports = { parseDuration, getQualityLabel };
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.2.5",
4
- "author": "Vitaliy Gashkov <vitnore@gmail.com>",
5
- "description": "Simple MPEG-DASH MPD parser",
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/vitnore/dasha.git"
22
+ "url": "git+https://github.com/vitalygashkov/dasha.git"
23
23
  },
24
24
  "funding": {
25
- "type": "patreon",
26
- "url": "https://www.patreon.com/vitnore"
25
+ "type": "individual",
26
+ "url": "https://boosty.to/vitalygashkov"
27
27
  },
28
28
  "scripts": {
29
29
  "test": "jest",