🐞 fix: 修复 TikTok 解析问题

This commit is contained in:
zhiyu1998 2024-07-12 13:00:01 +08:00
parent 10c4c58bb8
commit 9e813a2711
2 changed files with 56 additions and 45 deletions

View File

@ -79,6 +79,29 @@ chmod a+rx ~/.local/bin/yt-dlp
sudo pacman -Syu yt-dlp
```
`Tiktok解析`需要将`yt-dlp`升级到`最新版本`如果不会可以按照下面的教程LinuxWindows换个文件应该就可以
```shell
# 1. 去官方下载最新版本https://github.com/yt-dlp/yt-dlp/releases
# 2. 把yt-dlp放在Linux某个位置比如/home/YtDlpHome/yt-dlp
# 3. 删除之前的yt-dlp删除之前可以看看是不是最新版本
# 查看最新版本
yt-dlp --version
# 如果你是 apt 安装需要卸载
apt remove yt-dlp
# 4. 将/home/YtDlpHome/yt-dlp添加到环境变量下面二选一
vim ~/.bashrc # 如果你使用 bash
vim ~/.zshrc # 如果你使用 zsh
# 5. 添加到最后一行
export PATH="/home/YtDlpHome:$PATH"
# 6. 刷新环境变量即可
source ~/.bashrc # 如果你使用 bash
source ~/.zshrc # 如果你使用 zsh
```
`AM解析`需要使用两个依赖`freyr``atomicparsley`现在只以Debian系统为例
```shell

View File

@ -343,54 +343,42 @@ export class tools extends plugin {
}
// 处理链接
let url = await processTikTokUrl(e.msg.trim(), isOversea);
// 处理ID
let tiktokVideoId = await getIdVideo(url);
tiktokVideoId = tiktokVideoId.replace(/\//g, "");
const config = {
headers: {
"User-Agent":
"Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Mobile Safari/537.36",
},
// redirect: "follow",
follow: 10,
timeout: 10000,
}
// 如果不是海外,则使用代理
if (!isOversea) {
config.httpsAgent = tunnel.httpsOverHttp({
proxy: new HttpProxyAgent(this.myProxy),
});
}
const params = new URLSearchParams({
"iid": "7318518857994389254",
"device_id": "7318517321748022790",
"channel": "googleplay",
"app_name": "musical_ly",
"version_code": "300904",
"device_platform": "android",
"device_type": "ASUS_Z01QD",
"os_version": "9",
"aweme_id": tiktokVideoId
})
// console.log(`${TIKTOK_INFO}?${params.toString()}`)
await fetch(`${ TIKTOK_INFO }?${ params.toString() }`, config)
.then(async resp => {
const respJson = await resp.json();
const data = respJson.aweme_list[0];
e.reply(`识别tiktok, ${ data.desc }`);
this.downloadVideo(data.video.play_addr.url_list[0], !isOversea).then(video => {
e.reply(
segment.video(
`${ this.getCurDownloadPath(e) }/temp.mp4`,
),
);
});
});
// 去除多余参数
const parsedUrl = new URL(url);
parsedUrl.search = '';
const cleanedTiktokUrl = parsedUrl.toString();
// 下载逻辑
const path = this.getCurDownloadPath(e);
const title = execSync(`yt-dlp --get-title ${ cleanedTiktokUrl } ${ isOversea ? "" : `--proxy ${ this.myProxy }` }`)
e.reply(`识别TikTok视频下载中请耐心等待 \n${ title }`);
await this.tiktokHelper(path, cleanedTiktokUrl, isOversea);
await this.sendVideoToUpload(e, `${ path }/temp.mp4`);
return true;
}
/**
* yt-dlp for tiktok 工具
* @returns {Promise<void>}
* @param path 下载路径
* @param url 下载链接
* @param isOversea 是否是海外用户
*/
async tiktokHelper(path, url, isOversea) {
return new Promise((resolve, reject) => {
const command = `yt-dlp ${ isOversea ? "" : `--proxy ${ this.myProxy }` } -P ${ path } -o "temp.%(ext)s" ${ url }`;
exec(command, (error, stdout) => {
if (error) {
console.error(`Error executing command: ${ error }`);
reject(error);
} else {
console.log(`Command output: ${ stdout }`);
resolve(stdout);
}
});
});
}
async biliScan(e) {
e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', { recallMsg: 180 });
// 图片发送钩子