extract fetch
This commit is contained in:
parent
13600e0927
commit
e1ea5a81ec
2 changed files with 23 additions and 23 deletions
21
src/fetch.rs
Normal file
21
src/fetch.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
use atom_syndication::Link;
|
||||||
|
|
||||||
|
pub 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(())
|
||||||
|
}
|
25
src/lib.rs
25
src/lib.rs
|
@ -1,9 +1,6 @@
|
||||||
// https://www.phind.com/agent?cache=clke9xk39001cmj085upzho1t
|
|
||||||
|
|
||||||
use atom_syndication::Link;
|
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
mod feed;
|
mod feed;
|
||||||
|
mod fetch;
|
||||||
mod history;
|
mod history;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod subscriptions;
|
mod subscriptions;
|
||||||
|
@ -19,7 +16,7 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
||||||
if let Some(link) = entry.links().get(0).cloned() {
|
if let Some(link) = entry.links().get(0).cloned() {
|
||||||
if !history::is_already_downloaded(&link, history)? {
|
if !history::is_already_downloaded(&link, history)? {
|
||||||
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
|
||||||
download_audio(&link)?;
|
fetch::download_audio(&link)?;
|
||||||
history::mark_as_downloaded(&link, history)?;
|
history::mark_as_downloaded(&link, history)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,21 +24,3 @@ pub fn run(subscriptions: &str, history: &str, site: &str) -> Result<()> {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue