2023-07-25 10:33:41 +01:00
|
|
|
// https://www.phind.com/agent?cache=clke9xk39001cmj085upzho1t
|
|
|
|
|
2023-07-25 10:36:08 +01:00
|
|
|
use std::fs::File;
|
2023-07-25 10:33:41 +01:00
|
|
|
|
2023-07-25 10:50:31 +01:00
|
|
|
use atom_syndication::Link;
|
2023-07-25 10:33:41 +01:00
|
|
|
|
2023-07-25 10:36:08 +01:00
|
|
|
mod errors;
|
2023-07-25 10:46:47 +01:00
|
|
|
mod feed;
|
2023-07-25 10:53:26 +01:00
|
|
|
mod history;
|
2023-07-25 10:46:47 +01:00
|
|
|
pub mod prelude;
|
2023-07-25 10:33:41 +01:00
|
|
|
|
2023-07-25 10:46:47 +01:00
|
|
|
use prelude::*;
|
2023-07-25 10:33:41 +01:00
|
|
|
|
|
|
|
pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
|
|
|
for channel_name in lines_from(subscriptions)? {
|
|
|
|
let channel_name = channel_name?;
|
|
|
|
println!("Channel: {}", channel_name);
|
2023-07-25 10:46:47 +01:00
|
|
|
let feed_url = feed::get_feed_url(site, &channel_name)?;
|
2023-07-25 10:50:00 +01:00
|
|
|
for entry in feed::get_feed(feed_url)?.entries() {
|
2023-07-25 10:50:31 +01:00
|
|
|
if let Some(link) = entry.links().get(0).cloned() {
|
2023-07-25 10:53:26 +01:00
|
|
|
if !history::is_already_downloaded(&link, history)? {
|
2023-07-25 10:33:41 +01:00
|
|
|
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
|
|
|
download_audio(&link)?;
|
2023-07-25 10:55:02 +01:00
|
|
|
history::mark_as_downloaded(&link, history)?;
|
2023-07-25 10:33:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
// read list of rss feed URLs from file 'feeds.txt'
|
|
|
|
fn lines_from(file_name: &str) -> Result<std::io::Lines<std::io::BufReader<std::fs::File>>> {
|
|
|
|
use std::io::{BufRead, BufReader};
|
|
|
|
|
|
|
|
let file = File::open(file_name)?;
|
|
|
|
let reader = BufReader::new(file);
|
|
|
|
Ok(reader.lines())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn download_audio(link: &Link) -> Result<()> {
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
let cmd = "yt-dlp";
|
|
|
|
// println!("{} --extract-audio --audio-format mp3 {}", cmd, &link.href);
|
|
|
|
let output = Command::new(cmd)
|
|
|
|
.arg("--extract-audio")
|
|
|
|
.arg("--audio-format")
|
|
|
|
.arg("mp3")
|
|
|
|
.arg(&link.href)
|
|
|
|
.output()?;
|
|
|
|
if !output.stderr.is_empty() {
|
|
|
|
eprintln!("Error: {}", String::from_utf8(output.stderr)?);
|
|
|
|
println!("{}", String::from_utf8(output.stdout)?);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|