diff --git a/server/src/commands/download.rs b/server/src/commands/download.rs index 1315b49..479e671 100644 --- a/server/src/commands/download.rs +++ b/server/src/commands/download.rs @@ -9,16 +9,35 @@ pub async fn download_track( youtube_url: YoutubeUrl, home_absolute_path: &String, ) -> Result<(), CommandError> { - let download_file_at = format!("{}/{}.mp3", home_absolute_path, track_id); + let video_file = format!("{}/{}.mp4", home_absolute_path, track_id); let status = Command::new("yt-dlp") - .arg("--keep-video") .arg("-f") - .arg("bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4") - .arg("--extract-audio") + .arg("bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/mp4") + .arg("--recode-video") + .arg("mp4") + .arg("-o") + .arg(video_file) + .arg(&String::from(youtube_url.clone())) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .await; + + match status { + Ok(status) if status.success() => {} + Ok(_) | Err(_) => { + eprintln!("yt-dlp errored for track_id: {}", track_id); + return Err(CommandError::CommandFailed); + } + } + + let audio_file = format!("{}/{}.mp3", home_absolute_path, track_id); + let status = Command::new("yt-dlp") + .arg("-x") .arg("--audio-format") .arg("mp3") .arg("-o") - .arg(download_file_at) + .arg(audio_file) .arg(&String::from(youtube_url)) .stdout(Stdio::inherit()) .stderr(Stdio::inherit())