aboutsummaryrefslogtreecommitdiffstats
path: root/src/select
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-23 18:21:38 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-23 18:24:39 +0200
commit6adacc346a6b0406e69e77a24b204f2e74182471 (patch)
treed7c3c8bceb4be84a8e20703fa4b008f73f8ee3c5 /src/select
parentfeat(videos): Init (diff)
downloadyt-6adacc346a6b0406e69e77a24b204f2e74182471.zip
fix(select/cmds): Accept the watch flags for every command
This makes it easier to change the status of a video, without having to painstakingly remove the flags too.
Diffstat (limited to 'src/select')
-rw-r--r--src/select/cmds.rs85
-rw-r--r--src/select/selection_file/help.str6
2 files changed, 45 insertions, 46 deletions
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.
#