dasha 2.0.0 → 2.0.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
@@ -1,23 +1,15 @@
1
1
  # Dasha
2
2
 
3
- Dasha is a simple parser for MPD manifests.
4
-
5
- ## Installing
6
-
7
- **Requirements**
8
-
9
- - [Node.js](https://nodejs.org) v16 or greater
10
- - npm v8
3
+ [![npm version](https://img.shields.io/npm/v/dasha)](https://www.npmjs.com/package/dasha)
4
+ [![npm downloads/month](https://img.shields.io/npm/dm/dasha)](https://www.npmjs.com/package/dasha)
5
+ [![npm downloads](https://img.shields.io/npm/dt/dasha)](https://www.npmjs.com/package/dasha)
11
6
 
12
- **Install dependencies**
13
-
14
- ```bash
15
- npm i
16
- ```
7
+ Dasha is a simple parser for MPD manifests.
17
8
 
18
- ## Usage examples
9
+ ## Usage
19
10
 
20
- **Parse manifest and get tracks with selected video height**
11
+ - Install: `npm install dasha`
12
+ - Require: `const { parseManifest } = require('dasha');`
21
13
 
22
14
  ```javascript
23
15
  const { parseManifest } = require('./dasha');
@@ -27,33 +19,31 @@ const rawManifest = `
27
19
  <MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
28
20
  ...
29
21
  </MPD>
30
- `
22
+ `;
31
23
  const manifest = parseManifest(rawManifest);
32
24
  const targetHeight = 1080;
33
- const targetAudioLanguages = ['rus']
25
+ const targetAudioLanguages = ['rus'];
34
26
  const videoTrack = manifest.getVideoTrack(targetHeight);
35
27
  const audioTracks = manifest.getAudioTracks(targetAudioLanguages);
36
28
  const tracks = [videoTrack, ...audioTracks];
37
29
  ```
38
30
 
39
- **Tracks structure**
40
-
41
31
  ```typescript
42
32
  type VideoTrack = {
43
- type: "video",
44
- segments: { url: string, init: boolean }[],
45
- bitrate: number, // Kbps
46
- size: number, // MB
47
- width: number,
48
- height: number,
49
- quality: "SD" | "HD" | "Full HD",
50
- }
33
+ type: 'video';
34
+ segments: { url: string; init: boolean }[];
35
+ bitrate: number; // Kbps
36
+ size: number; // MB
37
+ width: number;
38
+ height: number;
39
+ quality: 'SD' | 'HD' | 'Full HD' | '4K' : '8K';
40
+ };
51
41
 
52
42
  type AudioTrack = {
53
- type: "audio",
54
- segments: { url: string, init: boolean }[],
55
- bitrate: number, // Kbps
56
- size: number, // MB
57
- audioSampleRate: number // kHz
58
- }
43
+ type: 'audio';
44
+ segments: { url: string; init: boolean }[];
45
+ bitrate: number; // Kbps
46
+ size: number; // MB
47
+ audioSampleRate: number; // kHz
48
+ };
59
49
  ```
package/lib/utils.js CHANGED
@@ -35,11 +35,14 @@ const parseDuration = (durationString) => {
35
35
  };
36
36
 
37
37
  const getQualityLabel = (videoHeight) => {
38
- let quality = 'SD';
39
- if (videoHeight >= 720) quality = 'HD';
40
- if (videoHeight >= 1080) quality = 'Full HD';
41
- if (videoHeight >= 2016) quality = '4K';
42
- return quality;
38
+ const height = typeof videoHeight === 'number' ? videoHeight : parseInt(videoHeight);
39
+ if (isNaN(height)) return;
40
+ let label = 'SD';
41
+ if (height >= 720) label = 'HD';
42
+ if (height >= 1080) label = 'Full HD';
43
+ if (height >= 2160) label = '4K';
44
+ if (height >= 4320) label = '8K';
45
+ return label;
43
46
  };
44
47
 
45
48
  module.exports = { parseDuration, getQualityLabel };
package/package.json CHANGED
@@ -1,12 +1,32 @@
1
1
  {
2
2
  "name": "dasha",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
+ "author": "Vitaliy Gashkov <vitnore@gmail.com>",
4
5
  "description": "Simple MPEG-DASH MPD parser",
5
6
  "license": "Apache-2.0",
6
- "author": "vitnore",
7
+ "keywords": [
8
+ "mpeg",
9
+ "dash",
10
+ "adaptive",
11
+ "mpd",
12
+ "manifest"
13
+ ],
7
14
  "main": "dasha.js",
15
+ "types": "types/dasha.d.ts",
16
+ "files": [
17
+ "lib",
18
+ "types"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/vitnore/dasha.git"
23
+ },
24
+ "funding": {
25
+ "type": "patreon",
26
+ "url": "https://www.patreon.com/vitnore"
27
+ },
8
28
  "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1",
29
+ "test": "jest",
10
30
  "types": "tsc -p tsconfig.json",
11
31
  "lint": "eslint \"**/*.js\" --fix",
12
32
  "lint:check": "eslint \"**/*.js\"",
@@ -19,6 +39,7 @@
19
39
  "eslint-config-prettier": "^8.3.0",
20
40
  "eslint-plugin-import": "^2.25.4",
21
41
  "eslint-plugin-prettier": "^4.0.0",
42
+ "jest": "^27.5.1",
22
43
  "prettier": "^2.5.1",
23
44
  "typescript": "^4.5.5"
24
45
  }
@@ -0,0 +1,2 @@
1
+ export * from './manifest';
2
+ export * from './constants';
@@ -3,6 +3,7 @@ import { QualityLabel } from './utils';
3
3
 
4
4
  declare class Manifest extends ProcessedManifest {
5
5
  constructor(manifest: ProcessedManifest);
6
+
6
7
  getVideoTrack(height: number): VideoTrack;
7
8
  getAudioTracks(languages: string[]): AudioTrack[];
8
9
  getSubtitleTracks(languages: string[]): SubtitleTrack[];
package/.eslintrc.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "env": { "es2021": true, "node": true },
3
- "extends": ["eslint:recommended", "plugin:prettier/recommended"],
4
- "parserOptions": { "ecmaVersion": 2021 },
5
- "rules": {
6
- "arrow-parens": ["error", "always"],
7
- "no-unused-vars": "warn"
8
- }
9
- }
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "printWidth": 100,
3
- "semi": true,
4
- "singleQuote": true,
5
- "tabWidth": 2,
6
- "trailingComma": "es5"
7
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "moduleResolution": "node",
5
- "strict": true,
6
- "baseUrl": ".",
7
- "preserveWatchOutput": true,
8
- "skipLibCheck": true
9
- },
10
- "include": ["types/**/*.ts"]
11
- }