From bdd4d8f899447b58f7c9b0fa30818ca3e8a7a299 Mon Sep 17 00:00:00 2001 From: Valentine Briese Date: Sat, 14 Oct 2023 15:24:09 -0700 Subject: [PATCH] Replace `--single-threaded` boolean option with `--threads` optional `usize` option --- crunchy-cli-core/src/archive/command.rs | 8 ++++---- crunchy-cli-core/src/download/command.rs | 8 ++++---- crunchy-cli-core/src/utils/download.rs | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs index 529da7d..59746bc 100644 --- a/crunchy-cli-core/src/archive/command.rs +++ b/crunchy-cli-core/src/archive/command.rs @@ -98,9 +98,9 @@ pub struct Archive { #[arg(short, long, default_value_t = false)] pub(crate) yes: bool, - #[arg(help = "Download using only one thread")] - #[arg(short = 't', long, default_value_t = false)] - pub(crate) single_threaded: bool, + #[arg(help = "Override the number of threads used to download")] + #[arg(short, long)] + pub(crate) threads: Option, #[arg(help = "Crunchyroll series url(s)")] #[arg(required = true)] @@ -163,7 +163,7 @@ impl Execute for Archive { .output_format(Some("matroska".to_string())) .audio_sort(Some(self.audio.clone())) .subtitle_sort(Some(self.subtitle.clone())) - .single_threaded(self.single_threaded); + .threads(self.threads); for single_formats in single_format_collection.into_iter() { let (download_formats, mut format) = get_format(&self, &single_formats).await?; diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs index 096e5a7..04084f5 100644 --- a/crunchy-cli-core/src/download/command.rs +++ b/crunchy-cli-core/src/download/command.rs @@ -80,9 +80,9 @@ pub struct Download { #[arg(long, default_value_t = false)] pub(crate) force_hardsub: bool, - #[arg(help = "Download using only one thread")] - #[arg(short = 't', long, default_value_t = false)] - pub(crate) single_threaded: bool, + #[arg(help = "Override the number of threads used to download")] + #[arg(short, long)] + pub(crate) threads: Option, #[arg(help = "Url(s) to Crunchyroll episodes or series")] #[arg(required = true)] @@ -154,7 +154,7 @@ impl Execute for Download { None }) .ffmpeg_preset(self.ffmpeg_preset.clone().unwrap_or_default()) - .single_threaded(self.single_threaded); + .threads(self.threads); for mut single_formats in single_format_collection.into_iter() { // the vec contains always only one item diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs index 7d2d66c..2817c48 100644 --- a/crunchy-cli-core/src/utils/download.rs +++ b/crunchy-cli-core/src/utils/download.rs @@ -50,7 +50,7 @@ pub struct DownloadBuilder { audio_sort: Option>, subtitle_sort: Option>, force_hardsub: bool, - single_threaded: bool, + threads: Option, } impl DownloadBuilder { @@ -62,7 +62,7 @@ impl DownloadBuilder { audio_sort: None, subtitle_sort: None, force_hardsub: false, - single_threaded: false, + threads: None, } } @@ -75,7 +75,7 @@ impl DownloadBuilder { subtitle_sort: self.subtitle_sort, force_hardsub: self.force_hardsub, - single_threaded: self.single_threaded, + threads: self.threads, formats: vec![], } @@ -102,7 +102,7 @@ pub struct Downloader { subtitle_sort: Option>, force_hardsub: bool, - single_threaded: bool, + threads: Option, formats: Vec, } @@ -575,9 +575,9 @@ impl Downloader { None }; - // Only use 1 CPU (core?) if `single-threaded` option is enabled - let cpus = if self.single_threaded { - 1 + // If `threads` is specified, use that many CPU cores(?). + let cpus = if let Some(threads) = self.threads { + threads } else { num_cpus::get() };