mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
* use a 'close enough' method to audio merge * change default, rename flag, and use more gooder words
This commit is contained in:
parent
7cf7a8e71c
commit
a4abb14ae3
1 changed files with 44 additions and 18 deletions
|
|
@ -16,7 +16,7 @@ use chrono::Duration;
|
||||||
use crunchyroll_rs::media::{Resolution, Subtitle};
|
use crunchyroll_rs::media::{Resolution, Subtitle};
|
||||||
use crunchyroll_rs::Locale;
|
use crunchyroll_rs::Locale;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use std::collections::HashMap;
|
use std::ops::Sub;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Clone, Debug, clap::Parser)]
|
#[derive(Clone, Debug, clap::Parser)]
|
||||||
|
|
@ -86,6 +86,12 @@ pub struct Archive {
|
||||||
#[arg(value_parser = MergeBehavior::parse)]
|
#[arg(value_parser = MergeBehavior::parse)]
|
||||||
pub(crate) merge: MergeBehavior,
|
pub(crate) merge: MergeBehavior,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
help = "If the merge behavior is 'auto', only download multiple video tracks if their length difference is higher than the given milliseconds"
|
||||||
|
)]
|
||||||
|
#[arg(long, default_value_t = 200)]
|
||||||
|
pub(crate) merge_auto_tolerance: u32,
|
||||||
|
|
||||||
#[arg(help = format!("Presets for converting the video to a specific coding format. \
|
#[arg(help = format!("Presets for converting the video to a specific coding format. \
|
||||||
Available presets: \n {}", FFmpegPreset::available_matches_human_readable().join("\n ")))]
|
Available presets: \n {}", FFmpegPreset::available_matches_human_readable().join("\n ")))]
|
||||||
#[arg(long_help = format!("Presets for converting the video to a specific coding format. \
|
#[arg(long_help = format!("Presets for converting the video to a specific coding format. \
|
||||||
|
|
@ -356,26 +362,46 @@ async fn get_format(
|
||||||
.collect(),
|
.collect(),
|
||||||
}),
|
}),
|
||||||
MergeBehavior::Auto => {
|
MergeBehavior::Auto => {
|
||||||
let mut d_formats: HashMap<Duration, DownloadFormat> = HashMap::new();
|
let mut d_formats: Vec<(Duration, DownloadFormat)> = vec![];
|
||||||
|
|
||||||
for (single_format, video, audio, subtitles) in format_pairs {
|
for (single_format, video, audio, subtitles) in format_pairs {
|
||||||
if let Some(d_format) = d_formats.get_mut(&single_format.duration) {
|
let closest_format = d_formats.iter_mut().min_by(|(x, _), (y, _)| {
|
||||||
d_format.audios.push((audio, single_format.audio.clone()));
|
x.sub(single_format.duration)
|
||||||
d_format.subtitles.extend(subtitles)
|
.abs()
|
||||||
} else {
|
.cmp(&y.sub(single_format.duration).abs())
|
||||||
d_formats.insert(
|
});
|
||||||
|
|
||||||
|
match closest_format {
|
||||||
|
Some(closest_format)
|
||||||
|
if closest_format
|
||||||
|
.0
|
||||||
|
.sub(single_format.duration)
|
||||||
|
.abs()
|
||||||
|
.num_milliseconds()
|
||||||
|
< archive.merge_auto_tolerance.into() =>
|
||||||
|
{
|
||||||
|
// If less than `audio_error` apart, use same audio.
|
||||||
|
closest_format
|
||||||
|
.1
|
||||||
|
.audios
|
||||||
|
.push((audio, single_format.audio.clone()));
|
||||||
|
closest_format.1.subtitles.extend(subtitles);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
d_formats.push((
|
||||||
single_format.duration,
|
single_format.duration,
|
||||||
DownloadFormat {
|
DownloadFormat {
|
||||||
video: (video, single_format.audio.clone()),
|
video: (video, single_format.audio.clone()),
|
||||||
audios: vec![(audio, single_format.audio.clone())],
|
audios: vec![(audio, single_format.audio.clone())],
|
||||||
subtitles,
|
subtitles,
|
||||||
},
|
},
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for d_format in d_formats.into_values() {
|
for (_, d_format) in d_formats.into_iter() {
|
||||||
download_formats.push(d_format)
|
download_formats.push(d_format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue