i5-add-tests (part 3) #9
5 changed files with 17 additions and 4 deletions
|
@ -1,13 +1,15 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub fn find(site: &str, channel_name: &str) -> Result<String> {
|
||||
use crate::fetch::FetchEnv;
|
||||
|
||||
pub fn find(site: &str, channel_name: &str, e: &FetchEnv) -> 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());
|
||||
}
|
||||
}
|
||||
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()
|
||||
|
|
|
@ -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<String>;
|
||||
pub type FeedFind = fn(&str, &str, &FetchEnv) -> Result<String>;
|
||||
pub type FeedGet = fn(&str) -> Result<Feed>;
|
||||
|
|
|
@ -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<Response>;
|
||||
|
||||
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<Response> {
|
||||
Ok(reqwest::blocking::get(url)?)
|
||||
}
|
||||
|
|
|
@ -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)? {
|
||||
|
|
|
@ -24,6 +24,7 @@ fn main() -> Result<()> {
|
|||
},
|
||||
fetch: FetchEnv {
|
||||
download: podal::fetch::download,
|
||||
get: podal::fetch::get,
|
||||
},
|
||||
},
|
||||
)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue