about summary refs log tree commit diff stats
path: root/src/select/cmds.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-22 14:23:38 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-22 14:23:38 +0200
commit2fd17e51868b5f25e888b6aee1c1f56f3fbec40b (patch)
tree5ce49ca4092438e47fcb677e6594174bd346fbdb /src/select/cmds.rs
parentfeat(download): Support limiting the downloader by maximal cache size (diff)
downloadyt-2fd17e51868b5f25e888b6aee1c1f56f3fbec40b.tar.gz
yt-2fd17e51868b5f25e888b6aee1c1f56f3fbec40b.zip
feat(select/file): Allow `--priority` argument to all functions
This allows setting a priority even on picked videos.
Diffstat (limited to 'src/select/cmds.rs')
-rw-r--r--src/select/cmds.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/select/cmds.rs b/src/select/cmds.rs
index 40e5b17..85e655f 100644
--- a/src/select/cmds.rs
+++ b/src/select/cmds.rs
@@ -25,41 +25,46 @@ 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,
-                line_number,
+                priority,
             )
             .await?
         }
         SelectCommand::Drop { shared } => {
+            let priority = compute_priority(line_number, shared.priority);
             set_video_status(
                 app,
                 &shared.hash.realize(app).await?,
                 VideoStatus::Drop,
-                line_number,
+                priority,
             )
             .await?
         }
         SelectCommand::Watch {
             shared,
-            priority,
             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, speed);
-            let priority = if let Some(pri) = priority {
-                Some(pri)
-            } else if let Some(pri) = line_number {
-                Some(pri)
-            } else {
-                None
-            };
+            let priority = compute_priority(line_number, shared.priority);
 
             if let Some(_) = video.cache_path {
                 set_video_status(app, &hash, VideoStatus::Cached, priority).await?;