From 90eef9a188f534e4bf9669811f16af3a36c8b600 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 9 Oct 2016 16:56:35 +0200 Subject: fixierung diff --git a/src/series.rs b/src/series.rs index 3037e6a..eba41be 100644 --- a/src/series.rs +++ b/src/series.rs @@ -12,7 +12,7 @@ use std::collections::HashMap; #[derive(Debug, Serialize)] pub struct Names { pub english: String, - pub aliases: String, + pub aliases: Vec, pub romaji: String, pub furigana: String, pub japanese: String, @@ -22,13 +22,14 @@ pub struct Names { pub struct Series { pub name: Names, pub tags: Vec, + pub image: String, } impl Names { pub fn new() -> Self { Names { english: String::new(), - aliases: String::new(), + aliases: vec![], romaji: String::new(), furigana: String::new(), japanese: String::new(), @@ -36,11 +37,21 @@ impl Names { } } +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(), } } @@ -60,11 +71,16 @@ impl Series { { 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(); + 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(); } } } @@ -73,6 +89,7 @@ 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.*?