From 50da08851898035eab15f681a1d146d35153b89d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 25 Jul 2023 19:36:56 +0100 Subject: [PATCH] feed::find uses fetch::get --- src/feed/find.rs | 6 ++++-- src/feed/mod.rs | 4 +++- src/fetch.rs | 8 ++++++++ src/lib.rs | 2 +- src/main.rs | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/feed/find.rs b/src/feed/find.rs index 3c0203e..c6ba1ba 100644 --- a/src/feed/find.rs +++ b/src/feed/find.rs @@ -1,13 +1,15 @@ use crate::prelude::*; -pub fn find(site: &str, channel_name: &str) -> Result { +use crate::fetch::FetchEnv; + +pub fn find(site: &str, channel_name: &str, e: &FetchEnv) -> Result { if let Some(channel_prefix) = channel_name.chars().next() { if channel_prefix != '@' { return Err(format!("Channel Name must begin with an '@': {}", channel_name).into()); } } let channel_url = format!("{}{}", site, channel_name); - let response = reqwest::blocking::get(channel_url)?; + let response = (e.get)(&channel_url)?; let rss_url = scraper::Html::parse_document(&response.text()?) .select(&scraper::Selector::parse("link[title='RSS']").unwrap()) .next() diff --git a/src/feed/mod.rs b/src/feed/mod.rs index f06df54..24ee1c9 100644 --- a/src/feed/mod.rs +++ b/src/feed/mod.rs @@ -1,5 +1,7 @@ use crate::prelude::*; +use crate::FetchEnv; + mod find; mod get; @@ -13,5 +15,5 @@ pub struct FeedEnv { pub get: FeedGet, } -pub type FeedFind = fn(&str, &str) -> Result; +pub type FeedFind = fn(&str, &str, &FetchEnv) -> Result; pub type FeedGet = fn(&str) -> Result; diff --git a/src/fetch.rs b/src/fetch.rs index d7f836e..a1aaeac 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -5,9 +5,11 @@ use std::process::Command; pub struct FetchEnv { pub download: FetchDownload, + pub get: FetchGet, } pub type FetchDownload = fn(&Link) -> Result<()>; +pub type FetchGet = fn(&str) -> Result; pub fn download(link: &Link) -> Result<()> { let cmd = "yt-dlp"; @@ -24,3 +26,9 @@ pub fn download(link: &Link) -> Result<()> { } Ok(()) } + +pub type Response = reqwest::blocking::Response; + +pub fn get(url: &str) -> Result { + Ok(reqwest::blocking::get(url)?) +} diff --git a/src/lib.rs b/src/lib.rs index ecaae86..8718f1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ pub struct Env { pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> { for channel_name in subscriptions::lines_from(subscriptions)? { println!("Channel: {}", channel_name); - let feed_url = (e.feed.find)(site, &channel_name)?; + let feed_url = (e.feed.find)(site, &channel_name, &e.fetch)?; for entry in (e.feed.get)(&feed_url)?.entries() { if let Some(link) = entry.links().get(0).cloned() { if !(e.history.find)(&link, history)? { diff --git a/src/main.rs b/src/main.rs index 41e7d98..c97df09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ fn main() -> Result<()> { }, fetch: FetchEnv { download: podal::fetch::download, + get: podal::fetch::get, }, }, )?;