You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
806 B
Rust
33 lines
806 B
Rust
use std::io::Read;
|
|
use std::process::{Command, Stdio};
|
|
|
|
use crate::providers::ytdl::playlist_entry::PlaylistEntry;
|
|
use crate::utils::error::BotResult;
|
|
|
|
mod playlist_entry;
|
|
|
|
/// Returns a list of youtube videos for a given url
|
|
pub(crate) fn get_videos_for_url(url: &str) -> BotResult<Vec<PlaylistEntry>> {
|
|
let ytdl = Command::new("youtube-dl")
|
|
.args(&[
|
|
"-f",
|
|
"--no-warnings",
|
|
"--flat-playlist",
|
|
"--dump-json",
|
|
"-i",
|
|
url,
|
|
])
|
|
.stdout(Stdio::piped())
|
|
.spawn()?;
|
|
|
|
let mut output = String::new();
|
|
ytdl.stdout.unwrap().read_to_string(&mut output)?;
|
|
|
|
let videos = output
|
|
.lines()
|
|
.map(|l| serde_json::from_str::<PlaylistEntry>(l).unwrap())
|
|
.collect();
|
|
|
|
Ok(videos)
|
|
}
|