diff --git a/src/main.rs b/src/main.rs index c35928d..fbb1747 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,11 @@ impl Display for Error { f.write_str(self.details.to_string().as_str()) } } +impl From for Error { + fn from(details: String) -> Self { + Self { details } + } +} impl From for Error { fn from(value: std::io::Error) -> Self { Self { @@ -51,9 +56,9 @@ fn main() -> Result<()> { let subscriptions = "subscriptions.txt"; let history = "downloaded.txt"; - for channel_url in lines_from(subscriptions)? { - let channel_url = channel_url?; - let feed_url = get_feed_url(channel_url)?; + for channel_name in lines_from(subscriptions)? { + let channel_name = channel_name?; + let feed_url = get_feed_url(channel_name)?; for entry in get_feed(feed_url)?.entries() { if let Some(link) = get_link(entry) { if !is_already_downloaded(&link, history)? { @@ -68,7 +73,13 @@ fn main() -> Result<()> { Ok(()) } -fn get_feed_url(channel_url: String) -> Result { +fn get_feed_url(channel_name: String) -> 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!("https://www.youtube.com/{}", 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())