about summary refs log tree commit diff stats
path: root/sys/nixpkgs/pkgs/yt/src/bin/yts
diff options
context:
space:
mode:
Diffstat (limited to 'sys/nixpkgs/pkgs/yt/src/bin/yts')
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs52
1 files changed, 17 insertions, 35 deletions
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(())
 }