about summary refs log tree commit diff stats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cli.rs16
-rw-r--r--src/select/cmds.rs85
-rw-r--r--src/select/selection_file/help.str6
3 files changed, 53 insertions, 54 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 72ec877..3883cb1 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -190,6 +190,14 @@ pub struct SharedSelectionCommandArgs {
     #[arg(short, long)]
     pub priority: Option<i64>,
 
+    /// The subtitles to download (e.g. 'en,de,sv')
+    #[arg(short = 'l', long)]
+    pub subtitle_langs: Option<String>,
+
+    /// The speed to set mpv to
+    #[arg(short, long)]
+    pub speed: Option<f64>,
+
     /// The short extractor hash
     pub hash: LazyExtractorHash,
 
@@ -218,14 +226,6 @@ pub enum SelectCommand {
     Watch {
         #[command(flatten)]
         shared: SharedSelectionCommandArgs,
-
-        /// The subtitles to download (e.g. 'en,de,sv')
-        #[arg(short = 'l', long)]
-        subtitle_langs: Option<String>,
-
-        /// The speed to set mpv to
-        #[arg(short, long)]
-        speed: Option<f64>,
     },
 
     /// Mark the video given by the hash to be dropped
diff --git a/src/select/cmds.rs b/src/select/cmds.rs
index c480bd9..2b36fe8 100644
--- a/src/select/cmds.rs
+++ b/src/select/cmds.rs
@@ -10,7 +10,7 @@
 
 use crate::{
     app::App,
-    cli::SelectCommand,
+    cli::{SelectCommand, SharedSelectionCommandArgs},
     storage::video_database::{
         getters::get_video_by_hash,
         setters::{set_video_options, set_video_status},
@@ -25,57 +25,25 @@ pub async fn handle_select_cmd(
     cmd: SelectCommand,
     line_number: Option<i64>,
 ) -> Result<()> {
-    fn compute_priority(line_number: Option<i64>, priority: Option<i64>) -> Option<i64> {
-        if let Some(pri) = priority {
-            Some(pri)
-        } else if let Some(pri) = line_number {
-            Some(pri)
-        } else {
-            None
-        }
-    }
-
     match cmd {
         SelectCommand::Pick { shared } => {
-            let priority = compute_priority(line_number, shared.priority);
-            set_video_status(
-                app,
-                &shared.hash.realize(app).await?,
-                VideoStatus::Pick,
-                priority,
-            )
-            .await?
+            handle_status_change(app, shared, line_number, VideoStatus::Pick).await?;
         }
         SelectCommand::Drop { shared } => {
-            let priority = compute_priority(line_number, shared.priority);
-            set_video_status(
-                app,
-                &shared.hash.realize(app).await?,
-                VideoStatus::Drop,
-                priority,
-            )
-            .await?
+            handle_status_change(app, shared, line_number, VideoStatus::Drop).await?;
         }
-        SelectCommand::Watch {
-            shared,
-            subtitle_langs,
-            speed,
-        } => {
-            let hash = shared.hash.realize(&app).await?;
-            let video = get_video_by_hash(app, &hash).await?;
-            let video_options = VideoOptions::new(
-                subtitle_langs.unwrap_or(app.config.select.subtitle_langs.clone()),
-                speed.unwrap_or(app.config.select.playback_speed),
-            );
-            let priority = compute_priority(line_number, shared.priority);
+        SelectCommand::Watched { shared } => {
+            handle_status_change(app, shared, line_number, VideoStatus::Watched).await?;
+        }
+        SelectCommand::Watch { shared } => {
+            let hash = shared.hash.clone().realize(&app).await?;
 
+            let video = get_video_by_hash(app, &hash).await?;
             if let Some(_) = video.cache_path {
-                set_video_status(app, &hash, VideoStatus::Cached, priority).await?;
+                handle_status_change(app, shared, line_number, VideoStatus::Cached).await?;
             } else {
-                set_video_status(app, &hash, VideoStatus::Watch, priority).await?;
+                handle_status_change(app, shared, line_number, VideoStatus::Watch).await?;
             }
-
-            set_video_options(app, hash, &video_options).await?;
         }
 
         SelectCommand::Url { shared } => {
@@ -88,3 +56,34 @@ pub async fn handle_select_cmd(
     }
     Ok(())
 }
+
+async fn handle_status_change(
+    app: &App,
+    shared: SharedSelectionCommandArgs,
+    line_number: Option<i64>,
+    new_status: VideoStatus,
+) -> Result<()> {
+    let hash = shared.hash.realize(&app).await?;
+    let video_options = VideoOptions::new(
+        shared
+            .subtitle_langs
+            .unwrap_or(app.config.select.subtitle_langs.clone()),
+        shared.speed.unwrap_or(app.config.select.playback_speed),
+    );
+    let priority = compute_priority(line_number, shared.priority);
+
+    set_video_status(app, &hash, new_status, priority).await?;
+    set_video_options(app, &hash, &video_options).await?;
+
+    Ok(())
+}
+
+fn compute_priority(line_number: Option<i64>, priority: Option<i64>) -> Option<i64> {
+    if let Some(pri) = priority {
+        Some(pri)
+    } else if let Some(pri) = line_number {
+        Some(pri)
+    } else {
+        None
+    }
+}
diff --git a/src/select/selection_file/help.str b/src/select/selection_file/help.str
index 295bc4d..9f4a896 100644
--- a/src/select/selection_file/help.str
+++ b/src/select/selection_file/help.str
@@ -1,8 +1,8 @@
 # Commands:
 #   w, watch [-p,-s,-l]   Mark the video given by the hash to be watched
-#   d, drop  [-p]         Mark the video given by the hash to be dropped
-#   u, url   [-p]         Open the video URL in Firefox's `timesinks.youtube` profile
-#   p, pick  [-p]         Reset the videos status to 'Pick'
+#   d, drop  [-p,-s,-l]   Mark the video given by the hash to be dropped
+#   u, url   [-p,-s,-l]   Open the video URL in Firefox's `timesinks.youtube` profile
+#   p, pick  [-p,-s,-l]   Reset the videos status to 'Pick'
 #
 # See `yt select <cmd_name> --help` for more help.
 #