extract site as a parameter

This commit is contained in:
Paul Campbell 2023-07-24 07:40:20 +01:00
parent 2cd5b20840
commit 2c953b5997

View file

@ -55,10 +55,11 @@ fn main() -> Result<()> {
println!("Podal");
let subscriptions = "subscriptions.txt";
let history = "downloaded.txt";
let site = "https://www.youtube.com/";
for channel_name in lines_from(subscriptions)? {
let channel_name = channel_name?;
let feed_url = get_feed_url(channel_name)?;
let feed_url = get_feed_url(site, channel_name)?;
for entry in get_feed(feed_url)?.entries() {
if let Some(link) = get_link(entry) {
if !is_already_downloaded(&link, history)? {
@ -73,13 +74,13 @@ fn main() -> Result<()> {
Ok(())
}
fn get_feed_url(channel_name: String) -> Result<String> {
fn get_feed_url(site: &str, channel_name: String) -> 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!("https://www.youtube.com/{}", channel_name);
let channel_url = format!("{}{}", site, channel_name);
let response = reqwest::blocking::get(channel_url)?;
let rss_url = scraper::Html::parse_document(&response.text()?)
.select(&scraper::Selector::parse("link[title='RSS']").unwrap())