@lzwme/m3u8-dl 1.4.3 → 1.5.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/cjs/cli.js CHANGED
@@ -65,6 +65,7 @@ commander_1.program
65
65
  .option('-S, --save-dir <dirpath>', '下载文件保存的路径。默认为当前目录')
66
66
  .option('--no-del-cache', '下载成功后是否删除临时文件。默认为 true。保存临时文件可以在重复下载时识别缓存')
67
67
  .option('--no-convert', '下载成功后,是否不合并转换为 mp4 文件。默认为 true。')
68
+ .option('--use-global-ffmpeg', '是否使用系统安装的 ffmpeg 而不是内置的 ffmpeg-static')
68
69
  .option('-H, --headers <headers>', '自定义请求头。格式为 key1=value1\nkey2=value2')
69
70
  .option('-T, --type <type>', '指定下载类型。默认根据URL自动识别,如果是批量下载多个不同 URL 类型,请不要设置。可选值:m3u8, file, parser')
70
71
  .option('-I, --ignore-segments <time-segments>', '忽略的视频片段,用-分割起始时间点,多个用逗号分隔。如:0-10,20-30')
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.m3u8Convert = m3u8Convert;
4
7
  const node_fs_1 = require("node:fs");
5
8
  const node_path_1 = require("node:path");
6
9
  const fe_utils_1 = require("@lzwme/fe-utils");
7
10
  const console_log_colors_1 = require("console-log-colors");
11
+ const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
8
12
  const utils_1 = require("./utils");
9
13
  async function m3u8Convert(options, data) {
10
- let ffmpegSupport = (0, utils_1.isSupportFfmpeg)();
14
+ const useGlobal = options.useGlobalFfmpeg || false;
15
+ const ffmpegBin = useGlobal ? 'ffmpeg' : ffmpeg_static_1.default;
16
+ let ffmpegSupport = (0, utils_1.isSupportFfmpeg)(ffmpegBin);
11
17
  let filepath = (0, node_path_1.resolve)(options.saveDir, options.filename);
12
18
  if (!ffmpegSupport)
13
19
  filepath = filepath.replace(/\.mp4$/, '.ts');
@@ -28,13 +34,13 @@ async function m3u8Convert(options, data) {
28
34
  }
29
35
  }
30
36
  // ffmpeg -i nz.ts -c copy -map 0:v -map 0:a -bsf:a aac_adtstoasc nz.mp4
31
- // const cmd = `ffmpeg -async 1 -y -f concat -safe 0 -i "${ffconcatFile}" -acodec copy -vcodec copy -bsf:a aac_adtstoasc ${headersString} "${filepath}"`;
32
- const cmd = `ffmpeg -async 1 -y -f concat -safe 0 -i "${ffconcatFile}" -c:v copy -c:a copy -movflags +faststart -fflags +genpts -bsf:a aac_adtstoasc ${headersString} "${filepath}"`;
37
+ // const cmd = `"${ffmpegBin}" -async 1 -y -f concat -safe 0 -i "${ffconcatFile}" -acodec copy -vcodec copy -bsf:a aac_adtstoasc ${headersString} "${filepath}"`;
38
+ const cmd = `"${ffmpegBin}" -async 1 -y -f concat -safe 0 -i "${ffconcatFile}" -c:v copy -c:a copy -movflags +faststart -fflags +genpts -bsf:a aac_adtstoasc ${headersString} "${filepath}"`;
33
39
  utils_1.logger.debug('[convert to mp4]cmd:', (0, console_log_colors_1.cyan)(cmd));
34
40
  const r = (0, fe_utils_1.execSync)(cmd);
35
41
  ffmpegSupport = !r.error;
36
42
  if (r.error)
37
- utils_1.logger.error('Conversion to mp4 failed. Please confirm that `ffmpeg` is installed!', r.stderr);
43
+ utils_1.logger.error(`Conversion to mp4 failed. Please confirm that \`${useGlobal ? 'ffmpeg' : 'ffmpeg-static'}\` is ${useGlobal ? 'installed' : 'available'}!`, r.stderr);
38
44
  else
39
45
  (0, node_fs_1.unlinkSync)(ffconcatFile);
40
46
  }
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.workPollPublic = exports.downloadQueue = exports.DownloadQueue = void 0;
4
7
  exports.preDownLoad = preDownLoad;
@@ -9,6 +12,7 @@ const node_path_1 = require("node:path");
9
12
  const fe_utils_1 = require("@lzwme/fe-utils");
10
13
  const helper_1 = require("@lzwme/fe-utils/cjs/common/helper");
11
14
  const console_log_colors_1 = require("console-log-colors");
15
+ const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
12
16
  const format_options_js_1 = require("./format-options.js");
13
17
  const local_play_js_1 = require("./local-play.js");
14
18
  const m3u8_convert_js_1 = require("./m3u8-convert.js");
@@ -87,8 +91,9 @@ const cache = {
87
91
  const tsDlFile = (0, node_path_1.resolve)(__dirname, './ts-download.js');
88
92
  exports.workPollPublic = new worker_pool_js_1.WorkerPool(tsDlFile);
89
93
  async function m3u8InfoParse(u, o = {}) {
94
+ const ffmpegBin = o.useGlobalFfmpeg ? 'ffmpeg' : ffmpeg_static_1.default;
95
+ const ext = (0, utils_js_1.isSupportFfmpeg)(ffmpegBin) ? '.mp4' : '.ts';
90
96
  const { url, options, urlMd5 } = (0, format_options_js_1.formatOptions)(u, o);
91
- const ext = (0, utils_js_1.isSupportFfmpeg)() ? '.mp4' : '.ts';
92
97
  /** 最终合并转换后的文件路径 */
93
98
  let filepath = (0, node_path_1.resolve)(options.saveDir, options.filename);
94
99
  if (!filepath.endsWith(ext))
@@ -9,7 +9,7 @@ export declare const getRetry: <T = string>(url: string, headers?: OutgoingHttpH
9
9
  response: import("http").IncomingMessage;
10
10
  }>;
11
11
  export declare const logger: NLogger;
12
- export declare function isSupportFfmpeg(): boolean;
12
+ export declare function isSupportFfmpeg(ffmpegBin: string): boolean;
13
13
  export declare function findFiles(apidir?: string, validate?: (filepath: string, stat: Stats) => boolean): string[];
14
14
  /** 获取重定向后的 URL */
15
15
  export declare function getLocation(url: string, method?: string): Promise<string>;
package/cjs/lib/utils.js CHANGED
@@ -24,9 +24,9 @@ const getRetry = (url, headers, retries = 3) => (0, fe_utils_1.retry)(() => expo
24
24
  exports.getRetry = getRetry;
25
25
  exports.logger = fe_utils_1.NLogger.getLogger('[M3U8-DL]', { color: fe_utils_1.color });
26
26
  let _isSupportFfmpeg = null;
27
- function isSupportFfmpeg() {
27
+ function isSupportFfmpeg(ffmpegBin) {
28
28
  if (null == _isSupportFfmpeg)
29
- _isSupportFfmpeg = (0, fe_utils_1.execSync)('ffmpeg -version').stderr === '';
29
+ _isSupportFfmpeg = (0, fe_utils_1.execSync)(`${ffmpegBin} -version`).stderr === '';
30
30
  return _isSupportFfmpeg;
31
31
  }
32
32
  function findFiles(apidir, validate) {
@@ -140,6 +140,8 @@ export interface M3u8DLOptions {
140
140
  * - 'parser':下载 VideoParser 支持解析的平台视频文件
141
141
  */
142
142
  type?: 'm3u8' | 'file' | 'parser';
143
+ /** 是否使用系统安装的 ffmpeg 而不是内置的 ffmpeg-static。默认为 false */
144
+ useGlobalFfmpeg?: boolean;
143
145
  }
144
146
  export interface M3u8DLResult extends Partial<DownloadResult> {
145
147
  /** 下载进度统计 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lzwme/m3u8-dl",
3
- "version": "1.4.3",
3
+ "version": "1.5.0",
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",
@@ -69,6 +69,7 @@
69
69
  "commander": "^14.0.0",
70
70
  "console-log-colors": "^0.5.0",
71
71
  "enquirer": "^2.4.1",
72
+ "ffmpeg-static": "^5.2.0",
72
73
  "m3u8-parser": "^7.2.0"
73
74
  },
74
75
  "files": [