mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: 1.0.6 修复了dy解析问题,加入重试机制
This commit is contained in:
parent
afac5f827c
commit
25d5493df4
@ -13,6 +13,7 @@ import { mkdirsSync } from "../utils/file.js";
|
|||||||
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
||||||
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
||||||
import { transMap, douyinTypeMap } from "../utils/constant.js"
|
import { transMap, douyinTypeMap } from "../utils/constant.js"
|
||||||
|
import { retry } from "../utils/common.js";
|
||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
|
|
||||||
|
|
||||||
@ -120,34 +121,39 @@ export class tools extends plugin {
|
|||||||
const douId = douRex.exec(res)[1];
|
const douId = douRex.exec(res)[1];
|
||||||
// const url = `https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=${ douId }`;
|
// const url = `https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=${ douId }`;
|
||||||
const url = `https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id=${douId}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333`;
|
const url = `https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id=${douId}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333`;
|
||||||
const resp = await fetch(url);
|
// 默认重试3次,每次间隔1s (防止SyntaxError: Unexpected token b in JSON at position 0)
|
||||||
const json = await resp.json();
|
retry(
|
||||||
const item = json.aweme_detail;
|
await (function (){
|
||||||
e.reply(`识别:抖音, ${item.desc}`);
|
return fetch(url).then(resp => resp.json())
|
||||||
const url_type_code = item.aweme_type;
|
})
|
||||||
const url_type = douyinTypeMap[url_type_code];
|
).then(resp_json => {
|
||||||
if (url_type === "video") {
|
const item = resp_json.aweme_detail;
|
||||||
const url_2 = item.video.play_addr.url_list[0];
|
e.reply(`识别:抖音, ${item.desc}`);
|
||||||
this.downloadVideo(url_2).then(video => {
|
const url_type_code = item.aweme_type;
|
||||||
e.reply(
|
const url_type = douyinTypeMap[url_type_code];
|
||||||
segment.video(
|
if (url_type === "video") {
|
||||||
`${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4`
|
const url_2 = item.video.play_addr.url_list[0];
|
||||||
)
|
this.downloadVideo(url_2).then(video => {
|
||||||
);
|
e.reply(
|
||||||
});
|
segment.video(
|
||||||
} else if (url_type === "image") {
|
`${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4`
|
||||||
// 无水印图片列表/No watermark image list
|
)
|
||||||
// let no_watermark_image_list = []
|
);
|
||||||
// 有水印图片列表/With watermark image list
|
});
|
||||||
// let watermark_image_list = []
|
} else if (url_type === "image") {
|
||||||
for (let i of item.images) {
|
|
||||||
// 无水印图片列表
|
// 无水印图片列表
|
||||||
// no_watermark_image_list.push(i.url_list[0])
|
// let no_watermark_image_list = []
|
||||||
// 有水印图片列表
|
// 有水印图片列表
|
||||||
// watermark_image_list.push(i.download_url_list[0])
|
// let watermark_image_list = []
|
||||||
e.reply(segment.image(i.download_url_list[0]));
|
for (let i of item.images) {
|
||||||
|
// 无水印图片列表
|
||||||
|
// no_watermark_image_list.push(i.url_list[0])
|
||||||
|
// 有水印图片列表
|
||||||
|
// watermark_image_list.push(i.download_url_list[0])
|
||||||
|
e.reply(segment.image(i.url_list[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
- {
|
- {
|
||||||
version: 1.0.5,
|
version: 1.0.6,
|
||||||
data:
|
data:
|
||||||
[
|
[
|
||||||
适配<span class="cmd">锅巴</span>插件,方便查看和修改配置,
|
适配<span class="cmd">锅巴</span>插件,方便查看和修改配置,
|
||||||
|
@ -43,4 +43,29 @@ function autoTask(func, time, groupList, isAutoPush = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { jFeatch, autoTask };
|
/**
|
||||||
|
* 重试函数(暂时只用于抖音的api)
|
||||||
|
* @param func
|
||||||
|
* @param maxRetries
|
||||||
|
* @param delay
|
||||||
|
* @returns {Promise<unknown>}
|
||||||
|
*/
|
||||||
|
function retry(func, maxRetries = 3, delay = 1000) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const attempt = (remainingTries) => {
|
||||||
|
func()
|
||||||
|
.then(resolve)
|
||||||
|
.catch(error => {
|
||||||
|
if (remainingTries === 1) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
console.log(`错误: ${error}. 重试将在 ${delay/1000} 秒...`);
|
||||||
|
setTimeout(() => attempt(remainingTries - 1), delay);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
attempt(maxRetries);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { jFeatch, autoTask, retry };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user