diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-21 10:49:23 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-21 11:28:43 +0200 |
commit | 1debeb77f7986de1b659dcfdc442de6415e1d9f5 (patch) | |
tree | 4df3e7c3f6a2d1ec116e4088c5ace7f143a8b05f /src/select/cmds.rs | |
download | yt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.tar.gz yt-1debeb77f7986de1b659dcfdc442de6415e1d9f5.zip |
chore: Initial Commit
This repository was migrated out of my nixos-config.
Diffstat (limited to 'src/select/cmds.rs')
-rw-r--r-- | src/select/cmds.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/select/cmds.rs b/src/select/cmds.rs new file mode 100644 index 0000000..40e5b17 --- /dev/null +++ b/src/select/cmds.rs @@ -0,0 +1,82 @@ +// yt - A fully featured command line YouTube client +// +// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de> +// SPDX-License-Identifier: GPL-3.0-or-later +// +// This file is part of Yt. +// +// You should have received a copy of the License along with this program. +// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +use crate::{ + app::App, + cli::SelectCommand, + storage::video_database::{ + getters::get_video_by_hash, + setters::{set_video_options, set_video_status}, + VideoOptions, VideoStatus, + }, +}; + +use anyhow::{Context, Result}; + +pub async fn handle_select_cmd( + app: &App, + cmd: SelectCommand, + line_number: Option<i64>, +) -> Result<()> { + match cmd { + SelectCommand::Pick { shared } => { + set_video_status( + app, + &shared.hash.realize(app).await?, + VideoStatus::Pick, + line_number, + ) + .await? + } + SelectCommand::Drop { shared } => { + set_video_status( + app, + &shared.hash.realize(app).await?, + VideoStatus::Drop, + line_number, + ) + .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 + }; + + if let Some(_) = video.cache_path { + set_video_status(app, &hash, VideoStatus::Cached, priority).await?; + } else { + set_video_status(app, &hash, VideoStatus::Watch, priority).await?; + } + + set_video_options(app, hash, &video_options).await?; + } + + SelectCommand::Url { shared } => { + let mut firefox = std::process::Command::new("firefox"); + firefox.args(["-P", "timesinks.youtube"]); + firefox.arg(shared.url.as_str()); + let _handle = firefox.spawn().context("Failed to run firefox")?; + } + SelectCommand::File { .. } => unreachable!("This should have been filtered out"), + } + Ok(()) +} |