🐞 fix:修复部分没有音频的b视频无法发出问题(感谢 @辰 提供样本)

This commit is contained in:
zhiyu1998 2024-10-04 15:55:18 +08:00
parent 16fbdd8ab7
commit 9ad9436a88
2 changed files with 21 additions and 4 deletions

View File

@ -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`);

View File

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