fix: 确保无论视频下载结果如何,都在最终删除临时文件 (#159)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2024-07-28 15:34:00 +08:00
committed by GitHub
parent 8a4a95e343
commit 6187827e1b
2 changed files with 8 additions and 5 deletions

View File

@@ -51,8 +51,6 @@ impl Downloader {
_ => Err(anyhow!("ffmpeg error")),
};
}
let _ = fs::remove_file(video_path).await;
let _ = fs::remove_file(audio_path).await;
Ok(())
}
}

View File

@@ -485,9 +485,14 @@ pub async fn fetch_page_video(
page_path.with_extension("tmp_video"),
page_path.with_extension("tmp_audio"),
);
downloader.fetch(video_stream.url(), &tmp_video_path).await?;
downloader.fetch(audio_stream.url(), &tmp_audio_path).await?;
downloader.merge(&tmp_video_path, &tmp_audio_path, &page_path).await?;
let res = {
downloader.fetch(video_stream.url(), &tmp_video_path).await?;
downloader.fetch(audio_stream.url(), &tmp_audio_path).await?;
downloader.merge(&tmp_video_path, &tmp_audio_path, &page_path).await
};
let _ = fs::remove_file(tmp_video_path).await;
let _ = fs::remove_file(tmp_audio_path).await;
res?;
}
}
Ok(())