aboutsummaryrefslogtreecommitdiff
path: root/src/series.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/series.rs')
-rw-r--r--src/series.rs35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/series.rs b/src/series.rs
index d111fb8..3037e6a 100644
--- a/src/series.rs
+++ b/src/series.rs
@@ -21,12 +21,17 @@ pub struct Names {
21#[derive(Debug, Serialize)] 21#[derive(Debug, Serialize)]
22pub struct Series { 22pub struct Series {
23 pub name: Names, 23 pub name: Names,
24 pub tags: Vec<String>,
24} 25}
25 26
26impl Names { 27impl Names {
27 pub fn new() -> Self { 28 pub fn new() -> Self {
28 Names { 29 Names {
29 String::new(), String::new(), String::new(), String::new(), String::new() 30 english: String::new(),
31 aliases: String::new(),
32 romaji: String::new(),
33 furigana: String::new(),
34 japanese: String::new(),
30 } 35 }
31 } 36 }
32} 37}
@@ -34,30 +39,40 @@ impl Names {
34impl Series { 39impl Series {
35 pub fn new() -> Self { 40 pub fn new() -> Self {
36 Series { 41 Series {
37 name: Names::new() 42 name: Names::new(),
43 tags: vec![],
38 } 44 }
39 } 45 }
40 46
41 pub fn parse(&mut self, buf: &str) { 47 pub fn parse(&mut self, buf: &str) {
42 let mut sections = get_sections(); 48 let mut sections = get_sections();
43 section::process(&buf, &mut sections); 49 section::process(&buf, &mut sections);
44 50
51 let re_genre_tags = Regex::new(r#"(?is)Genre Tags.*?>(.*?)</td>"#).unwrap();
52 let re_genre_tag = Regex::new(r#"[0-9]">(.*?)</A>"#).unwrap();
53
54 for cap in re_genre_tags.captures_iter(&buf) {
55 self.tags = re_genre_tag.captures_iter(cap.at(1).unwrap())
56 .map(|v| v.at(1).unwrap().to_string())
57 .collect();
58 }
59
45 { 60 {
46 let name: &Section = &sections["name".into()]; 61 let name: &Section = &sections["name".into()];
47 62
48 self.name.english = name["english".into()]; 63 self.name.english = name.data["english".into()].to_string();
49 self.name.aliases = name["aliases".into()]; 64 self.name.aliases = name.data["aliases".into()].to_string();
50 self.name.romaji = name["romaji".into()]; 65 self.name.romaji = name.data["romaji".into()].to_string();
51 self.name.furigana = name["furigana".into()]; 66 self.name.furigana = name.data["furigana".into()].to_string();
52 self.name.japanese = name["japanese".into()]; 67 self.name.japanese = name.data["japanese".into()].to_string();
53 } 68 }
54 } 69 }
55} 70}
56 71
57fn get_sections() -> HashMap<String, Section> { 72fn get_sections() -> HashMap<String, Section> {
58 let mut s: HashMap<String, Section> = HashMap::new(); 73 let mut s: HashMap<String, Section> = HashMap::new();
59 74
60 s.insert("name".into(), Section::new("name", r#"(?is)English Title.*?<TD>(.*?)</TD>.*?Aliases.*?<TD>(.*?)?</TD>.*?Romaji Title.*?<TD.*?>(.*?)</TD>.*?Furigana Title.*?<TD.*?>(.*?)</TD>.*?Japanese Title.*?<TD.*?>(.*?)</TD>"#, vec!["english", "aliases", "romaji", "furigana", "japanese"])); 75 s.insert("name".into(), Section::new("name", r#"(?is)English Title.*?<TD>(.*?)<.*?Aliases.*?<TD>(.*?)<.*?Romaji Title.*?<TD.*?>(.*?)</.*?Furigana Title.*?<TD.*?>(.*?)</.*?Japanese Title.*?<TD.*?>(.*?)</"#, vec!["english", "aliases", "romaji", "furigana", "japanese"]));
61 76
62 s 77 s
63} 78}