aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.rs
diff options
context:
space:
mode:
authornjaremko2017-07-17 19:27:45 -0400
committernjaremko2017-07-17 19:27:45 -0400
commit4e128165278d92b5efae7054355037eadbde1724 (patch)
treea19539fe67af54bd81c7db18da4134af36a9535e /src/actions.rs
parent57b19c651f2193e4331085585e6385b153c4b0ec (diff)
downloadpodcast-4e128165278d92b5efae7054355037eadbde1724.tar.bz2
Add play support
Diffstat (limited to 'src/actions.rs')
-rw-r--r--src/actions.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/actions.rs b/src/actions.rs
index 0f8d337..f126d7f 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -1,5 +1,6 @@
use regex::Regex;
use structs::*;
+use std::process::{Command, Stdio};
pub fn list_episodes(state: State, search: &str) {
let re = Regex::new(&search).unwrap();
@@ -8,8 +9,9 @@ pub fn list_episodes(state: State, search: &str) {
println!("Episodes for {}:", &podcast.name);
match Podcast::from_url(&podcast.url) {
Ok(podcast) => {
- for title in podcast.list_episodes() {
- println!("{}", title)
+ let episodes = podcast.episodes();
+ for (index, episode) in episodes.iter().enumerate() {
+ println!("({}) {}", episodes.len() - index, episode.title().unwrap());
}
}
Err(err) => println!("{}", err),
@@ -24,3 +26,25 @@ pub fn list_subscriptions(state: State) {
println!("{}", podcast.name);
}
}
+
+pub fn stream_episode(state: State, p_search: &str, e_search: &str) {
+ let re_pod = Regex::new(&p_search).unwrap();
+ let ep_num = e_search.parse::<usize>().unwrap();
+
+ for subscription in state.subscriptions() {
+ if re_pod.is_match(&subscription.name) {
+ let podcast = Podcast::from_url(&subscription.url).unwrap();
+ let episodes = podcast.episodes();
+ launch_mpv(episodes[episodes.len() - ep_num].download_url().unwrap());
+ }
+ }
+}
+
+fn launch_mpv(url: &str) {
+ Command::new("mpv")
+ .args(&["--audio-display=no", url])
+ .stdin(Stdio::inherit())
+ .stdout(Stdio::inherit())
+ .output()
+ .expect("failed to execute process");
+}