diff options
Diffstat (limited to 'tool/src')
| -rw-r--r-- | tool/src/add.rs | 19 | ||||
| -rw-r--r-- | tool/src/main.rs | 12 |
2 files changed, 15 insertions, 16 deletions
diff --git a/tool/src/add.rs b/tool/src/add.rs index fc43b76..40cc579 100644 --- a/tool/src/add.rs +++ b/tool/src/add.rs @@ -9,14 +9,13 @@ use jellyimport::{get_trakt, trakt::TraktKind}; use log::warn; use std::{ fmt::Display, - path::{Path, PathBuf}, -}; -use tokio::{ fs::{rename, OpenOptions}, - io::AsyncWriteExt, + io::Write, + path::{Path, PathBuf}, }; +use tokio::runtime::Handle; -pub async fn add(action: Action) -> anyhow::Result<()> { +pub fn add(action: Action, rt: &Handle) -> anyhow::Result<()> { match action { Action::Add { media } => { let theme = ColorfulTheme::default(); @@ -36,7 +35,7 @@ pub async fn add(action: Action) -> anyhow::Result<()> { let trakt = get_trakt()?; - let results = trakt.search(search_kinds, &name).await?; + let results = trakt.search(search_kinds, &name, rt)?; if results.is_empty() { warn!("no search results"); @@ -79,10 +78,8 @@ pub async fn add(action: Action) -> anyhow::Result<()> { .append(true) .write(true) .create(true) - .open(flagspath) - .await? - .write_all(flag.as_bytes()) - .await?; + .open(flagspath)? + .write_all(flag.as_bytes())?; } } else { let ext = media @@ -111,7 +108,7 @@ pub async fn add(action: Action) -> anyhow::Result<()> { .interact() .unwrap() { - rename(media, newpath).await?; + rename(media, newpath)?; } } diff --git a/tool/src/main.rs b/tool/src/main.rs index adf0a35..6aeb617 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -19,11 +19,13 @@ fn main() -> anyhow::Result<()> { let args = Args::parse(); match args { - a @ Action::Add { .. } => tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build() - .unwrap() - .block_on(add(a)), + a @ Action::Add { .. } => { + let rt = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap(); + add(a, rt.handle()) + } a @ Action::Migrate { .. } => migrate(a), _ => Ok(()), // Action::Reimport { |