use regex::Regex;
mod tests;
pub fn retrieve_audios(word: &str) -> Result<Vec<String>, std::io::Error> {
let url = format!("https://forvo.com/search/{}/", word);
let content = reqwest::get(&url.to_string())
.expect("Could not make request.")
.text()
.expect("Could not read text.");
let mut pronunciations = vec![];
let regex_sequence_pattern = Regex::new(r"(Play\(\w+,')(\w+=*)").unwrap();
for caps in regex_sequence_pattern.captures_iter(content.as_str()) {
let code_sequence = caps.get(2).unwrap().as_str();
pronunciations.push(code_sequence.to_string());
}
Ok(pronunciations)
}