Skip to content

Commit

Permalink
feat: separate audio video downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev committed Sep 29, 2024
1 parent d3dec5a commit 5eaecb1
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions server/src/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 5eaecb1

Please sign in to comment.