tools_batch_files 1.0.32 → 1.0.33
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/package.json +1 -1
- package/src/audioFn/audioBatch.js +27 -33
- package/utils/logger.js +1 -1
- package/utils/settleFiles.js +27 -11
package/package.json
CHANGED
@@ -200,10 +200,8 @@ const archiveZip = (fileName, inputPath, originFilePath) => {
|
|
200
200
|
* 获取 元数据
|
201
201
|
*/
|
202
202
|
const getMetadata = async (
|
203
|
-
fileName,
|
204
|
-
indexFilePath,
|
205
203
|
originFilePath,
|
206
|
-
{ rowFileName, title, keyword }
|
204
|
+
{ rowFileName, title, keyword, index }
|
207
205
|
) => {
|
208
206
|
//源音频数据
|
209
207
|
const photoMetadataComand = ffmpeg(originFilePath);
|
@@ -221,6 +219,7 @@ const getMetadata = async (
|
|
221
219
|
duration: "",
|
222
220
|
tag_ids: "3",
|
223
221
|
source_from: "sound_1",
|
222
|
+
anotherId: rowFileName + index,
|
224
223
|
};
|
225
224
|
|
226
225
|
await new Promise((resolve, reject) => {
|
@@ -268,8 +267,8 @@ const postData = (dataParams, indexFilePath) => {
|
|
268
267
|
logger("等待接口返回结果……");
|
269
268
|
|
270
269
|
// return axios.post("http://192.168.102.61:9999/upload/sound", formData, {
|
271
|
-
// return axios.post("http://
|
272
|
-
return axios.post("http://
|
270
|
+
// return axios.post("http://127.0.0.1:9999/upload/sound", formData, {
|
271
|
+
return axios.post("http://192.168.101.149:9999/upload/sound", formData, {
|
273
272
|
headers: {
|
274
273
|
"Content-Type": "multipart/form-data",
|
275
274
|
},
|
@@ -305,17 +304,14 @@ async function postDataWithRetry(
|
|
305
304
|
fs.rmdirSync(indexFilePath, { recursive: true });
|
306
305
|
return;
|
307
306
|
} else {
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
);
|
307
|
+
logger(`请求失败,重试中... (${retryCount + 1}/${maxRetries})`);
|
308
|
+
logger(`请求code!==200: ${resData.data.code}${resData.data.msg}`);
|
309
|
+
// 延时等待一段时间后再进行重试
|
310
|
+
await new Promise((resolve) => setTimeout(resolve, 100)); // 等待0.1秒
|
311
|
+
retryCount++;
|
312
312
|
}
|
313
313
|
} catch (error) {
|
314
|
-
|
315
|
-
logger(error);
|
316
|
-
retryCount++;
|
317
|
-
// 延时等待一段时间后再进行重试
|
318
|
-
await new Promise((resolve) => setTimeout(resolve, 100)); // 等待0.1秒
|
314
|
+
throw new Error("重试机制错误!" + error);
|
319
315
|
}
|
320
316
|
}
|
321
317
|
// 如果达到最大重试次数仍然失败,则抛出异常
|
@@ -326,14 +322,17 @@ async function postDataWithRetry(
|
|
326
322
|
* 任务
|
327
323
|
*/
|
328
324
|
const task = async (row, index, hash) => {
|
325
|
+
//index文件夹 output/0
|
326
|
+
const indexFilePath = path.join(workDir, "output", index + "");
|
327
|
+
let fileName = row.fileName;
|
328
|
+
const rowFileName = row.fileName;
|
329
|
+
const title = row.title;
|
330
|
+
const keyword = row.keyword;
|
329
331
|
try {
|
330
332
|
logger(
|
331
333
|
"**************************" + row.fileName + "**************************"
|
332
334
|
);
|
333
335
|
// Excel的列名分别为: fileName title keyword
|
334
|
-
let fileName = row.fileName;
|
335
|
-
const title = row.title;
|
336
|
-
const keyword = row.keyword;
|
337
336
|
// const keywordArr = row.keyword.split(",");
|
338
337
|
// const filteredArray = keywordArr.filter((item) => item.trim() !== "");
|
339
338
|
// const keyword = filteredArray.join(" ");
|
@@ -358,26 +357,21 @@ const task = async (row, index, hash) => {
|
|
358
357
|
logger(`-------------------${new Date()}------------------`);
|
359
358
|
|
360
359
|
logger("原文件路径:" + originFilePath);
|
360
|
+
logger(`第${index}条原文件路径:${originFilePath}`);
|
361
361
|
|
362
362
|
if (!originFilePath) {
|
363
|
-
logger(
|
363
|
+
logger(`第${index}条音频文件 ${fileName} 不存在`);
|
364
364
|
return;
|
365
365
|
}
|
366
366
|
|
367
|
-
//index文件夹 output/0
|
368
|
-
const indexFilePath = path.join(workDir, "output", index + "");
|
369
|
-
|
370
367
|
await fs_asnyc.access(originFilePath, fs_asnyc.constants.F_OK);
|
371
|
-
logFileSize(originFilePath);
|
372
|
-
const dataParams = await getMetadata(
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
keyword,
|
379
|
-
}
|
380
|
-
);
|
368
|
+
logFileSize(originFilePath, index);
|
369
|
+
const dataParams = await getMetadata(originFilePath, {
|
370
|
+
rowFileName,
|
371
|
+
title,
|
372
|
+
keyword,
|
373
|
+
index,
|
374
|
+
});
|
381
375
|
await wavAudio(indexFilePath, originFilePath, fileName);
|
382
376
|
await watermarkAudio(
|
383
377
|
indexFilePath,
|
@@ -432,7 +426,7 @@ const run = (index, data, hash) => {
|
|
432
426
|
return;
|
433
427
|
}
|
434
428
|
|
435
|
-
task(row, index)
|
429
|
+
task(row, index, hash)
|
436
430
|
.then(() => {
|
437
431
|
taskIndex++;
|
438
432
|
run(taskIndex, data, hash);
|
@@ -457,7 +451,7 @@ const main = () => {
|
|
457
451
|
//当前任务hash
|
458
452
|
let hash = "";
|
459
453
|
let jsonData = [];
|
460
|
-
logger("
|
454
|
+
logger("》》》》》》》》》》音频批量任务任务开始《《《《《《《《《《" + hash);
|
461
455
|
logger("当前目录: " + workDir + ";工作目录: " + exeDir);
|
462
456
|
|
463
457
|
// 读取success.txt,判断是否是 异常中断,
|
package/utils/logger.js
CHANGED
@@ -18,7 +18,7 @@ const logger = (log) => {
|
|
18
18
|
* @param {*} 日志内容 hash index fileName
|
19
19
|
*/
|
20
20
|
const successLogger = (hash, index, fileName) => {
|
21
|
-
console.log(
|
21
|
+
console.log(fileName);
|
22
22
|
fs.writeFileSync("success.txt", hash + " " + index + " " + fileName + "\n", {
|
23
23
|
flag: "a",
|
24
24
|
});
|
package/utils/settleFiles.js
CHANGED
@@ -19,10 +19,10 @@ function findFileInDir(dir, fileName) {
|
|
19
19
|
return null;
|
20
20
|
}
|
21
21
|
|
22
|
-
function logFileSize(path) {
|
22
|
+
function logFileSize(path, index) {
|
23
23
|
const fileSize = fs.statSync(path).size / (1024 * 1024);
|
24
24
|
const formattedSize = fileSize.toFixed(2); // 保留两位小数
|
25
|
-
logger(
|
25
|
+
logger(`第${index}条音频大小:${formattedSize}M`);
|
26
26
|
}
|
27
27
|
|
28
28
|
/**
|
@@ -44,14 +44,28 @@ function ensureDirSync(dirpath) {
|
|
44
44
|
* 判断文件是否存在
|
45
45
|
*/
|
46
46
|
function isExist(filePath) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
try {
|
48
|
+
fs.accessSync(filePath, fs.constants.F_OK);
|
49
|
+
console.log("存在");
|
50
|
+
return true;
|
51
|
+
} catch (err) {
|
52
|
+
console.log("错了");
|
53
|
+
console.error(err);
|
54
|
+
return false;
|
55
|
+
}
|
54
56
|
}
|
57
|
+
// function isExist(filePath) {
|
58
|
+
// fs.access(filePath, fs.constants.F_OK, (err) => {
|
59
|
+
// if (err) {
|
60
|
+
// console.log(err);
|
61
|
+
|
62
|
+
// return false;
|
63
|
+
// } else {
|
64
|
+
// console.log(555);
|
65
|
+
// return true;
|
66
|
+
// }
|
67
|
+
// });
|
68
|
+
// }
|
55
69
|
|
56
70
|
/**
|
57
71
|
* 上传失败后,存入新文件夹(手动创建)
|
@@ -68,10 +82,12 @@ function readTxt(path) {
|
|
68
82
|
try {
|
69
83
|
const data = fs.readFileSync(path, "utf-8");
|
70
84
|
const arr = data.split("\n").map((line) => line.trim()); // 删除每行两侧的空白符
|
71
|
-
const
|
85
|
+
const filteredArray = arr.filter((item) => item !== ""); //去除空项
|
86
|
+
|
87
|
+
const lastItem = filteredArray[filteredArray.length - 1];
|
72
88
|
|
73
89
|
const loghash = lastItem.split(" ")[0];
|
74
|
-
const lastItemIndex = lastItem.split(" ")[1];
|
90
|
+
const lastItemIndex = parseInt(lastItem.split(" ")[1]);
|
75
91
|
return { loghash, lastItemIndex };
|
76
92
|
} catch (error) {
|
77
93
|
console.error("readErrorTxt函数出错:", error);
|