diff --git a/src/google_arts_and_culture/tile_info.rs b/src/google_arts_and_culture/tile_info.rs index f31098b..ccd6c9c 100644 --- a/src/google_arts_and_culture/tile_info.rs +++ b/src/google_arts_and_culture/tile_info.rs @@ -39,6 +39,27 @@ impl PageInfo { } } +fn get_name_from_gap_html(html: &str) -> String { + let name = Regex::new(r#"

([^<]+)

([^"]+) ([^"]+)([^<]+)

"#) + .unwrap() + .captures(html) + .map(|c| format!("{}, {}; {}; {}", + &(c[3]), + &(c[2]), + &(c[1]), + &(c[4]))); + + if let Some(result) = name { + return result + } + + Regex::new(r#""name":"([^"]+)"#) + .unwrap() + .captures(html) + .map(|c| (c[1]).to_string()) + .unwrap_or_else(||"Google Arts and Culture Image".into()) +} + impl FromStr for PageInfo { type Err = PageParseError; @@ -51,11 +72,7 @@ impl FromStr for PageInfo { .get(2) .map_or_else(Default::default, |s| s.as_str().into()); - let name = Regex::new(r#""name":"([^"]+)"#) - .unwrap() - .captures(s) - .map(|c| c[1].to_string()) - .unwrap_or_else(|| "Google Arts and culture image".into()); + let name = get_name_from_gap_html(s); Ok(PageInfo { base_url,