about summary refs log tree commit diff stats
path: root/sys/nixpkgs/pkgs/yt/src/downloader.rs
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-01-20 18:38:18 +0100
committerSoispha <soispha@vhack.eu>2024-01-20 18:38:18 +0100
commitb53a8d82a07c29010a690b7126795fd7ddcabe0c (patch)
tree203dd0581950f9acb75881383d4b6fbc849e91af /sys/nixpkgs/pkgs/yt/src/downloader.rs
parentfix(sys/nixpkgs/yt/constants): Add extension to last selection path (diff)
downloadnixos-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/downloader.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/sys/nixpkgs/pkgs/yt/src/downloader.rs b/sys/nixpkgs/pkgs/yt/src/downloader.rs
index 34627f70..b30c49a2 100644
--- a/sys/nixpkgs/pkgs/yt/src/downloader.rs
+++ b/sys/nixpkgs/pkgs/yt/src/downloader.rs
@@ -21,6 +21,17 @@ pub struct Downloadable {
     pub id: Option<u32>,
 }
 
+impl std::fmt::Display for Downloadable {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
+        write!(
+            f,
+            "{}|{}",
+            self.url.as_str().replace('|', ";"),
+            self.id.unwrap_or(0),
+        )
+    }
+}
+
 pub struct Downloader {
     sent: usize,
     download_thread: JoinHandle<Result<()>>,
@@ -34,8 +45,8 @@ impl Downloader {
         let (itx, irx): (Sender<Downloadable>, Receiver<Downloadable>) = mpsc::channel();
         let (otx, orx) = mpsc::channel();
         let jh = thread::spawn(move || -> Result<()> {
-            while let Some(pt) = irx.recv().ok() {
-                debug!("Got '{}|{}' to be downloaded", pt.url, pt.id.unwrap_or(0));
+            while let Ok(pt) = irx.recv() {
+                debug!("Got '{}' to be downloaded", pt);
                 let path = download_url(&pt.url)
                     .with_context(|| format!("Failed to download url: '{}'", &pt.url))?;
                 otx.send((path, pt.id)).expect("Should not be dropped");