@lzwme/m3u8-dl 1.8.0 → 1.9.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
@@ -41,6 +41,7 @@ const i18n_js_1 = require("./lib/i18n.js");
41
41
  const utils_js_1 = require("./lib/utils.js");
42
42
  const video_search_js_1 = require("./lib/video-search.js");
43
43
  const m3u8_batch_download_1 = require("./m3u8-batch-download");
44
+ const index_js_1 = require("./video-parser/index.js");
44
45
  const pkg = (0, fe_utils_1.readJsonFileSync)((0, node_path_1.resolve)(__dirname, '../package.json'));
45
46
  process.on('unhandledRejection', r => {
46
47
  console.error(r);
@@ -54,7 +55,7 @@ process.on('SIGINT', signal => {
54
55
  process.exit();
55
56
  });
56
57
  // Initialize language before using t()
57
- const initialLang = (0, i18n_js_1.getLang)();
58
+ const initialLang = 'en'; // getLang();
58
59
  (0, i18n_js_1.setLanguage)(initialLang);
59
60
  commander_1.program
60
61
  .version(pkg.version, '-v, --version')
@@ -116,6 +117,17 @@ commander_1.program
116
117
  .action(async (keyword, options) => {
117
118
  await (0, video_search_js_1.VideoSerachAndDL)(keyword, options, getOptions());
118
119
  });
120
+ commander_1.program
121
+ .command('info <url>')
122
+ .description('解析视频 URL 并输出详细信息')
123
+ .option('--lang <lang>', (0, i18n_js_1.t)('cli.option.lang', initialLang))
124
+ .action(async (url) => {
125
+ getOptions(); // 处理语言设置
126
+ utils_js_1.logger.info('正在解析视频 URL:', url);
127
+ const result = await index_js_1.VideoParser.parse(url);
128
+ console.log(JSON.stringify(result, null, 2));
129
+ process.exit();
130
+ });
119
131
  commander_1.program.parse(process.argv);
120
132
  function getOptions() {
121
133
  const options = commander_1.program.opts();
@@ -12,6 +12,11 @@ export declare class VideoParser {
12
12
  static getPlatform(url: string): {
13
13
  url: string;
14
14
  platform: string;
15
+ errmsg?: undefined;
16
+ } | {
17
+ url: string;
18
+ platform: string;
19
+ errmsg: string;
15
20
  };
16
21
  /**
17
22
  * 获取所有支持的平台列表
@@ -33,8 +33,8 @@ class VideoParser {
33
33
  */
34
34
  static async parse(url, headers = {}) {
35
35
  const info = VideoParser.getPlatform(url);
36
- if (!info)
37
- return { code: 201, message: '不支持的视频平台' };
36
+ if (info.errmsg)
37
+ return { code: 400, message: info.errmsg || '不支持的视频平台' };
38
38
  const parserClass = VideoParser.platforms[info.platform].class;
39
39
  return await parserClass.parse(info.url, headers);
40
40
  }
@@ -72,8 +72,8 @@ class VideoParser {
72
72
  return { url, platform: 'unknown' };
73
73
  }
74
74
  catch (error) {
75
- console.error('解析 URL 失败', url, error);
76
- return { url, platform: 'unknown' };
75
+ // console.error('[parser]解析 URL 失败', url, (error as Error).message);
76
+ return { url, platform: 'unknown', errmsg: error.message };
77
77
  }
78
78
  }
79
79
  /**