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 }; }