about summary refs log tree commit diff stats
path: root/pkgs/by-name/yt/yt/src/select/selection_file/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/yt/yt/src/select/selection_file/mod.rs')
-rw-r--r--pkgs/by-name/yt/yt/src/select/selection_file/mod.rs82
1 files changed, 14 insertions, 68 deletions
diff --git a/pkgs/by-name/yt/yt/src/select/selection_file/mod.rs b/pkgs/by-name/yt/yt/src/select/selection_file/mod.rs
index 957fcd08..c63ca85a 100644
--- a/pkgs/by-name/yt/yt/src/select/selection_file/mod.rs
+++ b/pkgs/by-name/yt/yt/src/select/selection_file/mod.rs
@@ -1,79 +1,25 @@
 //! The data structures needed to express the file, which the user edits
 
-use anyhow::{bail, Context};
-use url::Url;
-
-use crate::{app::App, storage::video_database::extractor_hash::ExtractorHash};
+use anyhow::{Context, Result};
+use trinitry::Trinitry;
 
 pub mod display;
 pub mod duration;
 
-pub enum LineCommand {
-    Pick,
-    Drop,
-    Watch,
-    Url,
-}
-
-impl std::str::FromStr for LineCommand {
-    type Err = anyhow::Error;
-    fn from_str(v: &str) -> Result<Self, <Self as std::str::FromStr>::Err> {
-        match v {
-            "pick" | "p" => Ok(Self::Pick),
-            "drop" | "d" => Ok(Self::Drop),
-            "watch" | "w" => Ok(Self::Watch),
-            "url" | "u" => Ok(Self::Url),
-            other => bail!("'{}' is not a recognized command!", other),
-        }
-    }
-}
-
-pub struct Line {
-    pub cmd: LineCommand,
-    pub hash: ExtractorHash,
-    pub url: Url,
-}
-
-impl Line {
-    pub async fn from_str(app: &App, s: &str) -> anyhow::Result<Self> {
-        let buf: Vec<_> = s.split_whitespace().collect();
-
-        let url_as_str = buf
-            .last()
-            .with_context(|| format!("The line '{}' misses it's url field!'", s))?
-            .trim_matches('"');
+pub fn process_line(line: &str) -> Result<Option<Vec<String>>> {
+    // Filter out comments and empty lines
+    if line.starts_with('#') || line.trim().is_empty() {
+        Ok(None)
+    } else {
+        // pick 2195db "CouchRecherche? Gunnar und Han von STRG_F sind #mitfunkzuhause" "2020-04-01" "STRG_F - Live" "[1h 5m]" "https://www.youtube.com/watch?v=C8UXOaoMrXY"
 
-        let url: Url = Url::parse(url_as_str)
-            .with_context(|| format!("The url '{}' could not be parsed!", url_as_str))?;
+        let tri =
+            Trinitry::new(line).with_context(|| format!("Failed to parse line '{}'", line))?;
 
-        Ok(Line {
-            cmd: buf
-                .get(0)
-                .with_context(|| format!("The line '{}' is missing it's command!", s))?
-                .parse()?,
-            hash: ExtractorHash::parse_from_short_version(
-                app,
-                buf.get(1)
-                    .with_context(|| format!("The line '{}' is missing it's blake3 hash!", s))?,
-            )
-            .await
-            .with_context(|| {
-                format!(
-                    "Can't parse '{}' as blake3 hash!",
-                    buf.get(1).expect("Already checked"),
-                )
-            })?,
-            url,
-        })
-    }
-}
+        let mut vec = Vec::with_capacity(tri.arguments().len() + 1);
+        vec.push(tri.command().to_owned());
+        vec.extend(tri.arguments().to_vec().into_iter());
 
-pub async fn filter_line(app: &App, line: &str) -> anyhow::Result<Option<Line>> {
-    // Filter out comments and empty lines
-    if line.starts_with('#') || line.trim().is_empty() {
-        return Ok(None);
+        Ok(Some(vec))
     }
-
-    let line: Line = Line::from_str(app, line).await?;
-    Ok(Some(line))
 }