use super::tags; use super::tags::Tag; use super::dl_list; use super::dl_list::DLListItem; use super::section; use super::section::Section; use super::regex::Regex; use super::tiles; use std::collections::HashMap; #[derive(Debug, Serialize)] pub struct Names { pub english: String, pub aliases: String, pub romaji: String, pub furigana: String, pub japanese: String, } #[derive(Debug, Serialize)] pub struct Series { pub name: Names, pub tags: Vec, } impl Names { pub fn new() -> Self { Names { english: String::new(), aliases: String::new(), romaji: String::new(), furigana: String::new(), japanese: String::new(), } } } impl Series { pub fn new() -> Self { Series { name: Names::new(), tags: vec![], } } pub fn parse(&mut self, buf: &str) { let mut sections = get_sections(); section::process(&buf, &mut sections); let re_genre_tags = Regex::new(r#"(?is)Genre Tags.*?>(.*?)"#).unwrap(); let re_genre_tag = Regex::new(r#"[0-9]">(.*?)"#).unwrap(); for cap in re_genre_tags.captures_iter(&buf) { self.tags = re_genre_tag.captures_iter(cap.at(1).unwrap()) .map(|v| v.at(1).unwrap().to_string()) .collect(); } { let name: &Section = §ions["name".into()]; self.name.english = name.data["english".into()].to_string(); self.name.aliases = name.data["aliases".into()].to_string(); self.name.romaji = name.data["romaji".into()].to_string(); self.name.furigana = name.data["furigana".into()].to_string(); self.name.japanese = name.data["japanese".into()].to_string(); } } } fn get_sections() -> HashMap { let mut s: HashMap = HashMap::new(); s.insert("name".into(), Section::new("name", r#"(?is)English Title.*?(.*?)<.*?Aliases.*?(.*?)<.*?Romaji Title.*?(.*?)(.*?)(.*?)