podal/src/fetch.rs
Paul Campbell d8861d6f7e
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
Add tests for feed::find
2023-07-25 19:57:31 +01:00

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()?)
}