add youtube download
This commit is contained in:
parent
584b36820a
commit
90e34b8108
6 changed files with 58 additions and 1383 deletions
25
src/download.rs
Normal file
25
src/download.rs
Normal 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()))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue