From c71a10717392cc321b97e3f2173645e78c263488 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 3 Aug 2023 19:14:26 +0200 Subject: symlink sources --- tools/src/bin/import.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'tools/src') diff --git a/tools/src/bin/import.rs b/tools/src/bin/import.rs index a27b247..471a669 100644 --- a/tools/src/bin/import.rs +++ b/tools/src/bin/import.rs @@ -10,7 +10,12 @@ use jellymatroska::read::EbmlReader; use jellyremuxer::import::import_read; use jellytools::tmdb::{tmdb_details, tmdb_image, tmdb_search}; use log::info; -use std::{fs::File, io::stdin, path::PathBuf, process::exit}; +use std::{ + fs::{remove_file, File}, + io::stdin, + path::PathBuf, + process::exit, +}; #[derive(Parser)] struct Args { @@ -27,6 +32,10 @@ enum Action { title: Option, #[arg(short = 'T', long)] tmdb: Option, + #[arg(long)] + copy: bool, + #[arg(long)] + r#move: bool, #[arg(short, long)] input: Option, #[arg(short, long)] @@ -64,6 +73,8 @@ fn main() -> anyhow::Result<()> { tmdb: id, input, series, + copy, + r#move, } => { assert!(series || input.is_some(), "series or input required"); let kind = if series { "tv" } else { "movie" }; @@ -133,9 +144,16 @@ fn main() -> anyhow::Result<()> { if let Some(input) = input { let source_path = path.join(format!("source.mkv")); - // std::fs::rename(&input, &source_path)?; - // std::os::unix::fs::symlink(&input, &source_path)?; - std::fs::copy(&input, &source_path)?; + if r#move { + std::fs::rename(&input, &source_path)?; + } else if copy { + std::fs::copy(&input, &source_path)?; + } else { + if source_path.is_symlink() { + remove_file(&source_path)?; + } + std::os::unix::fs::symlink(&input, &source_path)?; + } let input = File::open(&source_path).unwrap(); let mut input = EbmlReader::new(input); let (tracks, local_tracks, seek_index, duration) = -- cgit v1.2.3-70-g09d2