aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authorNathan Jaremko2017-12-05 15:26:07 -0500
committerNathan Jaremko2017-12-05 15:26:07 -0500
commit978dbf71f22e3123b2f25154cfbe20a6e207dfe3 (patch)
treec4cc1155775f88e1d829549060f9ebf3fb39989f /src/utils.rs
parent2e8a59ebe8f076811d66072ec410320d7df1fd2e (diff)
downloadpodcast-978dbf71f22e3123b2f25154cfbe20a6e207dfe3.tar.bz2
Improve subscribing default behaviour
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/utils.rs b/src/utils.rs
index a12a73f..789c7da 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,10 +1,13 @@
use std::collections::HashSet;
use std::env;
-use std::fs::{self, DirBuilder};
-use std::io;
+use std::fs::{self, DirBuilder, File};
+use std::io::{self, BufReader, Read, Write};
use std::num::ParseIntError;
use std::path::PathBuf;
+use reqwest;
+use rss::Channel;
+
pub fn trim_extension(filename: &str) -> Option<String> {
let name = String::from(filename);
match name.rfind('.') {
@@ -90,6 +93,22 @@ pub fn get_xml_dir() -> PathBuf {
path
}
+pub fn download_rss_feed(url: &str) -> Result<Channel, String> {
+ let mut path = get_podcast_dir();
+ path.push(".rss");
+ DirBuilder::new().recursive(true).create(&path).unwrap();
+ let mut resp = reqwest::get(url).unwrap();
+ let mut content: Vec<u8> = Vec::new();
+ resp.read_to_end(&mut content).unwrap();
+ let channel = Channel::read_from(BufReader::new(&content[..])).unwrap();
+ let mut filename = String::from(channel.title());
+ filename.push_str(".xml");
+ path.push(filename);
+ let mut file = File::create(&path).unwrap();
+ file.write_all(&content).unwrap();
+ Ok(channel)
+}
+
pub fn parse_download_episodes(e_search: &str) -> Result<Vec<usize>, ParseIntError> {
let input = String::from(e_search);
let mut ranges = Vec::<(usize, usize)>::new();