From 9ad9436a887743ddbf4d4e7c33b24c02a36f8753 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Fri, 4 Oct 2024 15:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=B2=A1=E6=9C=89=E9=9F=B3=E9=A2=91=E7=9A=84?= =?UTF-8?q?b=E8=A7=86=E9=A2=91=E6=97=A0=E6=B3=95=E5=8F=91=E5=87=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=88=E6=84=9F=E8=B0=A2=20@=E8=BE=B0=20?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=A0=B7=E6=9C=AC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 15 +++++++++++++-- utils/bilibili.js | 10 ++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 61f7e96..5dcdf86 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -483,7 +483,7 @@ export class tools extends plugin { * @param second */ async sendStreamSegment(e, stream_url, second = this.streamDuration) { - let outputFilePath = `${ this.getCurDownloadPath(e) }/stream_${second}s.flv`; + let outputFilePath = `${ this.getCurDownloadPath(e) }/stream_${ second }s.flv`; // 删除临时文件 if (this.streamCompatibility) { await checkAndRemoveFile(outputFilePath.replace("flv", "mp4")); @@ -899,7 +899,18 @@ export class tools extends plugin { // 获取下载链接 const data = await getDownloadUrl(url, this.biliSessData); - await this.downBili(tempPath, data.videoUrl, data.audioUrl); + if (data.audioUrl != null) { + await this.downBili(tempPath, data.videoUrl, data.audioUrl); + } else { + // 处理无音频的情况 + await downloadBFile(data.videoUrl, `${ tempPath }.mp4`, _.throttle( + value => + logger.mark("视频下载进度", { + data: value, + }), + 1000, + )); + } // 上传视频 return this.sendVideoToUpload(e, `${ tempPath }.mp4`); diff --git a/utils/bilibili.js b/utils/bilibili.js index 4c6da22..fa9b10d 100644 --- a/utils/bilibili.js +++ b/utils/bilibili.js @@ -14,6 +14,7 @@ import { BILI_SCAN_CODE_GENERATE, BILI_VIDEO_INFO } from "../constants/tools.js"; +import { saveJsonToFile } from "./common.js"; import { mkdirIfNotExists } from "./file.js"; export const BILI_HEADER = { @@ -210,11 +211,16 @@ export async function getDownloadUrl(url, SESSDATA) { const { video, audio } = dash; const videoData = video?.[0]; const audioData = audio?.[0]; + // saveJsonToFile(dash); // 提取信息 const { backupUrl: videoBackupUrl, baseUrl: videoBaseUrl } = videoData; const videoUrl = selectAndAvoidMCdnUrl(videoBaseUrl, videoBackupUrl); - const { backupUrl: audioBackupUrl,baseUrl: audioBaseUrl } = audioData; - const audioUrl = selectAndAvoidMCdnUrl(audioBaseUrl, audioBackupUrl); + // 有部分视频可能存在没有音频,例如:https://www.bilibili.com/video/BV1CxvseRE8n/?p=1 + let audioUrl = null; + if (audioData != null || audioData !== undefined) { + const { backupUrl: audioBackupUrl, baseUrl: audioBaseUrl } = audioData; + audioUrl = selectAndAvoidMCdnUrl(audioBaseUrl, audioBackupUrl); + } return { videoUrl, audioUrl }; }