diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-23 03:19:40 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-23 03:19:40 +0100 |
commit | da57ad84e185fa2ee9d812bc74432bec51e6046e (patch) | |
tree | 0afb949f89225d1effe2e8d179714223883ebe65 /tool | |
parent | 63661f7cf6ed7421b895e024d47664464fc461b1 (diff) | |
download | jellything-da57ad84e185fa2ee9d812bc74432bec51e6046e.tar jellything-da57ad84e185fa2ee9d812bc74432bec51e6046e.tar.bz2 jellything-da57ad84e185fa2ee9d812bc74432bec51e6046e.tar.zst |
auto select directory and search result
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/add.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tool/src/add.rs b/tool/src/add.rs index 4645846..279574f 100644 --- a/tool/src/add.rs +++ b/tool/src/add.rs @@ -9,6 +9,7 @@ use dialoguer::{theme::ColorfulTheme, Confirm, FuzzySelect, Input, MultiSelect}; use jellybase::{CONF, SECRETS}; use jellycommon::{AssetLocation, ImportOptions, ImportSource, TraktKind}; use jellyimport::trakt::Trakt; +use log::warn; use tokio::{fs::File, io::AsyncWriteExt}; pub(crate) async fn add(action: Action) -> anyhow::Result<()> { @@ -44,8 +45,24 @@ pub(crate) async fn add(action: Action) -> anyhow::Result<()> { find_folders(&CONF.library_path, &PathBuf::new(), &mut directories) .context("listing library directories")?; + let mut default = 0; + for k in possible_kinds { + match k { + TraktKind::Movie => { + if let Some(i) = directories + .iter() + .position(|d| d.0.to_str().unwrap().contains("movies")) + { + default = i + }; + } + _ => (), + } + } + let target_dir_index = FuzzySelect::with_theme(&theme) .items(&directories) + .default(default) .interact() .unwrap(); directories[target_dir_index].0.clone() @@ -68,8 +85,14 @@ pub(crate) async fn add(action: Action) -> anyhow::Result<()> { let results = trakt.search(&search_kinds, &name, false).await?; + if results.is_empty() { + warn!("no search results"); + continue; + } + let correct = FuzzySelect::with_theme(&theme) .items(&results) + .default(0) .with_prompt("Metadata Source") .interact_opt() .unwrap(); |