From 2e6f2a2d21a0ba9a5c8f13bf27e64615144cf222 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 17 Dec 2023 14:49:19 +0100 Subject: tool: skip existing option --- tool/src/import/mod.rs | 15 ++++++++++++++- tool/src/main.rs | 9 ++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'tool/src') diff --git a/tool/src/import/mod.rs b/tool/src/import/mod.rs index fb42c4d..b4e03d6 100644 --- a/tool/src/import/mod.rs +++ b/tool/src/import/mod.rs @@ -15,7 +15,7 @@ use jellycommon::{ }; use jellymatroska::read::EbmlReader; use jellyremuxer::import::import_metadata; -use log::{info, warn}; +use log::{debug, info, warn}; use std::{ collections::BTreeMap, fs::{remove_file, File}, @@ -37,11 +37,24 @@ pub(crate) fn import(action: Action, dry: bool) -> anyhow::Result<()> { video, ignore_metadata, r#move, + skip_existing, } => { if std::env::current_dir().unwrap().file_name().unwrap() != "library" { warn!("new command can only be used in the library directory; what you are doing right now probably wont work.") } + if skip_existing { + if let Some(input) = &input { + let guessed_path = path.join(input.file_stem().unwrap_or(input.as_os_str())); + if guessed_path.exists() { + info!("guessed output ({guessed_path:?}) exists, skipping import"); + return Ok(()); + } else { + debug!("guessed output ({guessed_path:?}) missing"); + } + } + } + let tmdb_kind = if series { "tv" } else { "movie" }; let tmdb_id = if let Some(id) = tmdb_id { Some(id.parse().unwrap()) diff --git a/tool/src/main.rs b/tool/src/main.rs index 47c9a53..3744560 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -59,18 +59,21 @@ enum Action { /// Marks node as a video #[arg(long)] video: bool, - /// Path to the media of the node, required for non-series - #[arg(short, long)] - input: Option, /// Marks node as a series #[arg(short, long)] series: bool, + /// Path to the media of the node, required for non-series + #[arg(short, long)] + input: Option, /// Ignore attachments (dont use them as cover) #[arg(long)] ignore_attachments: bool, /// Ignore metadate (no title, description and tagline from input) #[arg(long)] ignore_metadata: bool, + /// Skip any action that appears to be run already. + #[arg(long)] + skip_existing: bool, }, Migrate { database: PathBuf, -- cgit v1.2.3-70-g09d2