dasha 3.1.4 → 4.0.0-alpha.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/package.json CHANGED
@@ -1,25 +1,36 @@
1
1
  {
2
2
  "name": "dasha",
3
- "version": "3.1.4",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "Streaming manifest parser",
5
5
  "files": [
6
- "dasha.js",
7
- "lib",
8
- "types"
6
+ "dist"
9
7
  ],
10
8
  "scripts": {
11
- "test": "npm run lint && npm run types && node --test",
12
- "types": "tsc -p tsconfig.json",
9
+ "test": "vitest",
13
10
  "lint": "eslint . && prettier --check .",
14
11
  "fix": "eslint . --fix && prettier --write .",
15
- "build": "tsup dasha.js --format esm,cjs",
12
+ "typecheck": "tsc --noEmit -p tsconfig.json",
13
+ "build": "tsdown dasha.ts --format esm --format cjs",
16
14
  "prepublishOnly": "npm run build"
17
15
  },
18
- "main": "dasha.js",
19
- "types": "./types/dasha.d.ts",
16
+ "type": "module",
17
+ "main": "./dist/dasha.js",
18
+ "types": "./dist/dasha.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "require": {
22
+ "types": "./dist/dasha.d.cts",
23
+ "default": "./dist/dasha.cjs"
24
+ },
25
+ "import": {
26
+ "types": "./dist/dasha.d.ts",
27
+ "default": "./dist/dasha.js"
28
+ }
29
+ }
30
+ },
20
31
  "repository": {
21
32
  "type": "git",
22
- "url": "https://github.com/vitalygashkov/dasha"
33
+ "url": "https://github.com/streamyx-labs/dasha"
23
34
  },
24
35
  "keywords": [
25
36
  "mpeg",
@@ -27,7 +38,9 @@
27
38
  "hls",
28
39
  "adaptive",
29
40
  "mpd",
41
+ "mpd-parser",
30
42
  "m3u8",
43
+ "m3u8-parser",
31
44
  "manifest",
32
45
  "playlist"
33
46
  ],
@@ -35,7 +48,7 @@
35
48
  "license": "MIT",
36
49
  "readmeFilename": "README.md",
37
50
  "bugs": {
38
- "url": "https://github.com/vitalygashkov/dasha/issues",
51
+ "url": "https://github.com/streamyx-labs/dasha/issues",
39
52
  "email": "vitalygashkov@vk.com"
40
53
  },
41
54
  "funding": [
@@ -52,17 +65,20 @@
52
65
  "node": "20 || 21 || 22"
53
66
  },
54
67
  "dependencies": {
55
- "m3u8-parser": "^7.2.0"
68
+ "@xmldom/xmldom": "^0.9.8",
69
+ "temporal-polyfill": "^0.3.0"
56
70
  },
57
71
  "devDependencies": {
58
- "@eslint/js": "^9.16.0",
59
- "@types/node": "^22.10.1",
60
- "eslint": "^9.16.0",
61
- "eslint-config-prettier": "^9.1.0",
62
- "eslint-plugin-prettier": "^5.2.1",
63
- "globals": "^15.13.0",
64
- "prettier": "^3.4.2",
65
- "tsup": "^8.3.5",
66
- "typescript": "^5.7.2"
72
+ "@eslint/js": "^9.25.1",
73
+ "@types/node": "^22.15.3",
74
+ "eslint": "^9.25.1",
75
+ "eslint-config-prettier": "^10.1.2",
76
+ "eslint-plugin-prettier": "^5.2.6",
77
+ "globals": "^16.0.0",
78
+ "prettier": "^3.5.3",
79
+ "tsdown": "^0.10.2",
80
+ "typescript": "^5.8.3",
81
+ "typescript-eslint": "^8.31.1",
82
+ "vitest": "^3.1.2"
67
83
  }
68
84
  }
package/dasha.js DELETED
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- const dash = require('./lib/dash');
4
- const hls = require('./lib/hls');
5
- const {
6
- filterByResolution,
7
- filterByQuality,
8
- filterByCodecs,
9
- filterByLanguages,
10
- filterByChannels,
11
- } = require('./lib/track');
12
- const { SUBTITLE_CODECS } = require('./lib/subtitle');
13
-
14
- const parse = (text, url, fallbackLanguage) => {
15
- if (text.includes('<MPD'))
16
- return dash.parseManifest(text, url, fallbackLanguage);
17
- else if (text.includes('#EXTM3U')) return hls.parseManifest(text, url);
18
- else throw new Error('Invalid manifest');
19
- };
20
-
21
- module.exports = {
22
- parse,
23
- filterByResolution,
24
- filterByQuality,
25
- filterByCodecs,
26
- filterByLanguages,
27
- filterByChannels,
28
- SUBTITLE_CODECS,
29
- };
package/lib/audio.js DELETED
@@ -1,148 +0,0 @@
1
- 'use strict';
2
-
3
- const { parseMimes } = require('./track');
4
- const { parseBitrate, parseSize } = require('./util');
5
-
6
- const AUDIO_CODECS = {
7
- AAC: 'AAC', // https://wikipedia.org/wiki/Advanced_Audio_Coding
8
- AC3: 'DD', // https://wikipedia.org/wiki/Dolby_Digital
9
- EC3: 'DD+', // https://wikipedia.org/wiki/Dolby_Digital_Plus
10
- OPUS: 'OPUS', // https://wikipedia.org/wiki/Opus_(audio_format)
11
- OGG: 'VORB', // https://wikipedia.org/wiki/Vorbis
12
- DTS: 'DTS', // https://en.wikipedia.org/wiki/DTS_(company)#DTS_Digital_Surround
13
- ALAC: 'ALAC', // https://en.wikipedia.org/wiki/Apple_Lossless_Audio_Codec
14
- FLAC: 'FLAC', // https://en.wikipedia.org/wiki/FLAC
15
- };
16
-
17
- const parseAudioCodecFromMime = (mime) => {
18
- const target = mime.toLowerCase().trim().split('.')[0];
19
- switch (target) {
20
- case 'mp4a':
21
- return AUDIO_CODECS.AAC;
22
- case 'ac-3':
23
- return AUDIO_CODECS.AC3;
24
- case 'ec-3':
25
- return AUDIO_CODECS.EC3;
26
- case 'opus':
27
- return AUDIO_CODECS.OPUS;
28
- case 'dtsc':
29
- return AUDIO_CODECS.DTS;
30
- case 'alac':
31
- return AUDIO_CODECS.ALAC;
32
- case 'flac':
33
- return AUDIO_CODECS.FLAC;
34
- default:
35
- throw new Error(`The MIME ${mime} is not supported as audio codec`);
36
- }
37
- };
38
-
39
- const parseAudioCodec = (codecs) => {
40
- const mimes = parseMimes(codecs);
41
- for (const mime of mimes) {
42
- try {
43
- return parseAudioCodecFromMime(mime);
44
- } catch (e) {
45
- continue;
46
- }
47
- }
48
- throw new Error(
49
- `No MIME types matched any supported Audio Codecs in ${codecs}`,
50
- );
51
- };
52
-
53
- const tryParseAudioCodec = (codecs) => {
54
- try {
55
- return parseAudioCodec(codecs);
56
- } catch (e) {
57
- return null;
58
- }
59
- };
60
-
61
- // https://professionalsupport.dolby.com/s/article/What-is-Dolby-Digital-Plus-JOC-Joint-Object-Coding?language=en_US
62
- const getDolbyDigitalPlusComplexityIndex = (supplementalProps = []) => {
63
- const targetScheme =
64
- 'tag:dolby.com,2018:dash:EC3_ExtensionComplexityIndex:2018';
65
- for (const prop of supplementalProps)
66
- if (prop.attributes.schemeIdUri === targetScheme)
67
- return parseInt(prop.attributes.value);
68
- };
69
-
70
- const checkIsDescriptive = (accessibilities = []) => {
71
- for (const accessibility of accessibilities) {
72
- const { schemeIdUri, value } = accessibility.attributes;
73
- const firstMatch =
74
- schemeIdUri == 'urn:mpeg:dash:role:2011' && value === 'descriptive';
75
- const secondMatch =
76
- schemeIdUri == 'urn:tva:metadata:cs:AudioPurposeCS:2007' && value === '1';
77
- const isDescriptive = firstMatch || secondMatch;
78
- if (isDescriptive) return true;
79
- }
80
- return false;
81
- };
82
-
83
- const parseChannels = (channels) => {
84
- const isDigit = (char) => char >= '0' && char <= '9';
85
- if (typeof channels === 'string') {
86
- if (channels.toUpperCase() == 'A000') return 2.0;
87
- else if (channels.toUpperCase() == 'F801') return 5.1;
88
- else if (isDigit(channels.replace('ch', '').replace('.', '')[0]))
89
- // e.g., '2ch', '2', '2.0', '5.1ch', '5.1'
90
- return parseFloat(channels.replace('ch', ''));
91
- throw new Error(`Unsupported audio channels value, '${channels}'`);
92
- }
93
- return parseFloat(channels);
94
- };
95
-
96
- const createAudioTrack = ({
97
- id,
98
- label,
99
- type,
100
- codec,
101
- channels,
102
- contentProtection,
103
- bitrate,
104
- duration,
105
- jointObjectCoding = 0,
106
- isDescriptive = false,
107
- language,
108
- segments,
109
- }) => {
110
- const parsedBitrate = parseBitrate(Number(bitrate));
111
- const parsedChannels = parseChannels(channels);
112
- const size = duration
113
- ? parseSize(Number(bitrate), Number(duration))
114
- : undefined;
115
- return {
116
- id,
117
- label,
118
- type,
119
- codec,
120
- bitrate: parsedBitrate,
121
- size,
122
- protection: contentProtection,
123
- language,
124
- segments,
125
- channels: parsedChannels,
126
- jointObjectCoding,
127
- isDescriptive,
128
- toString() {
129
- return [
130
- 'AUDIO',
131
- `[${codec}]`,
132
- `${parsedChannels || '?'}` +
133
- (jointObjectCoding ? ` (JOC ${jointObjectCoding})` : ''),
134
- `${parsedBitrate.kbps} kb/s`,
135
- language,
136
- ].join(' | ');
137
- },
138
- };
139
- };
140
-
141
- module.exports = {
142
- AUDIO_CODECS,
143
- parseAudioCodec,
144
- tryParseAudioCodec,
145
- createAudioTrack,
146
- getDolbyDigitalPlusComplexityIndex,
147
- checkIsDescriptive,
148
- };