mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Merge pull request #115 from crunchy-labs/feature/skip-existing-files
Skip existing files
This commit is contained in:
commit
901fdc0dbc
3 changed files with 31 additions and 25 deletions
|
|
@ -112,6 +112,10 @@ pub struct Archive {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
default_subtitle: Option<Locale>,
|
default_subtitle: Option<Locale>,
|
||||||
|
|
||||||
|
#[arg(help = "Skip files which are already existing")]
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
skip_existing: bool,
|
||||||
|
|
||||||
#[arg(help = "Ignore interactive input")]
|
#[arg(help = "Ignore interactive input")]
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
yes: bool,
|
yes: bool,
|
||||||
|
|
@ -232,17 +236,16 @@ impl Execute for Archive {
|
||||||
for (formats, mut subtitles) in archive_formats {
|
for (formats, mut subtitles) in archive_formats {
|
||||||
let (primary, additionally) = formats.split_first().unwrap();
|
let (primary, additionally) = formats.split_first().unwrap();
|
||||||
|
|
||||||
let path = free_file(
|
let formatted_path = primary.format_path((&self.output).into(), true);
|
||||||
primary.format_path(
|
let (path, changed) = free_file(formatted_path.clone());
|
||||||
if self.output.is_empty() {
|
|
||||||
"{title}.mkv"
|
if changed && self.skip_existing {
|
||||||
} else {
|
debug!(
|
||||||
&self.output
|
"Skipping already existing file '{}'",
|
||||||
}
|
formatted_path.to_string_lossy()
|
||||||
.into(),
|
);
|
||||||
true,
|
continue;
|
||||||
),
|
}
|
||||||
);
|
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Downloading {} to '{}'",
|
"Downloading {} to '{}'",
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ pub struct Download {
|
||||||
#[arg(value_parser = FFmpegPreset::parse)]
|
#[arg(value_parser = FFmpegPreset::parse)]
|
||||||
ffmpeg_preset: Vec<FFmpegPreset>,
|
ffmpeg_preset: Vec<FFmpegPreset>,
|
||||||
|
|
||||||
|
#[arg(help = "Skip files which are already existing")]
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
skip_existing: bool,
|
||||||
|
|
||||||
#[arg(help = "Ignore interactive input")]
|
#[arg(help = "Ignore interactive input")]
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
yes: bool,
|
yes: bool,
|
||||||
|
|
@ -216,17 +220,16 @@ impl Execute for Download {
|
||||||
}
|
}
|
||||||
|
|
||||||
for format in formats {
|
for format in formats {
|
||||||
let path = free_file(
|
let formatted_path = format.format_path((&self.output).into(), true);
|
||||||
format.format_path(
|
let (path, changed) = free_file(formatted_path.clone());
|
||||||
if self.output.is_empty() {
|
|
||||||
"{title}.mkv"
|
if changed && self.skip_existing {
|
||||||
} else {
|
debug!(
|
||||||
&self.output
|
"Skipping already existing file '{}'",
|
||||||
}
|
formatted_path.to_string_lossy()
|
||||||
.into(),
|
);
|
||||||
true,
|
continue;
|
||||||
),
|
}
|
||||||
);
|
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Downloading {} to '{}'",
|
"Downloading {} to '{}'",
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ pub fn tempfile<S: AsRef<str>>(suffix: S) -> io::Result<NamedTempFile> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the given path exists and rename it until the new (renamed) file does not exist.
|
/// Check if the given path exists and rename it until the new (renamed) file does not exist.
|
||||||
pub fn free_file(mut path: PathBuf) -> PathBuf {
|
pub fn free_file(mut path: PathBuf) -> (PathBuf, bool) {
|
||||||
// if it's a special file does not rename it
|
// if it's a special file does not rename it
|
||||||
if is_special_file(&path) {
|
if is_special_file(&path) {
|
||||||
return path;
|
return (path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
@ -55,7 +55,7 @@ pub fn free_file(mut path: PathBuf) -> PathBuf {
|
||||||
|
|
||||||
path.set_file_name(format!("{} ({}).{}", filename, i, ext))
|
path.set_file_name(format!("{} ({}).{}", filename, i, ext))
|
||||||
}
|
}
|
||||||
path
|
(path, i != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the given path is a special file. On Linux this is probably a pipe and on Windows
|
/// Check if the given path is a special file. On Linux this is probably a pipe and on Windows
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue