Skip to content

Commit

Permalink
Merge pull request #198 from vladh/master
Browse files Browse the repository at this point in the history
GAP: improve filename format
  • Loading branch information
lovasoa authored Mar 12, 2023
2 parents 17ecc72 + 8b8b3f3 commit ec8a0ff
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/google_arts_and_culture/tile_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ impl PageInfo {
}
}

fn get_name_from_gap_html(html: &str) -> String {
let name = Regex::new(r#"<h1 class="[^"]+">([^<]+)</h1><h2 class="[^"]+"><span class="[^"]+"><a href="[^"]+">([^"]+) ([^"]+)</a></span><span class="[^"]+">([^<]+)</span></h2>"#)
.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;

Expand All @@ -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,
Expand Down

0 comments on commit ec8a0ff

Please sign in to comment.