34 lines
873 B
Rust
34 lines
873 B
Rust
use crate::prelude::*;
|
|
|
|
use atom_syndication::Link;
|
|
use std::process::Command;
|
|
|
|
pub struct FetchEnv {
|
|
pub download: FetchDownload,
|
|
pub get: FetchGet,
|
|
}
|
|
|
|
pub type FetchDownload = fn(&Link) -> Result<()>;
|
|
pub type FetchGet = fn(&str) -> Result<Response>;
|
|
|
|
pub fn download(link: &Link) -> Result<()> {
|
|
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(())
|
|
}
|
|
|
|
pub type Response = String;
|
|
|
|
pub fn get(url: &str) -> Result<Response> {
|
|
Ok(reqwest::blocking::get(url)?.text()?)
|
|
}
|