about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-25 15:55:15 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-25 15:55:15 +0200
commit5638cbda332f0cb4d2bc5bfefac5a3ab3d01366e (patch)
tree0348a6ec8da2e4e8dd87d4d95ce0fcfc3a422404
parentrefactor(watch/playlist_handler): Init (diff)
downloadyt-5638cbda332f0cb4d2bc5bfefac5a3ab3d01366e.tar.gz
yt-5638cbda332f0cb4d2bc5bfefac5a3ab3d01366e.zip
feat(cli): Support the common select -> download -> watch workflow
Diffstat (limited to '')
-rw-r--r--src/cli.rs3
-rw-r--r--src/main.rs21
2 files changed, 24 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 42b6378..60b0772 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -61,6 +61,9 @@ pub enum Command {
         max_cache_size: Option<u64>,
     },
 
+    /// Select, download and watch in one command.
+    SeDoWa {},
+
     /// Work with single videos
     Videos {
         #[command(subcommand)]
diff --git a/src/main.rs b/src/main.rs
index 7febefc..304b99f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,6 +23,7 @@ use storage::video_database::getters::get_video_by_hash;
 use tokio::{
     fs::File,
     io::{stdin, BufReader},
+    task::JoinHandle,
 };
 use url::Url;
 use yt_dlp::wrapper::info_json::InfoJson;
@@ -106,6 +107,26 @@ async fn main() -> Result<()> {
                 _ => handle_select_cmd(&app, cmd, None).await?,
             }
         }
+        Command::SeDoWa {} => {
+            select::select(&app, false, false).await?;
+
+            let max_cache_size = app.config.download.max_cache_size;
+            info!("Max cache size: '{}'", max_cache_size);
+
+            let arc_app = Arc::new(app);
+
+            let arc_app_clone = Arc::clone(&arc_app);
+            let download: JoinHandle<Result<()>> = tokio::spawn(async move {
+                download::Downloader::new()
+                    .consume(arc_app_clone, max_cache_size.as_u64())
+                    .await?;
+
+                Ok(())
+            });
+
+            watch::watch(&arc_app).await?;
+            download.await??;
+        }
         Command::Videos { cmd } => match cmd {
             VideosCommand::List {
                 search_query,