Skip to content

Commit

Permalink
chore: add video download test
Browse files Browse the repository at this point in the history
  • Loading branch information
Okabe-Rintarou-0 committed Oct 2, 2024
1 parent 3768dfd commit 05c112a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion src-tauri/src/client/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ impl Client {
total: size,
};
progress_handler(payload.clone());
if size == 0 {
tracing::warn!(
"try to download video as {}, but size is 0, can't download",
save_path
);
return Err(AppError::VideoDownloadError(save_path.to_owned()));
}

let progress_handler = Arc::new(Mutex::new(progress_handler));
let payload = Arc::new(Mutex::new(payload));
Expand All @@ -336,9 +343,10 @@ impl Client {
let chunk_size = size / nproc as u64;
let mut tasks = JoinSet::new();
for i in 0..nproc {
tracing::info!("{}, {}, {}", i, chunk_size, size);
let begin = i as u64 * chunk_size;
let end = if i == nproc - 1 {
size
size - 1
} else {
(i + 1) as u64 * chunk_size - 1
};
Expand Down Expand Up @@ -442,6 +450,8 @@ impl Client {

#[cfg(test)]
mod tests {
use std::fs;

use super::*;

#[tokio::test]
Expand All @@ -454,6 +464,33 @@ mod tests {
Ok(())
}

#[tokio::test]
async fn test_download_video() -> Result<()> {
let cli = Arc::new(Client::new());
let video_url = "https://www.w3schools.com/html/mov_bbb.mp4";
let save_path = "test.mp4";
let video_info = VideoPlayInfo {
rtmp_url_hdv: video_url.to_owned(),
..Default::default()
};
let cli_cloned = cli.clone();
cli_cloned
.download_video(&video_info, save_path, |_| {})
.await?;

// download original video
let original = cli
.get_request(video_url, None::<&str>)
.await?
.bytes()
.await?
.to_vec();

let downloaded = fs::read(save_path)?;
assert_eq!(original, downloaded);
Ok(())
}

#[test]
fn test_get_oauth_signature() -> Result<()> {
let cli = Client::new();
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn read_log_content() -> Result<String> {
}

#[tauri::command]
fn is_ffmpeg_installed() -> bool {
async fn is_ffmpeg_installed() -> bool {
App::is_ffmpeg_installed()
}

Expand Down

0 comments on commit 05c112a

Please sign in to comment.