From 8e03019b44c7ad79366849dd825ab03963f84723 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Thu, 24 Nov 2022 18:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=8A=A0tiktok?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/tools.js b/apps/tools.js index e5acfba..1513b8f 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -23,6 +23,10 @@ export class tools extends plugin { reg: "(.*)(v.douyin.com)", fnc: "douyin", }, + { + reg: "(.*)(www.tiktok.com)", + fnc: "tiktok", + }, ], }); this.path = "./data/rcmp4/"; @@ -50,12 +54,12 @@ export class tools extends plugin { async douyin(e) { const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const douUrl = urlRex.exec(e.msg.trim())[0]; + e.reply("识别:抖音, 解析中..."); await this.douyinRequest(douUrl).then((res) => { const douRex = /.*video\/(\d+)\/(.*?)/g; const douId = douRex.exec(res)[1]; const url = `https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=${douId}`; - e.reply("解析中..."); return fetch(url) .then((resp) => resp.json()) .then((json) => json.item_list[0]) @@ -67,6 +71,21 @@ export class tools extends plugin { return true; } + // tiktok解析 + async tiktok(e) { + const urlRex = /(http:|https:)\/\/www.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g; + const url = urlRex.exec(e.msg.trim())[0] + + const tiktokApi = `https://api.douyin.wtf/api?url=${url}&minimal=true` + e.reply("识别:tiktok, 解析中..."); + fetch(tiktokApi) + .then(resp => resp.json()) + .then(async json => { + await e.reply(await segment.video(await this.downloadVideo(json.wm_video_url.replace("https","http")))) + }) + return true + } + // 请求参数 async douyinRequest(url) { const params = { @@ -129,4 +148,18 @@ export class tools extends plugin { } } } + + // 递归创建目录 异步方法 + mkdirs(dirname, callback) { + fs.exists(dirname, function (exists) { + if (exists) { + callback(); + } else { + // console.log(path.dirname(dirname)); + this.mkdirs(path.dirname(dirname), function () { + fs.mkdir(dirname, callback); + }); + } + }); + } }