dasha 3.1.8 → 3.2.0
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/lib/track.js +26 -10
- package/package.json +29 -29
package/lib/track.js
CHANGED
|
@@ -11,7 +11,9 @@ const parseMimes = (codecs) =>
|
|
|
11
11
|
const createResolutionFilter = (videos) => {
|
|
12
12
|
return ({ width, height }) => {
|
|
13
13
|
return videos.filter(
|
|
14
|
-
(track) =>
|
|
14
|
+
(track) =>
|
|
15
|
+
(!width || track.width === width) &&
|
|
16
|
+
(!height || track.height === height),
|
|
15
17
|
);
|
|
16
18
|
};
|
|
17
19
|
};
|
|
@@ -30,9 +32,13 @@ const createVideoCodecFilter = (videos) => createCodecFilter(videos);
|
|
|
30
32
|
const createVideoQualityFilter = (videos) => {
|
|
31
33
|
return (quality) => {
|
|
32
34
|
if (!quality) return [getBestTrack(videos)];
|
|
33
|
-
const trackQuality = String(quality).includes('p')
|
|
35
|
+
const trackQuality = String(quality).includes('p')
|
|
36
|
+
? quality
|
|
37
|
+
: `${quality}p`;
|
|
34
38
|
const results = videos.filter((track) => track.quality === trackQuality);
|
|
35
|
-
results.
|
|
39
|
+
results.sort((a, b) =>
|
|
40
|
+
b.bitrate && a.bitrate ? b.bitrate.bps - a.bitrate.bps : 0,
|
|
41
|
+
);
|
|
36
42
|
return results.length ? results : [getBestTrack(videos)];
|
|
37
43
|
};
|
|
38
44
|
};
|
|
@@ -49,13 +55,17 @@ const createAudioLanguageFilter = (audios) => {
|
|
|
49
55
|
if (!alreadyAdded) languages.push(audio.language);
|
|
50
56
|
}
|
|
51
57
|
} else {
|
|
52
|
-
audios.
|
|
58
|
+
audios.sort((a, b) =>
|
|
59
|
+
a.bitrate && b.bitrate ? b.bitrate.bps - a.bitrate.bps : 0,
|
|
60
|
+
);
|
|
53
61
|
return audios.slice(0, maxTracksPerLanguage);
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
const filtered = [];
|
|
57
65
|
for (const language of languages) {
|
|
58
|
-
const tracks = audios.filter((track) =>
|
|
66
|
+
const tracks = audios.filter((track) =>
|
|
67
|
+
track.language?.startsWith(language),
|
|
68
|
+
);
|
|
59
69
|
filtered.push(...tracks);
|
|
60
70
|
}
|
|
61
71
|
const results = [];
|
|
@@ -75,7 +85,8 @@ const createAudioLanguageFilter = (audios) => {
|
|
|
75
85
|
const createAudioChannelsFilter = (audios) => {
|
|
76
86
|
return (channels) => {
|
|
77
87
|
if (!channels) return audios;
|
|
78
|
-
const value =
|
|
88
|
+
const value =
|
|
89
|
+
typeof channels === 'string' ? parseFloat(channels) : channels;
|
|
79
90
|
return audios.filter((track) => track.channels === value);
|
|
80
91
|
};
|
|
81
92
|
};
|
|
@@ -85,18 +96,23 @@ const createSubtitleLanguageFilter = (subtitles) => {
|
|
|
85
96
|
if (!languages.length) return subtitles;
|
|
86
97
|
return subtitles.filter((track) =>
|
|
87
98
|
languages.some(
|
|
88
|
-
(language) =>
|
|
99
|
+
(language) =>
|
|
100
|
+
track.language?.startsWith(language) ||
|
|
101
|
+
track.label?.startsWith(language),
|
|
89
102
|
),
|
|
90
103
|
);
|
|
91
104
|
};
|
|
92
105
|
};
|
|
93
106
|
|
|
94
|
-
const filterByResolution = (tracks, resolution) =>
|
|
95
|
-
|
|
107
|
+
const filterByResolution = (tracks, resolution) =>
|
|
108
|
+
createResolutionFilter(tracks)(resolution);
|
|
109
|
+
const filterByQuality = (tracks, quality) =>
|
|
110
|
+
createVideoQualityFilter(tracks)(quality);
|
|
96
111
|
const filterByCodecs = (tracks, codecs) => createCodecFilter(tracks)(codecs);
|
|
97
112
|
const filterByLanguages = (tracks, languages, maxTracksPerLanguage) =>
|
|
98
113
|
createAudioLanguageFilter(tracks)(languages, maxTracksPerLanguage);
|
|
99
|
-
const filterByChannels = (tracks, channels) =>
|
|
114
|
+
const filterByChannels = (tracks, channels) =>
|
|
115
|
+
createAudioChannelsFilter(tracks)(channels);
|
|
100
116
|
|
|
101
117
|
module.exports = {
|
|
102
118
|
parseMimes,
|
package/package.json
CHANGED
|
@@ -1,43 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dasha",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Streaming manifest parser",
|
|
5
|
-
"files": [
|
|
6
|
-
"dasha.js",
|
|
7
|
-
"lib",
|
|
8
|
-
"types"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "npm run lint && npm run types && node --test",
|
|
12
|
-
"types": "tsc -p tsconfig.json",
|
|
13
|
-
"lint": "eslint . && prettier --check .",
|
|
14
|
-
"fix": "eslint . --fix && prettier --write .",
|
|
15
|
-
"build": "tsup dasha.js --format esm,cjs",
|
|
16
|
-
"prepublishOnly": "npm run build"
|
|
17
|
-
},
|
|
18
|
-
"main": "dasha.js",
|
|
19
|
-
"types": "./types/dasha.d.ts",
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "https://github.com/vitalygashkov/dasha"
|
|
23
|
-
},
|
|
24
5
|
"keywords": [
|
|
25
|
-
"
|
|
6
|
+
"adaptive",
|
|
26
7
|
"dash",
|
|
27
8
|
"hls",
|
|
28
|
-
"adaptive",
|
|
29
|
-
"mpd",
|
|
30
9
|
"m3u8",
|
|
31
10
|
"manifest",
|
|
11
|
+
"mpd",
|
|
12
|
+
"mpeg",
|
|
32
13
|
"playlist"
|
|
33
14
|
],
|
|
34
|
-
"author": "Vitaly Gashkov <vitalygashkov@vk.com>",
|
|
35
|
-
"license": "MIT",
|
|
36
|
-
"readmeFilename": "README.md",
|
|
37
15
|
"bugs": {
|
|
38
16
|
"url": "https://github.com/vitalygashkov/dasha/issues",
|
|
39
17
|
"email": "vitalygashkov@vk.com"
|
|
40
18
|
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Vitaly Gashkov <vitalygashkov@vk.com>",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/vitalygashkov/dasha"
|
|
24
|
+
},
|
|
41
25
|
"funding": [
|
|
42
26
|
{
|
|
43
27
|
"type": "individual",
|
|
@@ -48,8 +32,20 @@
|
|
|
48
32
|
"url": "https://www.patreon.com/vitalygashkov"
|
|
49
33
|
}
|
|
50
34
|
],
|
|
51
|
-
"
|
|
52
|
-
"
|
|
35
|
+
"files": [
|
|
36
|
+
"dasha.js",
|
|
37
|
+
"lib",
|
|
38
|
+
"types"
|
|
39
|
+
],
|
|
40
|
+
"main": "dasha.js",
|
|
41
|
+
"types": "./types/dasha.d.ts",
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "npm run lint && npm run types && node --test",
|
|
44
|
+
"types": "tsc -p tsconfig.json",
|
|
45
|
+
"lint": "eslint . && prettier --check .",
|
|
46
|
+
"fix": "eslint . --fix && prettier --write .",
|
|
47
|
+
"build": "tsup dasha.js --format esm,cjs",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
53
49
|
},
|
|
54
50
|
"dependencies": {
|
|
55
51
|
"m3u8-parser": "^7.2.0"
|
|
@@ -64,5 +60,9 @@
|
|
|
64
60
|
"prettier": "^3.4.2",
|
|
65
61
|
"tsup": "^8.3.5",
|
|
66
62
|
"typescript": "^5.7.2"
|
|
67
|
-
}
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=22.19"
|
|
66
|
+
},
|
|
67
|
+
"readmeFilename": "README.md"
|
|
68
68
|
}
|