diff options
author | Soispha <soispha@vhack.eu> | 2024-01-20 18:38:18 +0100 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2024-01-20 18:38:18 +0100 |
commit | b53a8d82a07c29010a690b7126795fd7ddcabe0c (patch) | |
tree | 203dd0581950f9acb75881383d4b6fbc849e91af /sys/nixpkgs/pkgs/yt/src/lib.rs | |
parent | fix(sys/nixpkgs/yt/constants): Add extension to last selection path (diff) | |
download | nixos-config-b53a8d82a07c29010a690b7126795fd7ddcabe0c.zip |
feat(sys/nixpkgs/yt): Add support for the 'url' command
This simply opens the youtube url in the browser
Diffstat (limited to '')
-rw-r--r-- | sys/nixpkgs/pkgs/yt/src/lib.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/sys/nixpkgs/pkgs/yt/src/lib.rs b/sys/nixpkgs/pkgs/yt/src/lib.rs index 2571b6b6..7fa090af 100644 --- a/sys/nixpkgs/pkgs/yt/src/lib.rs +++ b/sys/nixpkgs/pkgs/yt/src/lib.rs @@ -1,4 +1,5 @@ use anyhow::{bail, Context}; +use downloader::Downloadable; use serde::Deserialize; use url::Url; @@ -50,6 +51,7 @@ pub enum LineCommand { Pick, Drop, Watch, + Url, } impl std::str::FromStr for LineCommand { @@ -59,6 +61,7 @@ impl std::str::FromStr for LineCommand { "pick" | "p" => Ok(Self::Pick), "drop" | "d" => Ok(Self::Drop), "watch" | "w" => Ok(Self::Watch), + "url" | "u" => Ok(Self::Url), other => bail!("'{}' is not a recognized command!", other), } } @@ -115,7 +118,7 @@ impl std::fmt::Display for Duration { let base_hour = self.time - (self.time % HOUR); let base_min = (self.time % HOUR) - ((self.time % HOUR) % MINUTE); - let base_sec = ((self.time % HOUR) % MINUTE) - (((self.time % HOUR) % MINUTE) % SECOND); + let base_sec = (self.time % HOUR) % MINUTE; let h = base_hour / HOUR; let m = base_min / MINUTE; @@ -154,3 +157,29 @@ pub fn ytcc_drop(id: u32) -> anyhow::Result<()> { } Ok(()) } + +pub fn filter_line(line: &str) -> anyhow::Result<Option<Downloadable>> { + // Filter out comments and empty lines + if line.starts_with('#') || line.trim().is_empty() { + return Ok(None); + } + + let line = Line::from(line); + match line.cmd { + LineCommand::Pick => Ok(None), + LineCommand::Drop => ytcc_drop(line.id) + .with_context(|| format!("Failed to drop: {}", line.id)) + .map(|_| None), + LineCommand::Watch => Ok(Some(Downloadable { + id: Some(line.id), + url: line.url, + })), + LineCommand::Url => { + let mut firefox = std::process::Command::new("firefox"); + firefox.args(["-P", "timesinks.youtube"]); + firefox.arg(line.url.as_str()); + let _handle = firefox.spawn().context("Failed to run firefox")?; + Ok(None) + } + } +} |