diff options
author | jan <jan@ruken.pw> | 2016-10-09 14:56:35 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-09 14:56:35 (UTC) |
commit | 90eef9a188f534e4bf9669811f16af3a36c8b600 (patch) | |
tree | 8dc9e209abf685d0ac4699a1f35cb12f836af72b | |
parent | 6d7a31be9c6fd413d407334c40d02c008b7334ec (diff) |
-rw-r--r-- | src/series.rs | 31 |
1 files changed, 24 insertions, 7 deletions
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; | |||
12 | #[derive(Debug, Serialize)] | 12 | #[derive(Debug, Serialize)] |
13 | pub struct Names { | 13 | pub struct Names { |
14 | pub english: String, | 14 | pub english: String, |
15 | pub aliases: String, | 15 | pub aliases: Vec<String>, |
16 | pub romaji: String, | 16 | pub romaji: String, |
17 | pub furigana: String, | 17 | pub furigana: String, |
18 | pub japanese: String, | 18 | pub japanese: String, |
@@ -22,13 +22,14 @@ pub struct Names { | |||
22 | pub struct Series { | 22 | pub struct Series { |
23 | pub name: Names, | 23 | pub name: Names, |
24 | pub tags: Vec<String>, | 24 | pub tags: Vec<String>, |
25 | pub image: String, | ||
25 | } | 26 | } |
26 | 27 | ||
27 | impl Names { | 28 | impl Names { |
28 | pub fn new() -> Self { | 29 | pub fn new() -> Self { |
29 | Names { | 30 | Names { |
30 | english: String::new(), | 31 | english: String::new(), |
31 | aliases: String::new(), | 32 | aliases: vec![], |
32 | romaji: String::new(), | 33 | romaji: String::new(), |
33 | furigana: String::new(), | 34 | furigana: String::new(), |
34 | japanese: String::new(), | 35 | japanese: String::new(), |
@@ -36,11 +37,21 @@ impl Names { | |||
36 | } | 37 | } |
37 | } | 38 | } |
38 | 39 | ||
40 | fn remove_ahref(s: &str) -> String { | ||
41 | let re = Regex::new(r#"(?i)<A.*?>(.*)"#).unwrap(); | ||
42 | for cap in re.captures_iter(s) { | ||
43 | return cap.at(1).unwrap().to_string(); | ||
44 | } | ||
45 | |||
46 | s.into() | ||
47 | } | ||
48 | |||
39 | impl Series { | 49 | impl Series { |
40 | pub fn new() -> Self { | 50 | pub fn new() -> Self { |
41 | Series { | 51 | Series { |
42 | name: Names::new(), | 52 | name: Names::new(), |
43 | tags: vec![], | 53 | tags: vec![], |
54 | image: String::new(), | ||
44 | } | 55 | } |
45 | } | 56 | } |
46 | 57 | ||
@@ -60,11 +71,16 @@ impl Series { | |||
60 | { | 71 | { |
61 | let name: &Section = §ions["name".into()]; | 72 | let name: &Section = §ions["name".into()]; |
62 | 73 | ||
63 | self.name.english = name.data["english".into()].to_string(); | 74 | self.name.english = remove_ahref(&name.data["english".into()]); |
64 | self.name.aliases = name.data["aliases".into()].to_string(); | 75 | self.name.aliases = remove_ahref(&name.data["aliases".into()]).split(", ").map(|v| v.to_string()).collect(); |
65 | self.name.romaji = name.data["romaji".into()].to_string(); | 76 | if self.name.aliases[0] == "" { |
66 | self.name.furigana = name.data["furigana".into()].to_string(); | 77 | self.name.aliases.remove(0); |
67 | self.name.japanese = name.data["japanese".into()].to_string(); | 78 | } |
79 | self.name.romaji = remove_ahref(&name.data["romaji".into()]); | ||
80 | self.name.furigana = remove_ahref(&name.data["furigana".into()]); | ||
81 | self.name.japanese = remove_ahref(&name.data["japanese".into()]); | ||
82 | |||
83 | self.image = (§ions["image".into()] as &Section).data["small".into()].to_string(); | ||
68 | } | 84 | } |
69 | } | 85 | } |
70 | } | 86 | } |
@@ -73,6 +89,7 @@ fn get_sections() -> HashMap<String, Section> { | |||
73 | let mut s: HashMap<String, Section> = HashMap::new(); | 89 | let mut s: HashMap<String, Section> = HashMap::new(); |
74 | 90 | ||
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"])); | 91 | 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"])); |
92 | s.insert("image".into(), Section::new("image", r#"(?is)</H3>.*?besttable.*?<IMG.*?src="(.*?)""#, vec!["small"])); | ||
76 | 93 | ||
77 | s | 94 | s |
78 | } | 95 | } |