provide feed find/get functions as parameters from main
This commit is contained in:
parent
e1ea5a81ec
commit
17a92e45e4
5 changed files with 28 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub fn get_feed_url(site: &str, channel_name: &str) -> Result<String> {
|
||||
pub fn find(site: &str, channel_name: &str) -> Result<String> {
|
||||
if let Some(channel_prefix) = channel_name.chars().next() {
|
||||
if channel_prefix != '@' {
|
||||
return Err(format!("Channel Name must begin with an '@': {}", channel_name).into());
|
||||
|
|
|
@ -2,7 +2,7 @@ use atom_syndication::Feed;
|
|||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn get_feed(url: String) -> Result<Feed> {
|
||||
pub fn get(url: &str) -> Result<Feed> {
|
||||
let content = reqwest::blocking::get(url)?.bytes()?;
|
||||
let channel = Feed::read_from(&content[..])?;
|
||||
Ok(channel)
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
mod find;
|
||||
mod get;
|
||||
|
||||
pub use find::get_feed_url;
|
||||
pub use get::get_feed;
|
||||
pub use find::find;
|
||||
pub use get::get;
|
||||
|
||||
type Feed = atom_syndication::Feed;
|
||||
|
||||
pub type FeedFind = fn(&str, &str) -> Result<String>;
|
||||
pub type FeedGet = fn(&str) -> Result<Feed>;
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,5 +1,5 @@
|
|||
mod errors;
|
||||
mod feed;
|
||||
pub mod feed;
|
||||
mod fetch;
|
||||
mod history;
|
||||
pub mod prelude;
|
||||
|
@ -7,12 +7,18 @@ mod subscriptions;
|
|||
|
||||
use prelude::*;
|
||||
|
||||
pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
||||
pub fn run(
|
||||
subscriptions: &str,
|
||||
history: &str,
|
||||
site: &str,
|
||||
feed_find: feed::FeedFind,
|
||||
feed_get: feed::FeedGet,
|
||||
) -> Result<()> {
|
||||
for channel_name in subscriptions::lines_from(subscriptions)? {
|
||||
let channel_name = channel_name?;
|
||||
println!("Channel: {}", channel_name);
|
||||
let feed_url = feed::get_feed_url(site, &channel_name)?;
|
||||
for entry in feed::get_feed(feed_url)?.entries() {
|
||||
let feed_url = feed_find(site, &channel_name)?;
|
||||
for entry in feed_get(&feed_url)?.entries() {
|
||||
if let Some(link) = entry.links().get(0).cloned() {
|
||||
if !history::is_already_downloaded(&link, history)? {
|
||||
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
||||
|
|
|
@ -6,7 +6,13 @@ fn main() -> Result<()> {
|
|||
let history = "downloaded.txt";
|
||||
let site = "https://www.youtube.com/";
|
||||
|
||||
podal::run(subscriptions, history, site)?;
|
||||
podal::run(
|
||||
subscriptions,
|
||||
history,
|
||||
site,
|
||||
podal::feed::find,
|
||||
podal::feed::get,
|
||||
)?;
|
||||
|
||||
println!("Done");
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Reference in a new issue