From 589ef773becbbd3debcd918b3d6d45c7c6481a9a Mon Sep 17 00:00:00 2001 From: 1toldyou <86680163+1toldyou@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:08:12 -0700 Subject: [PATCH] Trim the beginning of output line for newer versions of ytarchive (#38) * trim the beginning of yta output line for all versions * run cargo fmt * wrap the regex for detecting timestamp with lazy_static! --- .gitignore | 3 +++ src/module/recorder.rs | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4a3b37d..68c2dd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ +.idea + /target + config.toml diff --git a/src/module/recorder.rs b/src/module/recorder.rs index adb0a50..ac5f91e 100644 --- a/src/module/recorder.rs +++ b/src/module/recorder.rs @@ -478,10 +478,13 @@ impl YTAStatus { } // New versions of ytarchive prepend a timestamp to the output - let line = if self.version == Some("0.3.2".into()) - && line.len() > 20 - && line.chars().nth(4) == Some('/') - { + // Sample line + // 2024/04/16 16:25:31 + lazy_static! { + static ref TIMESTAMP_RE: Regex = Regex::new(r"^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}") + .expect("Failed to compile regex for detecting yta output timestamp"); + } + let line = if line.len() > 20 && TIMESTAMP_RE.is_match(line) { line[20..].trim() } else { line