dasha 2.3.0 → 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) => {
@@ -34,7 +34,7 @@ class Manifest {
34
34
  .flat(1)
35
35
  .filter(isVideoAdaptationSet);
36
36
  const representations = adaptationSets.map((a) => a.representations).flat(2);
37
- const matchesInHeight = representations.filter((r) => r.height === height);
37
+ const matchesInHeight = representations.filter((r) => getHeightByWidth(r.width) === height);
38
38
  const matchesInId = representations.filter((r) => r.id.includes(height));
39
39
  const matches = matchesInHeight?.length ? matchesInHeight : matchesInId;
40
40
  const representation = this.findBestRepresentation(matches.length ? matches : representations);
@@ -49,7 +49,7 @@ class Manifest {
49
49
  size: Math.ceil((representation.bandwidth / 8e6) * this.mediaPresentationDuration), // MB
50
50
  width: representation.width,
51
51
  height: representation.height,
52
- quality: getQualityLabel(representation.width),
52
+ qualityLabel: getQualityLabel(representation.width),
53
53
  };
54
54
  }
55
55
 
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,7 +1,7 @@
1
1
  {
2
2
  "name": "dasha",
3
- "version": "2.3.0",
4
- "author": "Vitaly Gashkov <vitalygashkov@outlook.com>",
3
+ "version": "2.3.1",
4
+ "author": "Vitaly Gashkov <vitalygashkov@bk.ru>",
5
5
  "description": "MPD-manifest parser for MPEG DASH",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [