blob_dl/
assembling.rs

1pub mod youtube;
2
3use crate::analyzer;
4use crate::error::BlobResult;
5
6/// Asks the user for specific download preferences (output path, download format, ...) and builds
7/// a yt-dlp command according to them
8///
9/// Returns the command along with a DownloadConfig object, which contains all the user-specified preferences
10pub(crate) fn generate_command(url: &str, download_option: &analyzer::DownloadOption) -> BlobResult<(std::process::Command, youtube::config::DownloadConfig)> {
11    // Get preferences from the user, various errors may occur
12    let unchecked_config = match download_option {
13        analyzer::DownloadOption::YtPlaylist => youtube::yt_playlist::assemble_data(url),
14
15        analyzer::DownloadOption::YtVideo(id) => youtube::yt_video::assemble_data(url, *id)
16    };
17
18    match unchecked_config {
19        Ok(safe) => {
20            // Everything went smoothly, now generate a yt-dlp command
21            let (command, local_config) = safe.build_command();
22            Ok((command, local_config))
23        }
24        // Propagate the errors
25        Err(err) => Err(err)
26    }
27}