diff --git a/apps/tools.js b/apps/tools.js index 64dcc9f..da6d4bc 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -120,47 +120,84 @@ export class tools extends plugin { await this.douyinRequest(douUrl).then(async res => { const douRex = /.*video\/(\d+)\/(.*?)/g; 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/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( - await function () { - return fetch(url).then(resp => resp.json()); + // 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`; + + fetch("https://ttwid.bytedance.com/ttwid/union/register/", { + "method": "POST", + "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 item = resp_json.aweme_detail; - e.reply(`识别:抖音, ${ item.desc }`); - const url_type_code = item.aweme_type; - const url_type = douyinTypeMap[url_type_code]; - if (url_type === "video") { - const url_2 = item.video.play_addr.url_list[0]; - this.downloadVideo(url_2).then(video => { - e.reply( - segment.video( - `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4` - ) - ); - }); - } else if (url_type === "image") { - // 无水印图片列表 - let 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)); - } - }); + const dyApi = 'https://www.douyin.com/aweme/v1/web/aweme/detail/?' + const params = `aweme_id=${ douId }&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333` + // xg参数 + axios.post(`http://47.115.200.238/xg/path?url=${params.replace('&','%26')}`, { + 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": "" + }, + }).then(resp => { + const param = resp.data.result[0].paramsencode + const resDyApi = `${dyApi}${param}` + axios.get(resDyApi, { + headers + }).then(async resp => { + const item = resp.data.aweme_detail; + e.reply(`识别:抖音, ${ item.desc }`); + const urlTypeCode = item.aweme_type; + const urlType = douyinTypeMap[urlTypeCode]; + if (urlType === "video") { + const url_2 = item.video.play_addr.url_list[2]; + this.downloadVideo(url_2, false, headers).then(video => { + e.reply( + segment.video( + `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4` + ) + ); + }); + } else if (urlType === "image") { + // 无水印图片列表 + let 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; } @@ -398,7 +435,7 @@ export class tools extends plugin { task.push(this.downloadImg(item.url, downloadPath)) } 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`)); }); } @@ -620,7 +657,7 @@ export class tools extends plugin { } // 工具:根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 }`; if (!fs.existsSync(groupPath)) { mkdirsSync(groupPath); @@ -634,7 +671,7 @@ export class tools extends plugin { let res; if (!isProxy) { res = await axios.get(url, { - headers: { + headers: headers || { "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", }, @@ -642,7 +679,7 @@ export class tools extends plugin { }); } else { res = await axios.get(url, { - headers: { + headers: headers || { "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", },