🐞 fix: 修复dy无法解析问题

This commit is contained in:
zhiyu1998 2023-03-02 11:16:42 +08:00
parent 901435cc35
commit 35654ec0bd

View File

@ -120,47 +120,84 @@ export class tools extends plugin {
await this.douyinRequest(douUrl).then(async res => { await this.douyinRequest(douUrl).then(async res => {
const douRex = /.*video\/(\d+)\/(.*?)/g; const douRex = /.*video\/(\d+)\/(.*?)/g;
const douId = douRex.exec(res)[1]; const douId = douRex.exec(res)[1];
// 且行且珍惜下面是已经过期的两个抖音api获取难度越来越大
// 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`;
// 默认重试3次每次间隔1s (防止SyntaxError: Unexpected token b in JSON at position 0)
retry( fetch("https://ttwid.bytedance.com/ttwid/union/register/", {
await function () { "method": "POST",
return fetch(url).then(resp => resp.json()); "mode": "cors",
"credentials": 'include',
body: JSON.stringify({
"region": "cn",
"aid": 1768,
"needFid": false,
"service": "www.ixigua.com",
"migrate_info": {
"ticket": "",
"source": "node"
},
"cbUrlProtocol": "https",
"union": true
})
}).then(resp => {
const ttwid = resp.headers.get('set-cookie');
const odin_tt = 'a09d8eb0d95b7b9adb4b6fc6591918bfb996096967a7aa4305bd81b5150a8199d2e29ed21883cdd7709c5beaa2be3baa';
const headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'referer':'https://www.douyin.com/',
'Cookie': `ttwid=${ttwid};${odin_tt}`
} }
).then(async resp_json => { const dyApi = 'https://www.douyin.com/aweme/v1/web/aweme/detail/?'
const item = resp_json.aweme_detail; const params = `aweme_id=${ douId }&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333`
e.reply(`识别:抖音, ${ item.desc }`); // xg参数
const url_type_code = item.aweme_type; axios.post(`http://47.115.200.238/xg/path?url=${params.replace('&','%26')}`, {
const url_type = douyinTypeMap[url_type_code]; headers: {
if (url_type === "video") { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
const url_2 = item.video.play_addr.url_list[0]; "referer": "https://www.douyin.com/",
this.downloadVideo(url_2).then(video => { "cookie": ""
e.reply( },
segment.video( }).then(resp => {
`${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4` const param = resp.data.result[0].paramsencode
) const resDyApi = `${dyApi}${param}`
); axios.get(resDyApi, {
}); headers
} else if (url_type === "image") { }).then(async resp => {
// 无水印图片列表 const item = resp.data.aweme_detail;
let no_watermark_image_list = []; e.reply(`识别:抖音, ${ item.desc }`);
// 有水印图片列表 const urlTypeCode = item.aweme_type;
// let watermark_image_list = []; const urlType = douyinTypeMap[urlTypeCode];
for (let i of item.images) { if (urlType === "video") {
// 无水印图片列表 const url_2 = item.video.play_addr.url_list[2];
no_watermark_image_list.push({ this.downloadVideo(url_2, false, headers).then(video => {
message: segment.image(i.url_list[0]), e.reply(
nickname: this.e.sender.card || this.e.user_id, segment.video(
user_id: this.e.user_id, `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4`
}); )
// 有水印图片列表 );
// watermark_image_list.push(i.download_url_list[0]); });
// e.reply(segment.image(i.url_list[0])); } else if (urlType === "image") {
} // 无水印图片列表
// console.log(no_watermark_image_list) let no_watermark_image_list = [];
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list)); // 有水印图片列表
} // let watermark_image_list = [];
}); for (let i of item.images) {
// 无水印图片列表
no_watermark_image_list.push({
message: segment.image(i.url_list[0]),
nickname: this.e.sender.card || this.e.user_id,
user_id: this.e.user_id,
});
// 有水印图片列表
// watermark_image_list.push(i.download_url_list[0]);
// e.reply(segment.image(i.url_list[0]));
}
// console.log(no_watermark_image_list)
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list));
}
})
})
})
}); });
return true; return true;
} }
@ -398,7 +435,7 @@ export class tools extends plugin {
task.push(this.downloadImg(item.url, downloadPath)) task.push(this.downloadImg(item.url, downloadPath))
} else if (item.type === "video") { } else if (item.type === "video") {
// 视频 // 视频
this.downloadVideo(resp.includes.media[0].variants[0].url, true).then(_ => { await this.downloadVideo(resp.includes.media[0].variants[0].url, true).then(_ => {
e.reply(segment.video(`${ downloadPath }/temp.mp4`)); e.reply(segment.video(`${ downloadPath }/temp.mp4`));
}); });
} }
@ -620,7 +657,7 @@ export class tools extends plugin {
} }
// 工具根URL据下载视频 / 音频 // 工具根URL据下载视频 / 音频
async downloadVideo (url, isProxy = false) { async downloadVideo (url, isProxy = false, headers = null) {
const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`; const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`;
if (!fs.existsSync(groupPath)) { if (!fs.existsSync(groupPath)) {
mkdirsSync(groupPath); mkdirsSync(groupPath);
@ -634,7 +671,7 @@ export class tools extends plugin {
let res; let res;
if (!isProxy) { if (!isProxy) {
res = await axios.get(url, { res = await axios.get(url, {
headers: { headers: headers || {
"User-Agent": "User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },
@ -642,7 +679,7 @@ export class tools extends plugin {
}); });
} else { } else {
res = await axios.get(url, { res = await axios.get(url, {
headers: { headers: headers || {
"User-Agent": "User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
}, },