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: Vec, pub romaji: String, pub furigana: String, pub japanese: String, } #[derive(Debug, Serialize)] pub struct Series { pub name: Names, pub tags: Vec, pub image: String, } impl Names { pub fn new() -> Self { Names { english: String::new(), aliases: vec![], romaji: String::new(), furigana: String::new(), japanese: String::new(), } } } fn remove_ahref(s: &str) -> String { let re = Regex::new(r#"(?i)(.*)"#).unwrap(); for cap in re.captures_iter(s) { return cap.at(1).unwrap().to_string(); } s.into() } impl Series { pub fn new() -> Self { Series { name: Names::new(), tags: vec![], image: String::new(), } } 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 = remove_ahref(&name.data["english".into()]); self.name.aliases = remove_ahref(&name.data["aliases".into()]).split(", ").map(|v| v.to_string()).collect(); if self.name.aliases[0] == "" { self.name.aliases.remove(0); } self.name.romaji = remove_ahref(&name.data["romaji".into()]); self.name.furigana = remove_ahref(&name.data["furigana".into()]); self.name.japanese = remove_ahref(&name.data["japanese".into()]); self.image = (§ions["image".into()] as &Section).data["small".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.*?(.*?)(.*?)(.*?).*?besttable.*?