diff options
| author | Nathan Jaremko | 2017-12-04 15:44:03 -0500 |
|---|---|---|
| committer | Nathan Jaremko | 2017-12-04 15:44:03 -0500 |
| commit | 2e8a59ebe8f076811d66072ec410320d7df1fd2e (patch) | |
| tree | 7bbf79e955a19f6a9921318d95ebb4909c47790a | |
| parent | e31a2c59a209b0333dddd6e446e777c2372e68ca (diff) | |
| download | podcast-2e8a59ebe8f076811d66072ec410320d7df1fd2e.tar.bz2 | |
Version 0.4.4
| -rw-r--r-- | CHANGELOG | 13 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/actions.rs | 58 | ||||
| -rw-r--r-- | src/main.rs | 15 | ||||
| -rw-r--r-- | src/structs.rs | 35 | ||||
| -rw-r--r-- | src/utils.rs | 4 |
6 files changed, 94 insertions, 33 deletions
@@ -1,3 +1,8 @@ +0.4.4 +- Add ability to play latest episode by omitting episode number +- Fix update check working correctly +- Fix download still being case-sensitive + 0.4.3 - Display correct version in help screen @@ -8,10 +13,10 @@ - Whoops, never actually published this... 0.4.0 -- Update all dependencies to their latest respective versions -- Add check for updates functionality -- Add ability to unsubscribe from podcasts - Add ability to print zsh shell completion +- Add ability to unsubscribe from podcasts +- Add check for updates functionality - Ignore case when checking podcast titles +- Update all dependencies to their latest respective versions +- rename list -> ls - rename update -> refresh -- rename list -> ls
\ No newline at end of file @@ -1,6 +1,6 @@ [package] name = "podcast" -version = "0.4.3" +version = "0.4.4" authors = ["njaremko <njaremko@gmail.com>"] description = "A command line podcast player" license = "GPL-3.0" diff --git a/src/actions.rs b/src/actions.rs index 108d3e9..76841bb 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -1,13 +1,15 @@ -use rayon::prelude::*; -use regex::Regex; -use reqwest; -use rss::Channel; +use structs::*; +use utils::*; + use std::collections::HashSet; use std::fs::{self, DirBuilder, File}; use std::io::{self, BufReader, Read, Write}; use std::process::Command; -use structs::*; -use utils::*; + +use rayon::prelude::*; +use regex::Regex; +use reqwest; +use rss::Channel; use toml; pub fn list_episodes(search: &str) { @@ -123,7 +125,7 @@ pub fn download_range(state: &State, p_search: &str, e_search: &str) { } pub fn download_episode(state: &State, p_search: &str, e_search: &str) { - let re_pod = Regex::new(p_search).unwrap(); + let re_pod = Regex::new(&format!("(?i){}", &p_search)).expect("Failed to parse regex"); let ep_num = e_search.parse::<usize>().unwrap(); for subscription in &state.subscriptions { @@ -156,6 +158,46 @@ pub fn download_all(state: &State, p_search: &str) { } } +pub fn play_latest(state: &State, p_search: &str) { + let re_pod = Regex::new(&format!("(?i){}", &p_search)).expect("Failed to parse regex"); + let mut path = 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; + } + for subscription in &state.subscriptions { + if re_pod.is_match(&subscription.title) { + let mut filename = subscription.title.clone(); + filename.push_str(".xml"); + path.push(filename); + + let mut 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 episode = episodes[0].clone(); + + filename = String::from(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().unwrap()); + } else { + launch_player(episode.url().unwrap()); + } + return; + } + } +} + pub fn play_episode(state: &State, p_search: &str, ep_num_string: &str) { let re_pod = Regex::new(&format!("(?i){}", &p_search)).expect("Failed to parse regex"); let ep_num = ep_num_string.parse::<usize>().unwrap(); @@ -210,7 +252,7 @@ pub fn check_for_update(version: &str) { Ok(config) => { let latest = config["package"]["version"].as_str().unwrap(); if version != latest { - println!("New version avaliable: {}", latest); + println!("New version avaliable: {} -> {}", version, latest); } } Err(err) => eprintln!("{}", err), diff --git a/src/main.rs b/src/main.rs index d957df4..5dab9b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,12 @@ mod structs; mod utils; use actions::*; -use clap::{App, Arg, SubCommand}; -use structs::*; use utils::*; +use structs::*; -const VERSION: &str = "0.4.3"; +use clap::{App, Arg, SubCommand}; + +const VERSION: &str = "0.4.4"; fn main() { if let Err(err) = create_directories() { @@ -70,7 +71,7 @@ fn main() { .arg( Arg::with_name("EPISODE") .help("Episode index") - .required(true) + .required(false) .index(2), ), ) @@ -134,8 +135,10 @@ fn main() { Some("play") => { let play_matches = matches.subcommand_matches("play").unwrap(); let podcast = play_matches.value_of("PODCAST").unwrap(); - let episode = play_matches.value_of("EPISODE").unwrap(); - play_episode(&state, podcast, episode); + match play_matches.value_of("EPISODE") { + Some(episode) => play_episode(&state, podcast, episode), + None => play_latest(&state, podcast), + } } Some("subscribe") => state.subscribe( matches diff --git a/src/structs.rs b/src/structs.rs index e9b8c28..97c30c2 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,13 +1,15 @@ use actions::*; +use utils::*; + +use std::collections::BTreeSet; +use std::fs::{self, remove_dir_all, remove_file, DirBuilder, File}; +use std::io::{self, BufReader, Read, Write}; + use chrono::prelude::*; use rayon::prelude::*; use reqwest; use rss::{self, Channel, Item}; use serde_json; -use std::collections::BTreeSet; -use std::fs::{self, remove_dir_all, remove_file, DirBuilder, File}; -use std::io::{self, BufReader, Read, Write}; -use utils::*; use yaml_rust::YamlLoader; pub struct Config { @@ -84,10 +86,11 @@ impl State { subscriptions: match serde_json::from_value(v["subscriptions"].clone()) { Ok(val) => val, Err(_) => serde_json::from_value(v["subs"].clone()).unwrap(), - }, + }, } } }; + state.version = String::from(version); // Check if a day has passed (86400 seconds) since last launch if state .last_run_time @@ -98,6 +101,9 @@ impl State { check_for_update(&state.version); } state.last_run_time = Utc::now(); + if let Err(err) = state.save() { + eprintln!("{}", err); + } Ok(state) } else { Ok(State { @@ -290,13 +296,18 @@ impl Episode { let mut filename = String::from(title); filename.push_str(self.extension().unwrap()); path.push(filename); - println!("Downloading: {}", path.to_str().unwrap()); - let mut file = File::create(&path)?; - let mut resp = reqwest::get(url).unwrap(); - let mut content: Vec<u8> = Vec::new(); - resp.read_to_end(&mut content)?; - file.write_all(&content)?; - return Ok(()); + if !path.exists() { + println!("Downloading: {}", path.to_str().unwrap()); + let mut file = File::create(&path)?; + let mut resp = reqwest::get(url).unwrap(); + let mut content: Vec<u8> = Vec::new(); + resp.read_to_end(&mut content)?; + file.write_all(&content)?; + return Ok(()); + } else { + println!("File already exists: {}", path.to_str().unwrap()); + return Ok(()); + } } } Ok(()) diff --git a/src/utils.rs b/src/utils.rs index ab66574..a12a73f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,9 +1,9 @@ use std::collections::HashSet; use std::env; -use std::num::ParseIntError; -use std::path::PathBuf; use std::fs::{self, DirBuilder}; use std::io; +use std::num::ParseIntError; +use std::path::PathBuf; pub fn trim_extension(filename: &str) -> Option<String> { let name = String::from(filename); |
