diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-22 14:23:38 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-22 14:23:38 +0200 |
commit | 2fd17e51868b5f25e888b6aee1c1f56f3fbec40b (patch) | |
tree | 5ce49ca4092438e47fcb677e6594174bd346fbdb | |
parent | feat(download): Support limiting the downloader by maximal cache size (diff) | |
download | yt-2fd17e51868b5f25e888b6aee1c1f56f3fbec40b.tar.gz yt-2fd17e51868b5f25e888b6aee1c1f56f3fbec40b.zip |
feat(select/file): Allow `--priority` argument to all functions
This allows setting a priority even on picked videos.
-rw-r--r-- | src/cli.rs | 9 | ||||
-rw-r--r-- | src/select/cmds.rs | 25 | ||||
-rw-r--r-- | src/select/selection_file/help.str | 6 |
3 files changed, 23 insertions, 17 deletions
diff --git a/src/cli.rs b/src/cli.rs index a61a57e..34a98a6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -197,6 +197,10 @@ pub enum SubscriptionCommand { #[command(infer_subcommands = true)] /// Mark the video given by the hash to be watched pub struct SharedSelectionCommandArgs { + /// The ordering priority (higher means more at the top) + #[arg(short, long)] + pub priority: Option<i64>, + /// The short extractor hash pub hash: LazyExtractorHash, @@ -226,15 +230,12 @@ pub enum SelectCommand { #[command(flatten)] shared: SharedSelectionCommandArgs, - /// The ordering priority (higher means more at the top) - #[arg(short, long)] - priority: Option<i64>, - /// The subtitles to download (e.g. 'en,de,sv') #[arg(short = 'l', long, default_value = constants::DEFAULT_SUBTITLE_LANGS)] subtitle_langs: String, /// The speed to set mpv to + // NOTE: KEEP THIS IN SYNC WITH THE `DEFAULT_MPV_PLAYBACK_SPEED` in `constants.rs` <2024-08-20> #[arg(short, long, default_value = "2.7")] speed: f64, }, 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?; diff --git a/src/select/selection_file/help.str b/src/select/selection_file/help.str index 6e296f6..295bc4d 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 Mark the video given by the hash to be dropped -# u, url Open the video URL in Firefox's `timesinks.youtube` profile -# p, pick Reset the videos status to 'Pick' +# 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' # # See `yt select <cmd_name> --help` for more help. # |