feat: 添加dy直播解析 [beta]

This commit is contained in:
zhiyu1998 2024-09-30 14:49:41 +08:00
parent c5b6b4a21a
commit 0aaacc229b

View File

@ -356,9 +356,30 @@ export class tools extends plugin {
// 直播数据逻辑 // 直播数据逻辑
if (douUrl.includes("live")) { if (douUrl.includes("live")) {
const item = await data.data.data?.[0]; const item = await data.data.data?.[0];
const { title, cover, user_count_str } = item; const { title, cover, user_count_str, stream_url } = item;
const dySendContent = `${this.identifyPrefix}识别:抖音直播,${title}` const dySendContent = `${this.identifyPrefix}识别:抖音直播,${title}`
e.reply([segment.image(cover?.url_list?.[0]), dySendContent, `\n🏄‍♂️在线人数:${user_count_str}人正在观看`]); e.reply([segment.image(cover?.url_list?.[0]), dySendContent, `\n🏄‍♂️在线人数:${user_count_str}人正在观看`]);
// 下载10s的直播流
const outputFilePath = `${this.getCurDownloadPath(e)}/stream_10s.flv`
const file = fs.createWriteStream(outputFilePath);
axios.get(stream_url?.flv_pull_url?.FULL_HD1, {
responseType: 'stream'
}).then(response => {
logger.info("正在下载直播流...");
// 将流数据写入文件
response.data.pipe(file);
// 设置 10 秒后停止下载
setTimeout(() => {
logger.info('直播下载10秒钟到停止下载。');
response.data.destroy(); // 销毁流
e.reply(segment.video(outputFilePath));
file.close(); // 关闭文件流
}, 10000); // 10秒 = 10000毫秒
}).catch(error => {
console.error('下载失败:', error.message);
fs.unlink(outputFilePath, () => {}); // 下载失败时删除文件
});
return; return;
} }
const item = await data.aweme_detail; const item = await data.aweme_detail;