mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
add minimum subtitle size
This commit is contained in:
parent
7cf7a8e71c
commit
a7bef039fe
3 changed files with 29 additions and 5 deletions
|
|
@ -114,6 +114,12 @@ pub struct Archive {
|
|||
#[arg(long)]
|
||||
pub(crate) include_fonts: bool,
|
||||
|
||||
#[arg(
|
||||
help = "If a subtitle byte size is less than this amount, it is not included in the downloaded file."
|
||||
)]
|
||||
#[arg(long, default_value_t = 0)]
|
||||
pub(crate) meaningful_subtitle_size: u64,
|
||||
|
||||
#[arg(help = "Skip files which are already existing")]
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub(crate) skip_existing: bool,
|
||||
|
|
@ -213,6 +219,7 @@ impl Execute for Archive {
|
|||
.output_format(Some("matroska".to_string()))
|
||||
.audio_sort(Some(self.audio.clone()))
|
||||
.subtitle_sort(Some(self.subtitle.clone()))
|
||||
.meaningful_subtitle_min_size(self.meaningful_subtitle_size)
|
||||
.threads(self.threads);
|
||||
|
||||
for single_formats in single_format_collection.into_iter() {
|
||||
|
|
|
|||
|
|
@ -104,6 +104,12 @@ pub struct Download {
|
|||
#[arg(long, default_value_t = false)]
|
||||
pub(crate) force_hardsub: bool,
|
||||
|
||||
#[arg(
|
||||
help = "If a subtitle byte size is less than this amount, it is not included in the downloaded file."
|
||||
)]
|
||||
#[arg(long, default_value_t = 0)]
|
||||
pub(crate) meaningful_subtitle_size: u64,
|
||||
|
||||
#[arg(help = "The number of threads used to download")]
|
||||
#[arg(short, long, default_value_t = num_cpus::get())]
|
||||
pub(crate) threads: usize,
|
||||
|
|
@ -220,6 +226,7 @@ impl Execute for Download {
|
|||
DownloadBuilder::new(ctx.client.clone(), ctx.rate_limiter.clone())
|
||||
.default_subtitle(self.subtitle.clone())
|
||||
.force_hardsub(self.force_hardsub)
|
||||
.meaningful_subtitle_min_size(self.meaningful_subtitle_size)
|
||||
.output_format(if is_special_file(&self.output) || self.output == "-" {
|
||||
Some("mpegts".to_string())
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use std::borrow::Borrow;
|
|||
use std::cmp::Ordering;
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::str::FromStr;
|
||||
|
|
@ -56,6 +57,7 @@ pub struct DownloadBuilder {
|
|||
output_format: Option<String>,
|
||||
audio_sort: Option<Vec<Locale>>,
|
||||
subtitle_sort: Option<Vec<Locale>>,
|
||||
meaningful_subtitle_min_size: u64,
|
||||
force_hardsub: bool,
|
||||
download_fonts: bool,
|
||||
threads: usize,
|
||||
|
|
@ -72,6 +74,7 @@ impl DownloadBuilder {
|
|||
output_format: None,
|
||||
audio_sort: None,
|
||||
subtitle_sort: None,
|
||||
meaningful_subtitle_min_size: 0,
|
||||
force_hardsub: false,
|
||||
download_fonts: false,
|
||||
threads: num_cpus::get(),
|
||||
|
|
@ -88,6 +91,7 @@ impl DownloadBuilder {
|
|||
output_format: self.output_format,
|
||||
audio_sort: self.audio_sort,
|
||||
subtitle_sort: self.subtitle_sort,
|
||||
meaningful_subtitle_min_size: self.meaningful_subtitle_min_size,
|
||||
|
||||
force_hardsub: self.force_hardsub,
|
||||
download_fonts: self.download_fonts,
|
||||
|
|
@ -121,6 +125,7 @@ pub struct Downloader {
|
|||
output_format: Option<String>,
|
||||
audio_sort: Option<Vec<Locale>>,
|
||||
subtitle_sort: Option<Vec<Locale>>,
|
||||
meaningful_subtitle_min_size: u64,
|
||||
|
||||
force_hardsub: bool,
|
||||
download_fonts: bool,
|
||||
|
|
@ -298,11 +303,16 @@ impl Downloader {
|
|||
.then_some(format!(" for video {}", i))
|
||||
.unwrap_or_default()
|
||||
);
|
||||
subtitles.push(FFmpegMeta {
|
||||
path: subtitle_path,
|
||||
language: subtitle.locale.clone(),
|
||||
title: subtitle_title,
|
||||
})
|
||||
|
||||
let subtitle_size = subtitle_path.metadata()?.size();
|
||||
if subtitle_size > self.meaningful_subtitle_min_size {
|
||||
// Only add subtitles with meaningful information
|
||||
subtitles.push(FFmpegMeta {
|
||||
path: subtitle_path,
|
||||
language: subtitle.locale.clone(),
|
||||
title: subtitle_title,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
videos.push(FFmpegMeta {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue