2023-07-25 10:58:56 +01:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
use atom_syndication::Link;
|
2023-07-25 14:56:59 +01:00
|
|
|
use std::process::Command;
|
2023-07-25 10:58:56 +01:00
|
|
|
|
2023-07-25 19:24:15 +01:00
|
|
|
pub struct FetchEnv {
|
|
|
|
pub download: FetchDownload,
|
2023-07-25 19:36:56 +01:00
|
|
|
pub get: FetchGet,
|
2023-07-25 19:24:15 +01:00
|
|
|
}
|
|
|
|
|
2023-07-25 14:56:59 +01:00
|
|
|
pub type FetchDownload = fn(&Link) -> Result<()>;
|
2023-07-25 19:36:56 +01:00
|
|
|
pub type FetchGet = fn(&str) -> Result<Response>;
|
2023-07-25 10:58:56 +01:00
|
|
|
|
2023-07-25 14:56:59 +01:00
|
|
|
pub fn download(link: &Link) -> Result<()> {
|
2023-07-25 10:58:56 +01:00
|
|
|
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(())
|
|
|
|
}
|
2023-07-25 19:36:56 +01:00
|
|
|
|
2023-07-25 19:57:31 +01:00
|
|
|
pub type Response = String;
|
2023-07-25 19:36:56 +01:00
|
|
|
|
|
|
|
pub fn get(url: &str) -> Result<Response> {
|
2023-07-25 19:57:31 +01:00
|
|
|
Ok(reqwest::blocking::get(url)?.text()?)
|
2023-07-25 19:36:56 +01:00
|
|
|
}
|