add youtube download

This commit is contained in:
Oleg Sobolev 2024-03-23 22:55:48 +07:00
parent 584b36820a
commit 90e34b8108
6 changed files with 58 additions and 1383 deletions

25
src/download.rs Normal file
View file

@ -0,0 +1,25 @@
use crate::track::TrackInfo;
use std::{path::Path, process::Command};
pub fn download_from_youtube(url: &str) -> TrackInfo {
let output = Command::new("yt-dlp")
.args([
"-o",
"%(id)s",
"--extract-audio",
"--audio-format",
"mp3",
"--print",
"%(id)s",
url,
])
.output()
.unwrap();
let filename = std::str::from_utf8(output.stdout.as_slice())
.unwrap()
.replace('\n', "")
+ ".mp3";
TrackInfo::new(&Path::new(filename.as_str()))
}