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/bin/yts/main.rs | 52 +++++++++++---------------------- 1 file changed, 17 insertions(+), 35 deletions(-) (limited to 'sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs') diff --git a/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs b/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs index 788ecab2..7398db61 100644 --- a/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs +++ b/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs @@ -6,7 +6,7 @@ use std::{ process::Command as StdCmd, }; use tempfile::NamedTempFile; -use yt::{constants::HELP_STR, ytcc_drop, Line, LineCommand, YtccListData}; +use yt::{constants::HELP_STR, filter_line, YtccListData}; use crate::args::{Args, Command, OrderCommand}; @@ -49,26 +49,13 @@ fn main() -> Result<()> { let mut edit_file = NamedTempFile::new().context("Failed to get tempfile")?; - let file: String = json_map - .iter() - .map(|line| { - format!( - "pick {} \"{}\" <{}> [{}]\n", - line.id, - line.title, - line.playlists - .iter() - .map(|p| &p.name[..]) - .collect::>() - .join(", "), - line.duration.trim() - ) - }) - .collect(); + json_map.iter().for_each(|line| { + let line = line.to_string(); + edit_file + .write_all(line.as_bytes()) + .expect("This write should not fail"); + }); - for line in file.lines() { - writeln!(&edit_file, "{}", line)?; - } write!(&edit_file, "{}", HELP_STR)?; edit_file.flush().context("Failed to flush edit file")?; @@ -87,23 +74,18 @@ fn main() -> Result<()> { for line in reader.lines() { let line = line.context("Failed to read line")?; - if line.starts_with("#") { - continue; - } else if line.trim().len() == 0 { - // empty line - continue; - } - - let line = Line::from(line.as_str()); - match line.cmd { - LineCommand::Pick => (), - LineCommand::Drop => { - ytcc_drop(line.id).with_context(|| format!("Failed to drop: {}", line.id))? - } - LineCommand::Watch => watching.push(line.id), + if let Some(downloadable) = + filter_line(&line).with_context(|| format!("Failed to process line: '{}'", line))? + { + watching.push(downloadable); } } - dbg!(&watching); + let watching: String = watching + .iter() + .map(|d| d.to_string()) + .collect::>() + .join("\n"); + println!("{}", &watching); Ok(()) } -- cgit 1.4.1