diff options
| author | njaremko | 2017-07-17 21:50:26 -0400 |
|---|---|---|
| committer | njaremko | 2017-07-17 21:50:26 -0400 |
| commit | cd83d6ecaf7d9025c3db452268cf246ae4c4aaa0 (patch) | |
| tree | 77be33df40e823b08d234b8a7d09245049b35553 /src/actions.rs | |
| parent | c981cf824f5d75423f88437361d915cb1233eb3a (diff) | |
| download | podcast-cd83d6ecaf7d9025c3db452268cf246ae4c4aaa0.tar.bz2 | |
Fix play functionality
Diffstat (limited to 'src/actions.rs')
| -rw-r--r-- | src/actions.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/actions.rs b/src/actions.rs index a228b74..b8074b1 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,6 +1,7 @@ use regex::Regex; use structs::*; use std::process::{Command, Stdio}; +use utils::*; pub fn list_episodes(state: State, search: &str) { let re = Regex::new(&search).unwrap(); @@ -54,15 +55,24 @@ pub fn download_all(state: State, p_search: &str) { } } -pub fn stream_episode(state: State, p_search: &str, e_search: &str) { +pub fn play_episode(state: State, p_search: &str, ep_num_string: &str) { let re_pod = Regex::new(&p_search).unwrap(); - let ep_num = e_search.parse::<usize>().unwrap(); - + let ep_num = ep_num_string.parse::<usize>().unwrap(); + let mut path = get_podcast_dir(); for subscription in state.subscriptions() { if re_pod.is_match(&subscription.name) { let podcast = Podcast::from_url(&subscription.url).unwrap(); + path.push(podcast.title()); let episodes = podcast.episodes(); - launch_mpv(episodes[episodes.len() - ep_num].download_url().unwrap()); + let episode = episodes[episodes.len() - ep_num].clone(); + + let mut filename = String::from(episode.title().unwrap()); + filename.push_str(episode.download_extension().unwrap()); + path.push(filename); + match path.exists() { + true => launch_mpv(path.to_str().unwrap()), + false => launch_mpv(episode.url().unwrap()), + } } } } @@ -70,8 +80,6 @@ pub fn stream_episode(state: State, p_search: &str, e_search: &str) { fn launch_mpv(url: &str) { Command::new("mpv") .args(&["--audio-display=no", url]) - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .output() + .status() .expect("failed to execute process"); } |
