🎈 pref: 优化 哔哩哔哩 专栏发送逻辑 && 优化直播切片

This commit is contained in:
zhiyu1998 2024-10-01 14:54:59 +08:00
parent 236b241fdf
commit b91b866e25

View File

@ -483,7 +483,6 @@ export class tools extends plugin {
* @param second * @param second
*/ */
async sendStreamSegment(e, stream_url, second = this.streamDuration) { async sendStreamSegment(e, stream_url, second = this.streamDuration) {
const pipelineAsync = promisify(pipeline);
const outputFilePath = `${ this.getCurDownloadPath(e) }/stream_10s.flv`; const outputFilePath = `${ this.getCurDownloadPath(e) }/stream_10s.flv`;
await checkAndRemoveFile(outputFilePath); await checkAndRemoveFile(outputFilePath);
@ -492,13 +491,14 @@ export class tools extends plugin {
logger.info("[R插件][发送直播流] 正在下载直播流..."); logger.info("[R插件][发送直播流] 正在下载直播流...");
const file = fs.createWriteStream(outputFilePath); const file = fs.createWriteStream(outputFilePath);
await pipelineAsync(response.data, file); response.data.pipe(file);
// 设置 streamDuration 秒后停止下载 // 设置 streamDuration 秒后停止下载
setTimeout(async () => { setTimeout(async () => {
logger.info(`[R插件][发送直播流] 直播下载 ${ this.streamDuration } 秒钟到,停止下载!`); logger.info(`[R插件][发送直播流] 直播下载 ${ this.streamDuration } 秒钟到,停止下载!`);
response.data.destroy(); // 销毁流 response.data.destroy(); // 销毁流
await this.sendVideoToUpload(e, outputFilePath); await this.sendVideoToUpload(e, outputFilePath);
file.close();
}, second * 1000); }, second * 1000);
} catch (error) { } catch (error) {
logger.error(`下载失败: ${ error.message }`); logger.error(`下载失败: ${ error.message }`);