From 0fa2931a6474c0295fdcbc92477e30120be53e1a Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Sun, 28 Aug 2022 01:32:17 +0200 Subject: [PATCH] Add fix for rule DashInTitle --- src/rules/has_dash_in_title.rs | 18 ++++++++++++++++-- src/rules/mod.rs | 4 ++-- src/utils/constructors.rs | 8 +++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/rules/has_dash_in_title.rs b/src/rules/has_dash_in_title.rs index 7a59f7b..72ca120 100644 --- a/src/rules/has_dash_in_title.rs +++ b/src/rules/has_dash_in_title.rs @@ -1,6 +1,7 @@ use regex::Captures; use eyre::Result; use super::*; +use crate::utils::constructors::episode_name; pub struct DashInTitle {} impl Rule for DashInTitle { @@ -14,7 +15,20 @@ impl Rule for DashInTitle { return None } - fn fix(_filename: &str, _captures: &Captures) -> Result { - return Ok(FixStatus::NotImplemented) + fn fix(_filename: &str, captures: &Captures) -> Result { + let ep_name = match captures.name("name") { + Some(ep) => Some(ep.as_str().to_string()), + None => None + }; + + let name = episode_name( + captures.name("title").unwrap().as_str().to_string(), + captures.name("season").unwrap().as_str().to_string(), + captures.name("episode").unwrap().as_str().to_string(), + ep_name, + captures.name("ext").unwrap().as_str().to_string() + ); + + return Ok(FixStatus::Fixed(name)) } } \ No newline at end of file diff --git a/src/rules/mod.rs b/src/rules/mod.rs index f59e2bb..1dfad95 100644 --- a/src/rules/mod.rs +++ b/src/rules/mod.rs @@ -37,9 +37,9 @@ pub enum ComplianceStatus { } pub enum FixStatus { - // Fixed, + Fixed(String), NotImplemented, - // NotFixable + NotFixable } pub trait Rule { diff --git a/src/utils/constructors.rs b/src/utils/constructors.rs index 5cf92c1..d149942 100644 --- a/src/utils/constructors.rs +++ b/src/utils/constructors.rs @@ -1,4 +1,6 @@ -#[allow(dead_code)] -pub fn episode_name(title: String, season: String, episode: String, name: String, format: String) -> String { - format!("${title} S${season}E${episode} - ${name}.${format}") +pub fn episode_name(title: String, season: String, episode: String, name: Option, format: String) -> String { + match name { + Some(n) => format!("{} S{}E{} - {}.{}", title, season, episode, n, format), + None => format!("{} S{}E{}.{}", title, season, episode, format), + } }