Skip to content

Commit

Permalink
add choice on output file existing
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nil committed Jan 16, 2024
1 parent 9012146 commit d4e9127
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 11 deletions.
94 changes: 93 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
shell-escape = "0.1.5"
sled = "0.34.7"
strum = { version = "0.25.0", features = ["derive"] }
strum_macros = "0.25.3"
time = { version = "0.3", features = ["parsing", "macros"] }
tokio = { version = "1.15", features = ["rt", "macros", "process", "fs", "signal"] }
tokio = { version = "1.15", features = [
"rt",
"macros",
"process",
"fs",
"signal",
] }
tokio-process-stream = "0.4"
tokio-stream = "0.1"

[dev-dependencies]
mktemp = "0.5.1"

[target.'cfg(unix)'.dependencies]
unix-named-pipe = "0.2"

[target.'cfg(windows)'.dependencies.tokio]
version = "1.15"
features = ["net"]

[profile.release]
lto = true
opt-level = "s"
Expand Down
34 changes: 33 additions & 1 deletion src/command/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ mod encode;
mod vmaf;

pub use encode::*;
use strum::EnumCount;
pub use vmaf::*;

use crate::{command::encode::default_output_ext, ffprobe::Ffprobe};
use clap::Parser;
use clap::{Parser, ValueEnum};
use std::{
path::{Path, PathBuf},
sync::Arc,
Expand All @@ -22,6 +23,10 @@ pub struct EncodeToOutput {
#[arg(short, long)]
pub output: Option<PathBuf>,

/// What to do if the output file already exists.
#[arg(long, default_value("rename"))]
pub on_duplicate: Option<OnDuplicate>,

/// Set the output ffmpeg audio codec.
/// By default 'copy' is used. Otherwise, if re-encoding is necessary, 'libopus' is default.
///
Expand Down Expand Up @@ -95,3 +100,30 @@ impl Sample {
self.extension = output.extension().and_then(|e| e.to_str().map(Into::into));
}
}

#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, Hash, EnumCount)]
pub enum OnDuplicate {
Overwrite,
Skip,
#[default]
Rename,
Ask,
}

impl ValueEnum for OnDuplicate {
fn value_variants<'a>() -> &'a [Self] {
let variants = &[Self::Overwrite, Self::Skip, Self::Rename, Self::Ask];
// safety check in case one forgets to add a new variant
debug_assert!(OnDuplicate::COUNT == variants.len());
variants
}

fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
match self {
OnDuplicate::Overwrite => Some(clap::builder::PossibleValue::new("overwrite")),
OnDuplicate::Skip => Some(clap::builder::PossibleValue::new("skip")),
OnDuplicate::Rename => Some(clap::builder::PossibleValue::new("rename").help("Tries to rename the output file by appending and incrementing a number.\nE.g. `vid.av1.mkv` -> `vid.av1_1.mkv` -> `vid.av1_2.mkv` etc.")),
OnDuplicate::Ask => Some(clap::builder::PossibleValue::new("ask")),
}
}
}
Loading

0 comments on commit d4e9127

Please sign in to comment.