regex date checking

This commit is contained in:
Simon
2025-11-15 12:41:05 +00:00
parent 85c270b906
commit 36e549b176
2 changed files with 10 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ scraper = "0.24.0"
once_cell = "1.21.3"
rustc-hash = "2.1.1"
async-trait = "0.1"
regex = "1.12.2"
[lints.rust]
unexpected_cfgs = "allow"

View File

@@ -10,6 +10,7 @@ use error_chain::error_chain;
use htmlentity::entity::{ICodedDataTrait, decode};
use std::sync::{Arc, RwLock};
use std::vec;
use regex::Regex;
error_chain! {
foreign_links {
@@ -18,6 +19,12 @@ error_chain! {
}
}
fn is_valid_date(s: &str) -> bool {
// Regex: strict yyyy-mm-dd (no validation of real calendar dates, just format)
let re = Regex::new(r"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$").unwrap();
re.is_match(s)
}
#[derive(Debug, Clone)]
pub struct XxdbxProvider {
url: String,
@@ -124,6 +131,8 @@ impl XxdbxProvider {
search_type = "channels";
} else if self.stars.read().unwrap().iter().map(|s|s.to_ascii_lowercase()).collect::<Vec<String>>().contains(&search_string.to_ascii_lowercase()) {
search_type = "stars";
} else if is_valid_date(&search_string){
search_type = "dates";
}
let video_url = format!(