@lzwme/m3u8-dl 0.0.3 → 0.0.4
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/cjs/lib/m3u8-convert.js
CHANGED
|
@@ -11,13 +11,15 @@ async function m3u8Convert(options, data) {
|
|
|
11
11
|
let ffmpegSupport = (0, utils_1.isSupportFfmpeg)();
|
|
12
12
|
let filepath = (0, node_path_1.resolve)(options.saveDir, options.filename);
|
|
13
13
|
if (!ffmpegSupport)
|
|
14
|
-
filepath = filepath.replace(
|
|
14
|
+
filepath = filepath.replace(/\.mp4$/, '.ts');
|
|
15
15
|
if (!options.force && (0, node_fs_1.existsSync)(filepath))
|
|
16
16
|
return filepath;
|
|
17
17
|
utils_1.logger.info(`Starting ${ffmpegSupport ? 'convert to mp4' : 'merge into ts'} file:`, (0, console_log_colors_1.greenBright)(filepath));
|
|
18
18
|
if (ffmpegSupport) {
|
|
19
19
|
const inputFilePath = (0, node_path_1.resolve)(options.cacheDir, 'input.txt');
|
|
20
|
-
|
|
20
|
+
let filesAllArr = data.map(d => (0, node_path_1.resolve)(d.tsOut)).filter(d => (0, node_fs_1.existsSync)(d));
|
|
21
|
+
if (process.platform === 'win32')
|
|
22
|
+
filesAllArr = filesAllArr.map(d => d.replaceAll('\\', '/'));
|
|
21
23
|
await node_fs_1.promises.writeFile(inputFilePath, 'ffconcat version 1.0\nfile ' + filesAllArr.join('\nfile '));
|
|
22
24
|
const cmd = `ffmpeg -y -f concat -safe 0 -i ${inputFilePath} -acodec copy -vcodec copy -absf aac_adtstoasc ${filepath}`;
|
|
23
25
|
utils_1.logger.debug('[convert to mp4]cmd:', (0, console_log_colors_1.cyan)(cmd));
|
|
@@ -26,12 +28,13 @@ async function m3u8Convert(options, data) {
|
|
|
26
28
|
if (r.error)
|
|
27
29
|
utils_1.logger.error('Conversion to mp4 failed. Please confirm that `ffmpeg` is installed!', r.stderr);
|
|
28
30
|
}
|
|
29
|
-
|
|
31
|
+
if (!ffmpegSupport) {
|
|
32
|
+
filepath = filepath.replace(/\.mp4$/, '.ts');
|
|
30
33
|
await node_fs_1.promises.writeFile(filepath, Buffer.concat(data.map(d => (0, node_fs_1.readFileSync)(d.tsOut))));
|
|
31
34
|
}
|
|
32
|
-
if ((0, node_fs_1.existsSync)(filepath))
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
+
if (!(0, node_fs_1.existsSync)(filepath))
|
|
36
|
+
return '';
|
|
37
|
+
utils_1.logger.info(`File saved[${(0, console_log_colors_1.magentaBright)((0, helper_1.formatByteSize)((0, node_fs_1.statSync)(filepath).size))}]:`, (0, console_log_colors_1.greenBright)(filepath));
|
|
35
38
|
return filepath;
|
|
36
39
|
}
|
|
37
40
|
exports.m3u8Convert = m3u8Convert;
|
package/cjs/lib/m3u8-download.js
CHANGED
|
@@ -45,8 +45,6 @@ async function formatOptions(url, opts) {
|
|
|
45
45
|
options.filename += '.mp4';
|
|
46
46
|
if (!options.cacheDir)
|
|
47
47
|
options.cacheDir = `cache/${urlMd5}`;
|
|
48
|
-
if (!(0, node_fs_1.existsSync)(options.cacheDir))
|
|
49
|
-
await node_fs_1.promises.mkdir(options.cacheDir, { recursive: true });
|
|
50
48
|
if (options.headers)
|
|
51
49
|
utils_1.request.setHeaders(options.headers);
|
|
52
50
|
if (options.debug) {
|
|
@@ -75,6 +73,8 @@ async function m3u8InfoParse(url, options = {}) {
|
|
|
75
73
|
}
|
|
76
74
|
async function preDownLoad(url, options) {
|
|
77
75
|
const result = await m3u8InfoParse(url, options);
|
|
76
|
+
if (!result.m3u8Info)
|
|
77
|
+
return;
|
|
78
78
|
for (const info of result.m3u8Info.data) {
|
|
79
79
|
if (!exports.workPoll.freeNum)
|
|
80
80
|
return;
|
|
@@ -172,7 +172,7 @@ async function m3u8Download(url, options = {}) {
|
|
|
172
172
|
await barrier.wait();
|
|
173
173
|
if (stats.tsFailed === 0) {
|
|
174
174
|
result.filepath = await (0, m3u8_convert_1.m3u8Convert)(options, m3u8Info.data);
|
|
175
|
-
if ((0, node_fs_1.existsSync)(options.cacheDir) && options.delCache)
|
|
175
|
+
if (result.filepath && (0, node_fs_1.existsSync)(options.cacheDir) && options.delCache)
|
|
176
176
|
(0, fe_utils_1.rmrfAsync)(options.cacheDir);
|
|
177
177
|
}
|
|
178
178
|
else
|
package/cjs/lib/ts-download.js
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.tsDownload = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
6
7
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
8
|
+
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
7
9
|
const utils_1 = require("./utils");
|
|
8
10
|
async function tsDownload(info, cryptoInfo) {
|
|
9
11
|
try {
|
|
@@ -13,6 +15,7 @@ async function tsDownload(info, cryptoInfo) {
|
|
|
13
15
|
if (r.response.statusCode === 200) {
|
|
14
16
|
utils_1.logger.debug('\n', info);
|
|
15
17
|
const data = cryptoInfo.key ? aesDecrypt(r.buffer, cryptoInfo) : r.buffer;
|
|
18
|
+
(0, fe_utils_1.mkdirp)((0, node_path_1.dirname)(info.tsOut));
|
|
16
19
|
await node_fs_1.promises.writeFile(info.tsOut, data);
|
|
17
20
|
info.tsSize = r.buffer.byteLength;
|
|
18
21
|
return true;
|
|
@@ -41,7 +41,10 @@ async function m3u8BatchDownload(urls, options) {
|
|
|
41
41
|
if (key) {
|
|
42
42
|
const o = { ...tasks.get(key) };
|
|
43
43
|
tasks.delete(key);
|
|
44
|
-
o.onProgress
|
|
44
|
+
const p = o.onProgress;
|
|
45
|
+
o.onProgress = (finished, total, info) => {
|
|
46
|
+
if (p)
|
|
47
|
+
p(finished, total, info);
|
|
45
48
|
if (!preDLing && keyNext && tasks.size && m3u8_download_1.workPoll.freeNum > 1 && total - finished < options.threadNum) {
|
|
46
49
|
utils_1.logger.debug('\n[预下载下一集]', 'freeNum:', m3u8_download_1.workPoll.freeNum, 'totalNum:', m3u8_download_1.workPoll.totalNum, 'totalTask:', m3u8_download_1.workPoll.totalTask, tasks.size);
|
|
47
50
|
preDLing = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lzwme/m3u8-dl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Batch download of m3u8 files and convert to mp4",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"types": "cjs/index.d.ts",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"registry": "https://registry.npmjs.com"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@lzwme/fed-lint-helper": "^2.3.
|
|
48
|
-
"@types/node": "^
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^5.59.
|
|
50
|
-
"@typescript-eslint/parser": "^5.59.
|
|
51
|
-
"eslint": "^8.
|
|
47
|
+
"@lzwme/fed-lint-helper": "^2.3.2",
|
|
48
|
+
"@types/node": "^20.2.0",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.59.6",
|
|
50
|
+
"@typescript-eslint/parser": "^5.59.6",
|
|
51
|
+
"eslint": "^8.40.0",
|
|
52
52
|
"eslint-config-prettier": "^8.8.0",
|
|
53
53
|
"eslint-plugin-prettier": "^4.2.1",
|
|
54
54
|
"husky": "^8.0.3",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"commander": "^10.0.1",
|
|
62
62
|
"console-log-colors": "^0.4.0",
|
|
63
63
|
"enquirer": "^2.3.6",
|
|
64
|
-
"m3u8-parser": "^6.
|
|
64
|
+
"m3u8-parser": "^6.1.0"
|
|
65
65
|
},
|
|
66
66
|
"files": [
|
|
67
67
|
"cjs",
|