about summary refs log tree commit diff stats
path: root/pkgs/by-name/yt/yt/src/bin/yt/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/yt/yt/src/bin/yt/main.rs')
-rw-r--r--pkgs/by-name/yt/yt/src/bin/yt/main.rs91
1 files changed, 0 insertions, 91 deletions
diff --git a/pkgs/by-name/yt/yt/src/bin/yt/main.rs b/pkgs/by-name/yt/yt/src/bin/yt/main.rs
deleted file mode 100644
index 37348834..00000000
--- a/pkgs/by-name/yt/yt/src/bin/yt/main.rs
+++ /dev/null
@@ -1,91 +0,0 @@
-use anyhow::{bail, Context, Result};
-use std::{
-    env, fs,
-    io::{BufRead, BufReader, BufWriter, Write},
-    process::Command as StdCmd,
-};
-use tempfile::Builder;
-use yt::{
-    constants::{last_select, HELP_STR},
-    downloader::Downloader,
-    filter_line, YtccListData,
-};
-
-fn main() -> Result<()> {
-    cli_log::init_cli_log!();
-
-    let json_map = {
-        let mut ytcc = StdCmd::new("ytcc");
-        ytcc.args([
-            "--output",
-            "json",
-            "list",
-            "--order-by",
-            "publish_date",
-            "desc",
-        ]);
-
-        serde_json::from_slice::<Vec<YtccListData>>(
-            &ytcc.output().context("Failed to json from ytcc")?.stdout,
-        )
-        .context("Failed to deserialize json output")?
-    };
-
-    let temp_file = Builder::new()
-        .prefix("yt_video_select-")
-        .suffix(".yts")
-        .rand_bytes(6)
-        .tempfile()
-        .context("Failed to get tempfile")?;
-
-    {
-        let mut edit_file = BufWriter::new(&temp_file);
-
-        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_all(HELP_STR.as_bytes())?;
-        edit_file.flush().context("Failed to flush edit file")?;
-
-        let mut nvim = StdCmd::new("nvim");
-        nvim.arg(temp_file.path());
-        let status = nvim.status().context("Falied to run nvim")?;
-        if !status.success() {
-            bail!("nvim exited with error status: {}", status)
-        }
-    }
-
-    let read_file = temp_file.reopen()?;
-    fs::copy(
-        temp_file.path(),
-        last_select().context("Failed to get the persistent selection file path")?,
-    )
-    .context("Failed to persist selection file")?;
-
-    let mut watching = Vec::new();
-    let reader = BufReader::new(&read_file);
-    for line in reader.lines() {
-        let line = line.context("Failed to read line")?;
-
-        if let Some(downloadable) =
-            filter_line(&line).with_context(|| format!("Failed to process line: '{}'", line))?
-        {
-            watching.push(downloadable);
-        }
-    }
-
-    if watching.is_empty() {
-        return Ok(());
-    }
-
-    let downloader = Downloader::new(watching).context("Failed to construct downloader")?;
-    downloader
-        .consume()
-        .context("Failed to consume downloader")?;
-
-    Ok(())
-}