@secret-momo/utils 1.4.0 → 1.4.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.
@@ -3,8 +3,8 @@ import type { DownloadOptions, DownloadResult } from './types';
3
3
  * 使用 aria2c 下载视频资源到指定目录。
4
4
  *
5
5
  * 下载前会检查本机是否安装 `aria2c`;若不存在会抛出异常,并提示通过
6
- * `brew install aria2` 安装。下载时使用 `aria2c -x8 -s8 -k1M` 参数,
7
- * 并根据 URL 或响应 `Content-Type` 推断视频扩展名。
6
+ * `brew install aria2` 安装。下载时使用 `aria2c -x8 -s8 -k1M` 参数和抖音
7
+ * referer,并根据 URL 或响应 `Content-Type` 推断视频扩展名。
8
8
  *
9
9
  * @param options 下载配置
10
10
  * @param options.url 视频资源 URL
@@ -1 +1 @@
1
- import{mkdirSync as a}from"node:fs";import{join as c,basename as u}from"node:path";import{execFile as n}from"node:child_process";import{promisify as m}from"node:util";import{dateTimeToNow as s}from"../date-time.js";import{fetch as f}from"../fetch.js";import{logger as l}from"../pino.js";import{pickVideoExtension as d}from"./extension.js";import{fileSize as p}from"../file.js";const t=m(n);async function w(){try{await t("aria2c",["--version"])}catch(r){throw r.code==="ENOENT"?new Error("\u672A\u627E\u5230 aria2c \u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u5148\u4F7F\u7528 brew install aria2 \u5B89\u88C5\u3002",{cause:r}):r}}async function y(r){try{return(await f(r,{method:"HEAD"})).headers.get("content-type")}catch{return null}}async function h({url:r,dir:e}){await w();try{a(e,{recursive:!0});const i=d(r,await y(r)),o=c(e,`${s("YYYYMMDD_HHmmss")}.${i}`);return await t("aria2c",["-x8","-s8","-k1M","-d",e,"-o",u(o),r]),{isSuccess:!0,filePath:o,fileSize:await p(o)}}catch(i){return l.child({name:"aria2DownloadVideo"}).error(i),{isSuccess:!1,error:i}}}export{h as aria2DownloadVideo};
1
+ import{mkdirSync as a}from"node:fs";import{join as c,basename as u}from"node:path";import{execFile as n}from"node:child_process";import{promisify as m}from"node:util";import{dateTimeToNow as s}from"../date-time.js";import{fetch as f}from"../fetch.js";import{logger as w}from"../pino.js";import{pickVideoExtension as d}from"./extension.js";import{fileSize as l}from"../file.js";const t=m(n);async function p(){try{await t("aria2c",["--version"])}catch(r){throw r.code==="ENOENT"?new Error("\u672A\u627E\u5230 aria2c \u547D\u4EE4\u884C\u5DE5\u5177\uFF0C\u8BF7\u5148\u4F7F\u7528 brew install aria2 \u5B89\u88C5\u3002",{cause:r}):r}}async function y(r){try{return(await f(r,{method:"HEAD"})).headers.get("content-type")}catch{return null}}async function h({url:r,dir:e}){await p();try{a(e,{recursive:!0});const i=d(r,await y(r)),o=c(e,`${s("YYYYMMDD_HHmmss")}.${i}`);return await t("aria2c",["-x8","-s8","-k1M","--referer=https://www.douyin.com/","-d",e,"-o",u(o),r]),{isSuccess:!0,filePath:o,fileSize:await l(o)}}catch(i){return w.child({name:"aria2DownloadVideo"}).error(i),{isSuccess:!1,error:i}}}export{h as aria2DownloadVideo};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secret-momo/utils",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "engines": {