subscriptions is just the channel name (with @ prefix)

This commit is contained in:
Paul Campbell 2023-07-24 07:35:55 +01:00
parent e18c0f8bea
commit 1896a57b93

View file

@ -16,6 +16,11 @@ impl Display for Error {
f.write_str(self.details.to_string().as_str()) f.write_str(self.details.to_string().as_str())
} }
} }
impl From<String> for Error {
fn from(details: String) -> Self {
Self { details }
}
}
impl From<std::io::Error> for Error { impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self { fn from(value: std::io::Error) -> Self {
Self { Self {
@ -51,9 +56,9 @@ fn main() -> Result<()> {
let subscriptions = "subscriptions.txt"; let subscriptions = "subscriptions.txt";
let history = "downloaded.txt"; let history = "downloaded.txt";
for channel_url in lines_from(subscriptions)? { for channel_name in lines_from(subscriptions)? {
let channel_url = channel_url?; let channel_name = channel_name?;
let feed_url = get_feed_url(channel_url)?; let feed_url = get_feed_url(channel_name)?;
for entry in get_feed(feed_url)?.entries() { for entry in get_feed(feed_url)?.entries() {
if let Some(link) = get_link(entry) { if let Some(link) = get_link(entry) {
if !is_already_downloaded(&link, history)? { if !is_already_downloaded(&link, history)? {
@ -68,7 +73,13 @@ fn main() -> Result<()> {
Ok(()) Ok(())
} }
fn get_feed_url(channel_url: String) -> Result<String> { fn get_feed_url(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 response = reqwest::blocking::get(channel_url)?; let response = reqwest::blocking::get(channel_url)?;
let rss_url = scraper::Html::parse_document(&response.text()?) let rss_url = scraper::Html::parse_document(&response.text()?)
.select(&scraper::Selector::parse("link[title='RSS']").unwrap()) .select(&scraper::Selector::parse("link[title='RSS']").unwrap())