From b53a8d82a07c29010a690b7126795fd7ddcabe0c Mon Sep 17 00:00:00 2001 From: Soispha Date: Sat, 20 Jan 2024 18:38:18 +0100 Subject: feat(sys/nixpkgs/yt): Add support for the 'url' command This simply opens the youtube url in the browser --- sys/nixpkgs/pkgs/yt/src/downloader.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'sys/nixpkgs/pkgs/yt/src/downloader.rs') 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, } +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>, @@ -34,8 +45,8 @@ impl Downloader { let (itx, irx): (Sender, Receiver) = 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"); -- cgit 1.4.1