52CTWUQP2WCBMYNGOIOLOVUYWXF3YOJAPJY3WIHIFLIQD2WHIDFQC
None => download::download_all(&state, podcast).await?,
None => match download_matches.value_of("latest") {
Some(num_of_latest) => download::download_latest(&state, podcast, num_of_latest.parse()?).await?,
None => download::download_all(&state, podcast).await?,
}
}
fn find_matching_podcast(state: &State, p_search: &str) -> Result<Option<Podcast>, Error> {
let re_pod = Regex::new(&format!("(?i){}", &p_search))?;
for subscription in &state.subscriptions {
if re_pod.is_match(&subscription.title) {
let podcast = Podcast::from_title(&subscription.title)?;
return Ok(Some(podcast));
}
}
Ok(None)
pub async fn download_latest(state: &State, p_search: &str, latest: usize) -> Result<(), Error> {
if let Some(podcast) = find_matching_podcast(state, p_search)? {
let episodes = podcast.episodes();
let mut d_vec = vec![];
for ep in &episodes[..latest] {
d_vec.push(download(podcast.title().into(), ep.clone()));
}
for c in futures::future::join_all(d_vec).await.iter() {
if let Err(err) = c {
println!("Error: {}", err);
}
}
}
Ok(())
}