diff --git a/crunchy-cli-core/src/cli/archive.rs b/crunchy-cli-core/src/cli/archive.rs index 768c629..d7e6bf9 100644 --- a/crunchy-cli-core/src/cli/archive.rs +++ b/crunchy-cli-core/src/cli/archive.rs @@ -1,7 +1,7 @@ use crate::cli::log::tab_info; use crate::cli::utils::{ - download_segments, find_multiple_seasons_with_same_number, find_resolution, - interactive_season_choosing, FFmpegPreset, + all_locale_in_locales, download_segments, find_multiple_seasons_with_same_number, + find_resolution, interactive_season_choosing, FFmpegPreset, }; use crate::utils::context::Context; use crate::utils::format::Format; @@ -132,7 +132,7 @@ pub struct Archive { #[async_trait::async_trait(?Send)] impl Execute for Archive { - fn pre_check(&self) -> Result<()> { + fn pre_check(&mut self) -> Result<()> { if !has_ffmpeg() { bail!("FFmpeg is needed to run this command") } else if PathBuf::from(&self.output) @@ -151,6 +151,9 @@ impl Execute for Archive { warn!("Skipping 'nvidia' hardware acceleration preset since no other codec preset was specified") } + self.locale = all_locale_in_locales(self.locale.clone()); + self.subtitle = all_locale_in_locales(self.subtitle.clone()); + Ok(()) } diff --git a/crunchy-cli-core/src/cli/download.rs b/crunchy-cli-core/src/cli/download.rs index 7a49a4c..2f83ffd 100644 --- a/crunchy-cli-core/src/cli/download.rs +++ b/crunchy-cli-core/src/cli/download.rs @@ -1,7 +1,7 @@ use crate::cli::log::tab_info; use crate::cli::utils::{ - download_segments, find_multiple_seasons_with_same_number, find_resolution, - interactive_season_choosing, FFmpegPreset, + download_segments, find_multiple_seasons_with_same_number, + find_resolution, interactive_season_choosing, FFmpegPreset, }; use crate::utils::context::Context; use crate::utils::format::Format; @@ -84,7 +84,7 @@ pub struct Download { #[async_trait::async_trait(?Send)] impl Execute for Download { - fn pre_check(&self) -> Result<()> { + fn pre_check(&mut self) -> Result<()> { if has_ffmpeg() { debug!("FFmpeg detected") } else if PathBuf::from(&self.output) diff --git a/crunchy-cli-core/src/cli/utils.rs b/crunchy-cli-core/src/cli/utils.rs index da56f5e..84850f8 100644 --- a/crunchy-cli-core/src/cli/utils.rs +++ b/crunchy-cli-core/src/cli/utils.rs @@ -1,7 +1,7 @@ use crate::utils::context::Context; use anyhow::{bail, Result}; use crunchyroll_rs::media::{Resolution, VariantData, VariantSegment}; -use crunchyroll_rs::{Media, Season}; +use crunchyroll_rs::{Locale, Media, Season}; use indicatif::{ProgressBar, ProgressFinish, ProgressStyle}; use lazy_static::lazy_static; use log::{debug, LevelFilter}; @@ -369,6 +369,20 @@ pub(crate) fn find_multiple_seasons_with_same_number(seasons: &Vec .collect() } +/// Check if [`Locale::Custom("all")`] is in the provided locale list and return [`Locale::all`] if +/// so. If not, just return the provided locale list. +pub(crate) fn all_locale_in_locales(locales: Vec) -> Vec { + if locales + .iter() + .find(|l| l.to_string().to_lowercase().trim() == "all") + .is_some() + { + Locale::all() + } else { + locales + } +} + pub(crate) fn interactive_season_choosing(seasons: Vec>) -> Vec> { let input_regex = Regex::new(r"((?P\d+)|(?P\d+)-(?P\d+)?)(\s|$)").unwrap(); diff --git a/crunchy-cli-core/src/lib.rs b/crunchy-cli-core/src/lib.rs index 6cef42e..ab3f33c 100644 --- a/crunchy-cli-core/src/lib.rs +++ b/crunchy-cli-core/src/lib.rs @@ -16,10 +16,10 @@ pub use cli::{archive::Archive, download::Download, login::Login}; #[async_trait::async_trait(?Send)] trait Execute { - fn pre_check(&self) -> Result<()> { + fn pre_check(&mut self) -> Result<()> { Ok(()) } - async fn execute(self, ctx: Context) -> Result<()>; + async fn execute(mut self, ctx: Context) -> Result<()>; } #[derive(Debug, Parser)] @@ -171,7 +171,7 @@ pub async fn cli_entrypoint() { /// Cannot be done in the main function. I wanted to return `dyn` [`Execute`] from the match but had to /// box it which then conflicts with [`Execute::execute`] which consumes `self` -async fn execute_executor(executor: impl Execute, ctx: Context) { +async fn execute_executor(mut executor: impl Execute, ctx: Context) { if let Err(err) = executor.pre_check() { error!("Misconfigurations detected: {}", err); std::process::exit(1)