Merge pull request #116 from crunchy-labs/feature/all-languages

(Re-)add `-l all` languages
This commit is contained in:
ByteDream 2023-01-16 15:55:39 +01:00 committed by GitHub
commit cdf054ff58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 12 deletions

View file

@ -1,7 +1,7 @@
use crate::cli::log::tab_info; use crate::cli::log::tab_info;
use crate::cli::utils::{ use crate::cli::utils::{
download_segments, find_multiple_seasons_with_same_number, find_resolution, all_locale_in_locales, download_segments, find_multiple_seasons_with_same_number,
interactive_season_choosing, FFmpegPreset, find_resolution, interactive_season_choosing, FFmpegPreset,
}; };
use crate::utils::context::Context; use crate::utils::context::Context;
use crate::utils::format::Format; use crate::utils::format::Format;
@ -126,7 +126,7 @@ pub struct Archive {
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Execute for Archive { impl Execute for Archive {
fn pre_check(&self) -> Result<()> { fn pre_check(&mut self) -> Result<()> {
if !has_ffmpeg() { if !has_ffmpeg() {
bail!("FFmpeg is needed to run this command") bail!("FFmpeg is needed to run this command")
} else if PathBuf::from(&self.output) } else if PathBuf::from(&self.output)
@ -145,6 +145,9 @@ impl Execute for Archive {
warn!("Skipping 'nvidia' hardware acceleration preset since no other codec preset was specified") 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(()) Ok(())
} }
@ -352,12 +355,12 @@ async fn formats_from_series(
.into_iter() .into_iter()
.filter(|l| !season.iter().any(|s| s.metadata.audio_locales.contains(l))) .filter(|l| !season.iter().any(|s| s.metadata.audio_locales.contains(l)))
.collect::<Vec<Locale>>(); .collect::<Vec<Locale>>();
for not_present in not_present_audio { if !not_present_audio.is_empty() {
error!( error!(
"Season {} of series {} is not available with {} audio", "Season {} of series {} is not available with {} audio",
season.first().unwrap().metadata.season_number, season.first().unwrap().metadata.season_number,
series.title, series.title,
not_present not_present_audio.into_iter().map(|l| l.to_string()).collect::<Vec<String>>().join(", ")
) )
} }

View file

@ -1,7 +1,7 @@
use crate::cli::log::tab_info; use crate::cli::log::tab_info;
use crate::cli::utils::{ use crate::cli::utils::{
download_segments, find_multiple_seasons_with_same_number, find_resolution, download_segments, find_multiple_seasons_with_same_number,
interactive_season_choosing, FFmpegPreset, find_resolution, interactive_season_choosing, FFmpegPreset,
}; };
use crate::utils::context::Context; use crate::utils::context::Context;
use crate::utils::format::Format; use crate::utils::format::Format;
@ -89,7 +89,7 @@ pub struct Download {
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Execute for Download { impl Execute for Download {
fn pre_check(&self) -> Result<()> { fn pre_check(&mut self) -> Result<()> {
if !has_ffmpeg() { if !has_ffmpeg() {
bail!("FFmpeg is needed to run this command") bail!("FFmpeg is needed to run this command")
} else if Path::new(&self.output) } else if Path::new(&self.output)

View file

@ -1,7 +1,7 @@
use crate::utils::context::Context; use crate::utils::context::Context;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use crunchyroll_rs::media::{Resolution, VariantData, VariantSegment}; use crunchyroll_rs::media::{Resolution, VariantData, VariantSegment};
use crunchyroll_rs::{Media, Season}; use crunchyroll_rs::{Locale, Media, Season};
use indicatif::{ProgressBar, ProgressFinish, ProgressStyle}; use indicatif::{ProgressBar, ProgressFinish, ProgressStyle};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{debug, LevelFilter}; use log::{debug, LevelFilter};
@ -363,6 +363,20 @@ pub(crate) fn find_multiple_seasons_with_same_number(seasons: &Vec<Media<Season>
.collect() .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<Locale>) -> Vec<Locale> {
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<Media<Season>>) -> Vec<Media<Season>> { pub(crate) fn interactive_season_choosing(seasons: Vec<Media<Season>>) -> Vec<Media<Season>> {
let input_regex = let input_regex =
Regex::new(r"((?P<single>\d+)|(?P<range_from>\d+)-(?P<range_to>\d+)?)(\s|$)").unwrap(); Regex::new(r"((?P<single>\d+)|(?P<range_from>\d+)-(?P<range_to>\d+)?)(\s|$)").unwrap();

View file

@ -16,10 +16,10 @@ pub use cli::{archive::Archive, download::Download, login::Login};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
trait Execute { trait Execute {
fn pre_check(&self) -> Result<()> { fn pre_check(&mut self) -> Result<()> {
Ok(()) Ok(())
} }
async fn execute(self, ctx: Context) -> Result<()>; async fn execute(mut self, ctx: Context) -> Result<()>;
} }
#[derive(Debug, Parser)] #[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 /// 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` /// 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() { if let Err(err) = executor.pre_check() {
error!("Misconfigurations detected: {}", err); error!("Misconfigurations detected: {}", err);
std::process::exit(1) std::process::exit(1)