mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
✨ feat: 添加阿b直播解析切片 [beta]
This commit is contained in:
parent
0aaacc229b
commit
3d17f93df0
@ -31,10 +31,12 @@ import {
|
|||||||
BILI_EP_INFO,
|
BILI_EP_INFO,
|
||||||
BILI_ONLINE,
|
BILI_ONLINE,
|
||||||
BILI_SSID_INFO,
|
BILI_SSID_INFO,
|
||||||
|
BILI_STREAM_FLV,
|
||||||
BILI_STREAM_INFO,
|
BILI_STREAM_INFO,
|
||||||
BILI_SUMMARY,
|
BILI_SUMMARY,
|
||||||
DY_COMMENT,
|
DY_COMMENT,
|
||||||
DY_INFO, DY_LIVE_INFO,
|
DY_INFO,
|
||||||
|
DY_LIVE_INFO,
|
||||||
DY_TOUTIAO_INFO,
|
DY_TOUTIAO_INFO,
|
||||||
GENERAL_REQ_LINK,
|
GENERAL_REQ_LINK,
|
||||||
HIBI_API_SERVICE,
|
HIBI_API_SERVICE,
|
||||||
@ -75,7 +77,7 @@ import {
|
|||||||
downloadImg,
|
downloadImg,
|
||||||
estimateReadingTime,
|
estimateReadingTime,
|
||||||
formatBiliInfo,
|
formatBiliInfo,
|
||||||
retryAxiosReq, saveJsonToFile,
|
retryAxiosReq,
|
||||||
secondsToTime,
|
secondsToTime,
|
||||||
testProxy,
|
testProxy,
|
||||||
truncateString,
|
truncateString,
|
||||||
@ -360,26 +362,7 @@ export class tools extends plugin {
|
|||||||
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的直播流
|
// 下载10s的直播流
|
||||||
const outputFilePath = `${this.getCurDownloadPath(e)}/stream_10s.flv`
|
this.sendStreamSegment(e, stream_url?.flv_pull_url?.HD1);
|
||||||
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;
|
||||||
@ -467,6 +450,36 @@ export class tools extends plugin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载直播片段
|
||||||
|
* @param e
|
||||||
|
* @param stream_url
|
||||||
|
* @param second
|
||||||
|
*/
|
||||||
|
sendStreamSegment(e, stream_url, second = 10) {
|
||||||
|
const outputFilePath = `${ this.getCurDownloadPath(e) }/stream_10s.flv`
|
||||||
|
const file = fs.createWriteStream(outputFilePath);
|
||||||
|
axios.get(stream_url, {
|
||||||
|
responseType: 'stream'
|
||||||
|
}).then(response => {
|
||||||
|
logger.info("[R插件][发送直播流] 正在下载直播流...");
|
||||||
|
// 将流数据写入文件
|
||||||
|
response.data.pipe(file);
|
||||||
|
|
||||||
|
// 设置 10 秒后停止下载
|
||||||
|
setTimeout(() => {
|
||||||
|
logger.info('[R插件][发送直播流] 直播下载10秒钟到,停止下载!');
|
||||||
|
response.data.destroy(); // 销毁流
|
||||||
|
e.reply(segment.video(outputFilePath));
|
||||||
|
file.close(); // 关闭文件流
|
||||||
|
}, second * 1000); // 10秒 = 10000毫秒
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('下载失败:', error.message);
|
||||||
|
fs.unlink(outputFilePath, () => {
|
||||||
|
}); // 下载失败时删除文件
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 DY 评论
|
* 获取 DY 评论
|
||||||
* @param e
|
* @param e
|
||||||
@ -581,9 +594,18 @@ export class tools extends plugin {
|
|||||||
const streamId = parsedUrl.pathname.match(idPattern)?.[1];
|
const streamId = parsedUrl.pathname.match(idPattern)?.[1];
|
||||||
// logger.info(streamId)
|
// logger.info(streamId)
|
||||||
// 提取相关信息
|
// 提取相关信息
|
||||||
const liveData = await this.getBiliStream(streamId);
|
const liveData = await this.getBiliStreamInfo(streamId);
|
||||||
// saveJsonToFile(liveData.data);
|
// saveJsonToFile(liveData.data);
|
||||||
const { title, user_cover, keyframe, description, tags, live_time, parent_area_name, area_name } = liveData.data.data;
|
const {
|
||||||
|
title,
|
||||||
|
user_cover,
|
||||||
|
keyframe,
|
||||||
|
description,
|
||||||
|
tags,
|
||||||
|
live_time,
|
||||||
|
parent_area_name,
|
||||||
|
area_name
|
||||||
|
} = liveData.data.data;
|
||||||
e.reply([
|
e.reply([
|
||||||
segment.image(user_cover),
|
segment.image(user_cover),
|
||||||
segment.image(keyframe),
|
segment.image(keyframe),
|
||||||
@ -594,6 +616,9 @@ export class tools extends plugin {
|
|||||||
`${ live_time ? `⏰ 直播时间:${ live_time }` : '' }`,
|
`${ live_time ? `⏰ 直播时间:${ live_time }` : '' }`,
|
||||||
].filter(item => item.trim() !== "").join("\n")
|
].filter(item => item.trim() !== "").join("\n")
|
||||||
]);
|
]);
|
||||||
|
const streamData = await this.getBiliStream(streamId);
|
||||||
|
const { url: streamUrl } = streamData.data.data.durl[0];
|
||||||
|
await this.sendStreamSegment(e, streamUrl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 处理专栏
|
// 处理专栏
|
||||||
@ -910,7 +935,7 @@ export class tools extends plugin {
|
|||||||
* @param liveId
|
* @param liveId
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
async getBiliStream(liveId) {
|
async getBiliStreamInfo(liveId) {
|
||||||
return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, {
|
return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, {
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': COMMON_USER_AGENT,
|
'User-Agent': COMMON_USER_AGENT,
|
||||||
@ -918,6 +943,19 @@ export class tools extends plugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取直播流
|
||||||
|
* @param liveId
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
async getBiliStream(liveId) {
|
||||||
|
return axios.get(`${ BILI_STREAM_FLV }?cid=${ liveId }`, {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': COMMON_USER_AGENT,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use newFunction instead.
|
* @deprecated Use newFunction instead.
|
||||||
*/
|
*/
|
||||||
|
@ -61,6 +61,13 @@ export const BILI_SCAN_CODE_DETECT = "https://passport.bilibili.com/x/passport-l
|
|||||||
*/
|
*/
|
||||||
export const BILI_STREAM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info"
|
export const BILI_STREAM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据真实直播间号获取直播视频流
|
||||||
|
* https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/live/live_stream.md
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
export const BILI_STREAM_FLV = "https://api.live.bilibili.com/room/v1/Room/playUrl"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取视频在线人数_web端
|
* 获取视频在线人数_web端
|
||||||
* https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/online.md
|
* https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/online.md
|
||||||
|
Loading…
x
Reference in New Issue
Block a user