Add fix for rule DashInTitle
This commit is contained in:
parent
c840b080f6
commit
0fa2931a64
3 changed files with 23 additions and 7 deletions
|
@ -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<FixStatus> {
|
||||
return Ok(FixStatus::NotImplemented)
|
||||
fn fix(_filename: &str, captures: &Captures) -> Result<FixStatus> {
|
||||
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))
|
||||
}
|
||||
}
|
|
@ -37,9 +37,9 @@ pub enum ComplianceStatus {
|
|||
}
|
||||
|
||||
pub enum FixStatus {
|
||||
// Fixed,
|
||||
Fixed(String),
|
||||
NotImplemented,
|
||||
// NotFixable
|
||||
NotFixable
|
||||
}
|
||||
|
||||
pub trait Rule {
|
||||
|
|
|
@ -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<String>, format: String) -> String {
|
||||
match name {
|
||||
Some(n) => format!("{} S{}E{} - {}.{}", title, season, episode, n, format),
|
||||
None => format!("{} S{}E{}.{}", title, season, episode, format),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue