aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.rs22
-rw-r--r--src/utils.rs11
2 files changed, 24 insertions, 9 deletions
diff --git a/src/actions.rs b/src/actions.rs
index b808ecc..15d19a4 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -2,8 +2,8 @@ use regex::Regex;
use reqwest;
use rss::Channel;
use std::fs::{DirBuilder, File};
-use std::io::{Read, Write};
-use std::process::Command;
+use std::io::{self, Read, Write};
+use std::process::{Command, ExitStatus};
use structs::*;
use utils::*;
@@ -101,18 +101,28 @@ pub fn play_episode(state: &State, p_search: &str, ep_num_string: &str) {
path.push(podcast.title());
path.push(filename);
if path.exists() {
- launch_mpv(path.to_str().unwrap());
+ if let Err(err) = launch_mpv(path.to_str().unwrap()) {
+ handle_launch_mpv_error(err);
+ }
} else {
- launch_mpv(episode.url().unwrap());
+ if let Err(err) = launch_mpv(episode.url().unwrap()) {
+ handle_launch_mpv_error(err);
+ }
}
return;
}
}
}
-fn launch_mpv(url: &str) {
+fn launch_mpv(url: &str) -> io::Result<ExitStatus> {
Command::new("mpv")
.args(&["--audio-display=no", url])
.status()
- .expect("failed to execute process");
+}
+
+fn handle_launch_mpv_error(err: io::Error) {
+ match err.kind() {
+ io::ErrorKind::NotFound => eprintln!("mpv not found in PATH, is it installed?"),
+ _ => eprintln!("Error: {}", err),
+ }
}
diff --git a/src/utils.rs b/src/utils.rs
index ffe691e..e602932 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -28,7 +28,12 @@ pub fn already_downloaded(dir: &str) -> BTreeSet<String> {
}
pub fn get_podcast_dir() -> PathBuf {
- let mut path = env::home_dir().unwrap();
- path.push("Podcasts");
- path
+ match env::var_os("PODCAST") {
+ Some(val) => PathBuf::from(val),
+ None => {
+ let mut path = env::home_dir().unwrap();
+ path.push("Podcasts");
+ path
+ }
+ }
}