Add episode marker rule
This commit is contained in:
parent
43ceb4c52e
commit
944fc385ad
3 changed files with 61 additions and 1 deletions
|
@ -102,6 +102,10 @@ fn lint_file_name(file: &DirEntry, filename: &str) -> ComplianceStatus {
|
||||||
|
|
||||||
let captures = captures.unwrap();
|
let captures = captures.unwrap();
|
||||||
|
|
||||||
|
if let Some(reason) = EpisodeMarker::check(filename, &captures) {
|
||||||
|
return ComplianceStatus::NonCompliant(reason);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(reason) = HasEpisodeName::check(filename, &captures) {
|
if let Some(reason) = HasEpisodeName::check(filename, &captures) {
|
||||||
return ComplianceStatus::NonCompliant(reason);
|
return ComplianceStatus::NonCompliant(reason);
|
||||||
}
|
}
|
||||||
|
|
52
src/rules/episode_marker.rs
Normal file
52
src/rules/episode_marker.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
use regex::Captures;
|
||||||
|
use eyre::Result;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub struct EpisodeMarker {}
|
||||||
|
impl Rule for EpisodeMarker {
|
||||||
|
fn check(_filename: &str, captures: &Captures) -> Option<NonCompliantReason> {
|
||||||
|
match captures.name("seasonPrefix") {
|
||||||
|
Some(marker) => {
|
||||||
|
if marker.as_str() != "S" {
|
||||||
|
return Some(NonCompliantReason::InvalidEpisodeMarker("Season Prefix must be 'S'".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Season Prefix found".to_string())),
|
||||||
|
}
|
||||||
|
|
||||||
|
match captures.name("episodePrefix") {
|
||||||
|
Some(marker) => {
|
||||||
|
if marker.as_str() != "E" {
|
||||||
|
return Some(NonCompliantReason::InvalidEpisodeMarker("Episode Prefix must be 'E'".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Episode Prefix found".to_string())),
|
||||||
|
}
|
||||||
|
|
||||||
|
match captures.name("season") {
|
||||||
|
Some(marker) => {
|
||||||
|
let str = marker.as_str();
|
||||||
|
if str.len() != 2 && str.len() != 3 {
|
||||||
|
return Some(NonCompliantReason::InvalidEpisodeMarker("Season should be annotated with either 2 or 3 digits".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Season digits found".to_string())),
|
||||||
|
}
|
||||||
|
|
||||||
|
match captures.name("episode") {
|
||||||
|
Some(marker) => {
|
||||||
|
let str = marker.as_str();
|
||||||
|
if str.len() != 2 && str.len() != 3 {
|
||||||
|
return Some(NonCompliantReason::InvalidEpisodeMarker("Episode should be annotated with either 2 or 3 digits".to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Episode digits found".to_string())),
|
||||||
|
}
|
||||||
|
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fix(_filename: &str, _captures: &Captures) -> Result<FixStatus> {
|
||||||
|
return Ok(FixStatus::NotImplemented)
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,11 +2,13 @@ use std::fmt::{Display, Formatter};
|
||||||
use regex::Captures;
|
use regex::Captures;
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
|
||||||
|
mod episode_marker;
|
||||||
mod has_fluff;
|
mod has_fluff;
|
||||||
mod has_dash_in_title;
|
mod has_dash_in_title;
|
||||||
mod has_episode_name;
|
mod has_episode_name;
|
||||||
mod missing_separator;
|
mod missing_separator;
|
||||||
|
|
||||||
|
pub use episode_marker::EpisodeMarker;
|
||||||
pub use has_fluff::HasFluff;
|
pub use has_fluff::HasFluff;
|
||||||
pub use has_episode_name::HasEpisodeName;
|
pub use has_episode_name::HasEpisodeName;
|
||||||
pub use has_dash_in_title::DashInTitle;
|
pub use has_dash_in_title::DashInTitle;
|
||||||
|
@ -16,7 +18,8 @@ pub enum NonCompliantReason {
|
||||||
DashInTitle,
|
DashInTitle,
|
||||||
MissingName,
|
MissingName,
|
||||||
HasFluff,
|
HasFluff,
|
||||||
MissingNameSeparator
|
MissingNameSeparator,
|
||||||
|
InvalidEpisodeMarker(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for NonCompliantReason {
|
impl Display for NonCompliantReason {
|
||||||
|
@ -26,6 +29,7 @@ impl Display for NonCompliantReason {
|
||||||
NonCompliantReason::MissingName => write!(f, "Missing episode name"),
|
NonCompliantReason::MissingName => write!(f, "Missing episode name"),
|
||||||
NonCompliantReason::HasFluff => write!(f, "Has fluff"),
|
NonCompliantReason::HasFluff => write!(f, "Has fluff"),
|
||||||
NonCompliantReason::MissingNameSeparator => write!(f, "Missing episode name separator"),
|
NonCompliantReason::MissingNameSeparator => write!(f, "Missing episode name separator"),
|
||||||
|
NonCompliantReason::InvalidEpisodeMarker(r) => write!(f, "Episode marker must be of format S00E00 - {}", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue