NUYITHNW2PMOOUBX2ZT3JHSK3MQUFP4W3GEZ5HFJFDOMT56R4QSAC
S3YILTUU7CUF6AOV2OHCCXIR37C6B5LTFW4OHJNHEJNMA7UOFKBAC
FBQOBNZ6JJQXSHYQK7MCFA4U7NBNB47FXED7Y7HPRTOQVXJFIAGAC
XIHPYOWDLQY2MVMVUQPH23O3TBALRG4G2CHSLWSCAYMY5NVJ32WQC
IFBRAMVLQ4Z6BAEMWDIXD2V5HSZK4DHRWYZNB32IBY7ZRTNZJVCQC
FRLZDOAN7A3N623TLAPO66JVWBLBI45AG6P3DMQMDKGEZ2OBPYAAC
L7S4333LAJBFHRBEI5KB27CQJ3VVWSFZ6HOJ4FPFDDNAE4PUH6GAC
O53GR2OQHGRKAVJT2RVPRHYFB54W5LM4DQYT7EYVGKU7HDK5CJJQC
SBPKWZNQF5BWAJ7SZHWVK5BG6DTVJNDYND6UG5PDZCWZ2W4W2HXQC
3YR56Y65UIAL3J7PUXWVJMOOHYZYDIX4V54OT2TJPZ25WQ6MXHCQC
UIMZBURR7KOWSREO4GDH5C2LZDUTEZBKQNYWBYSFGUTRYJ4GKSNQC
JJ4SMY257MAHSJSZH5PJZMLBH3GJX5VKH2ZZSBGWLL7FWP7OA7TQC
6FJACP6KUOZ4HWK4PSS5PFPGDYXZSCAWSKIARWBDGCZTPJWXA62AC
JYSIHNS67XTGAR4HN7ZHWFMGGYSK5IY6J6EHO4YUZOR7UMMWAORQC
}
}
Ok(())
}
pub fn download_episode_by_name(
state: &State,
p_search: &str,
e_search: &str,
download_all: bool,
) -> Result<()> {
let re_pod = Regex::new(&format!("(?i){}", &p_search)).chain_err(|| UNABLE_TO_PARSE_REGEX)?;
for subscription in &state.subscriptions {
if re_pod.is_match(&subscription.title) {
let podcast = Podcast::from_title(&subscription.title)
.chain_err(|| UNABLE_TO_RETRIEVE_PODCAST_BY_TITLE)?;
let episodes = podcast.episodes();
if download_all {
episodes
.iter()
.filter(|ep| {
ep.title()
.unwrap_or_else(|| "".to_string())
.contains(e_search)
})
.for_each(|ep| {
ep.download(podcast.title()).unwrap_or_else(|_| {
println!("Error downloading episode: {}", podcast.title())
});
})
} else {
let filtered_episodes: Vec<&Episode> = episodes
.iter()
.filter(|ep| {
ep.title()
.unwrap_or_else(|| "".to_string())
.contains(e_search)
})
.collect();
if let Some(ep) = filtered_episodes.first() {
ep.download(podcast.title())
.chain_err(|| "unable to download episode")?;
}
}
}
return Ok(());
}
}
Ok(())
}
pub fn play_episode_by_name(state: &State, p_search: &str, ep_string: &str) -> Result<()> {
let re_pod: Regex =
Regex::new(&format!("(?i){}", &p_search)).chain_err(|| UNABLE_TO_PARSE_REGEX)?;
let mut path: PathBuf = get_xml_dir()?;
if let Err(err) = DirBuilder::new().recursive(true).create(&path) {
eprintln!(
"Couldn't create directory: {}\nReason: {}",
path.to_str().unwrap(),
err
);
return Ok(());
}
for subscription in &state.subscriptions {
if re_pod.is_match(&subscription.title) {
let mut filename: String = subscription.title.clone();
filename.push_str(".xml");
path.push(filename);
let mut file: File = File::open(&path).unwrap();
let mut content: Vec<u8> = Vec::new();
file.read_to_end(&mut content).unwrap();
let podcast = Podcast::from(Channel::read_from(content.as_slice()).unwrap());
let episodes = podcast.episodes();
let filtered_episodes: Vec<&Episode> = episodes
.iter()
.filter(|ep| {
ep.title()
.unwrap_or_else(|| "".to_string())
.contains(ep_string)
})
.collect();
if let Some(episode) = filtered_episodes.first() {
filename = episode.title().unwrap();
filename.push_str(episode.extension().unwrap());
path = get_podcast_dir()?;
path.push(podcast.title());
path.push(filename);
if path.exists() {
launch_player(path.to_str().chain_err(|| UNABLE_TO_CONVERT_TO_STR)?)?;
} else {
launch_player(
episode
.url()
.chain_err(|| "unable to retrieve episode url")?,
)?;
}
.arg(Arg::with_name("EPISODE").help("Episode index").index(2)),
.arg(
Arg::with_name("EPISODE")
.required(false)
.help("Episode index")
.index(2),
)
.arg(
Arg::with_name("name")
.short("e")
.long("episode")
.help("Download using episode name instead of number")
.required(false),
)
.arg(
Arg::with_name("all")
.short("a")
.long("all")
.help("Download all matching episodes")
.required(false),
),