about summary refs log tree commit diff stats
path: root/sys/nixpkgs/pkgs/yt/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sys/nixpkgs/pkgs/yt/src/lib.rs31
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)
+        }
+    }
+}