about summary refs log tree commit diff stats
path: root/sys/nixpkgs/pkgs/yt/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'sys/nixpkgs/pkgs/yt/src/bin')
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs46
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs2
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs52
3 files changed, 33 insertions, 67 deletions
diff --git a/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs b/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs
index ae1bcacd..f3c16613 100644
--- a/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs
+++ b/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs
@@ -7,8 +7,8 @@ use std::{
 use tempfile::Builder;
 use yt::{
     constants::{last_select, HELP_STR},
-    downloader::{Downloadable, Downloader},
-    ytcc_drop, Line, LineCommand, YtccListData,
+    downloader::Downloader,
+    filter_line, YtccListData,
 };
 
 fn main() -> Result<()> {
@@ -41,16 +41,14 @@ fn main() -> Result<()> {
     {
         let mut edit_file = BufWriter::new(&temp_file);
 
-        json_map
-            .iter()
-            .map(|line| line.to_string())
-            .for_each(|line| {
-                edit_file
-                    .write(line.as_bytes())
-                    .expect("This write should not fail");
-            });
+        json_map.iter().for_each(|line| {
+            let line = line.to_string();
+            edit_file
+                .write_all(line.as_bytes())
+                .expect("This write should not fail");
+        });
 
-        edit_file.write(HELP_STR.as_bytes())?;
+        edit_file.write_all(HELP_STR.as_bytes())?;
         edit_file.flush().context("Failed to flush edit file")?;
 
         let mut nvim = StdCmd::new("nvim");
@@ -64,7 +62,7 @@ fn main() -> Result<()> {
     let read_file = temp_file.reopen()?;
     fs::copy(
         temp_file.path(),
-        last_select().context("Failed to get persistent the selection file path")?,
+        last_select().context("Failed to get the persistent selection file path")?,
     )
     .context("Failed to persist selection file")?;
 
@@ -73,28 +71,14 @@ fn main() -> Result<()> {
     for line in reader.lines() {
         let line = line.context("Failed to read line")?;
 
-        if line.starts_with("#") {
-            // comment
-            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(Downloadable {
-                id: Some(line.id),
-                url: line.url,
-            }),
+        if let Some(downloadable) =
+            filter_line(&line).with_context(|| format!("Failed to process line: '{}'", line))?
+        {
+            watching.push(downloadable);
         }
     }
 
-    if watching.len() == 0 {
+    if watching.is_empty() {
         return Ok(());
     }
 
diff --git a/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs b/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs
index 437df803..3fa3148d 100644
--- a/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs
+++ b/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs
@@ -37,7 +37,7 @@ fn main() -> Result<()> {
                 )
                 .context("Failed to deserialize json output")?;
 
-                if json.len() == 0 {
+                if json.is_empty() {
                     bail!("Could not find a video with id: {}", id);
                 }
                 assert_eq!(json.len(), 1);
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::<Vec<&str>>()
-                    .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::<Vec<String>>()
+        .join("\n");
+    println!("{}", &watching);
     Ok(())
 }