From 18a791635283482d4e48cb7ef00df8f908ff22ac Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 22 Dec 2023 11:59:47 +0100 Subject: tool: cleanup --- tool/Cargo.toml | 2 -- tool/src/main.rs | 87 ++++++++++++++++---------------------------------------- 2 files changed, 25 insertions(+), 64 deletions(-) (limited to 'tool') diff --git a/tool/Cargo.toml b/tool/Cargo.toml index 9ad1af4..9f72df5 100644 --- a/tool/Cargo.toml +++ b/tool/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" jellycommon = { path = "../common" } jellybase = { path = "../base" } jellyclient = { path = "../client" } -jellymatroska = { path = "../matroska" } -jellyremuxer = { path = "../remuxer" } log = { workspace = true } env_logger = "0.10.1" diff --git a/tool/src/main.rs b/tool/src/main.rs index 6384822..7b58125 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -7,6 +7,7 @@ pub mod migrate; +use anyhow::anyhow; use base64::Engine; use clap::{Parser, Subcommand, ValueEnum}; use jellyclient::{Instance, LoginDetails}; @@ -18,8 +19,9 @@ use std::{fmt::Debug, fs::File, io::Write, path::PathBuf}; #[derive(Parser)] struct Args { - #[arg(short = 'N', long)] - dry: bool, + /// Path to global jellything config + #[arg(short = 'C', long)] + config: Option, #[clap(subcommand)] action: Action, } @@ -35,55 +37,12 @@ enum Action { #[arg(short, long)] hostname: String, }, - // /// Imports a movie, video or series given media and metadata sources - // New { - // /// Relative path to the node's parent(!). - // path: PathBuf, - // /// Search the node by title on TMDB - // #[arg(short = 't', long)] - // tmdb_search: Option, - // /// Search the node by id on TMDB - // #[arg(short = 'T', long)] - // tmdb_id: Option, - // #[arg(long)] - // /// Prefix the inferred id with something to avoid collisions - // ident_prefix: Option, - // /// Copies media into the library - // #[arg(long)] - // copy: bool, - // /// Moves media into the library (potentially destructive operation) - // #[arg(long)] - // r#move: bool, - // /// Marks node as a video - // #[arg(long)] - // video: bool, - // /// 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, - // /// Sets the title - // #[arg(long)] - // title: Option, - // }, Migrate { database: PathBuf, mode: MigrateMode, save_location: PathBuf, }, Reimport { - /// Path to global jellything config - config: PathBuf, /// Custom hostname, the config's is used by default #[arg(long)] hostname: Option, @@ -106,6 +65,16 @@ fn main() -> anyhow::Result<()> { .init(); let args = Args::parse(); + let config = args + .config + .or(std::env::var_os("JELLYTHING_CONFIG").map(|p| PathBuf::from(p))) + .map(|path| { + Ok::<_, anyhow::Error>(serde_yaml::from_reader::<_, GlobalConfig>(File::open( + path, + )?)?) + }) + .transpose()?; + match args.action { Action::Init { base_path: path, @@ -163,19 +132,13 @@ fn main() -> anyhow::Result<()> { warn!("please change the admin password."); Ok(()) } - // a @ Action::New { .. } => import(a, args.dry), a @ Action::Migrate { .. } => migrate(a), - Action::Reimport { - config, - hostname, - no_tls, - } => tokio::runtime::Builder::new_multi_thread() + Action::Reimport { hostname, no_tls } => tokio::runtime::Builder::new_multi_thread() .enable_all() .build() .unwrap() .block_on(async move { - let config = serde_yaml::from_reader::<_, GlobalConfig>(File::open(config)?)?; - + let config = config.ok_or(anyhow!("this action requires the config"))?; let inst = Instance::new(hostname.unwrap_or(config.hostname.clone()), !no_tls); info!("login"); let session = inst @@ -193,12 +156,12 @@ fn main() -> anyhow::Result<()> { } } -fn ok_or_warn(r: Result) -> Option { - match r { - Ok(t) => Some(t), - Err(e) => { - warn!("{e:?}"); - None - } - } -} +// fn ok_or_warn(r: Result) -> Option { +// match r { +// Ok(t) => Some(t), +// Err(e) => { +// warn!("{e:?}"); +// None +// } +// } +// } -- cgit v1.2.3-70-g09d2