Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user choice on existing output file; don't just overwrite target #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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