Fix re-download only issued when local file has more audios/subtitles & respect --no-closed-captions flag

This commit is contained in:
bytedream 2024-02-23 18:31:39 +01:00
parent 80568a7f58
commit 7c7844adc5

View file

@ -141,7 +141,7 @@ pub struct Archive {
#[arg(long_help = "Only works in combination with `--skip-existing`. \ #[arg(long_help = "Only works in combination with `--skip-existing`. \
By default, already existing files are determined by their name and the download of the corresponding episode is skipped. \ By default, already existing files are determined by their name and the download of the corresponding episode is skipped. \
With this flag you can modify this behavior. \ With this flag you can modify this behavior. \
Valid options are 'audio' and 'subtitle' (if the file already exists but the audio/subtitle differs from what should be downloaded, the episode gets downloaded and the file overwritten)")] Valid options are 'audio' and 'subtitle' (if the file already exists but the audio/subtitle are less from what should be downloaded, the episode gets downloaded and the file overwritten).")]
#[arg(long, default_values_t = SkipExistingMethod::default())] #[arg(long, default_values_t = SkipExistingMethod::default())]
#[arg(value_parser = SkipExistingMethod::parse)] #[arg(value_parser = SkipExistingMethod::parse)]
pub(crate) skip_existing_method: Vec<SkipExistingMethod>, pub(crate) skip_existing_method: Vec<SkipExistingMethod>,
@ -278,20 +278,34 @@ impl Execute for Archive {
.skip_existing_method .skip_existing_method
.contains(&SkipExistingMethod::Subtitle); .contains(&SkipExistingMethod::Subtitle);
if method_audio { let audio_differ = if method_audio {
audio_locales format
.retain(|a| !format.locales.iter().any(|(l, _)| a == l)); .locales
} .iter()
if self .any(|(a, _)| !audio_locales.contains(a))
.skip_existing_method } else {
.contains(&SkipExistingMethod::Subtitle) false
{ };
subtitle_locales let subtitle_differ = if method_subtitle {
.retain(|s| !format.locales.iter().any(|(_, l)| l.contains(s))) format
.locales
.clone()
.into_iter()
.flat_map(|(a, mut s)| {
// remove the closed caption if the flag is given to omit
// closed captions
if self.no_closed_caption && a != Locale::ja_JP {
s.retain(|l| l != &a)
} }
s
})
.any(|l| !subtitle_locales.contains(&l))
} else {
false
};
if (method_audio && !audio_locales.is_empty()) if (method_audio && audio_differ)
|| (method_subtitle && !subtitle_locales.is_empty()) || (method_subtitle && subtitle_differ)
{ {
skip = false; skip = false;
path = formatted_path.clone() path = formatted_path.clone()