From bcbdd4729b987092fc9afa6027388aa1981367e1 Mon Sep 17 00:00:00 2001 From: mykola2312 Date: Sun, 31 Mar 2024 19:40:48 +0300 Subject: [PATCH] make download_format use spawn_pipe because of yt-dlp's undefined behavior related to file naming --- src/dl/yt_dlp.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/dl/yt_dlp.rs b/src/dl/yt_dlp.rs index 22f1629..1479aa9 100644 --- a/src/dl/yt_dlp.rs +++ b/src/dl/yt_dlp.rs @@ -4,7 +4,6 @@ use core::fmt; use ordered_float::OrderedFloat; use serde::Deserialize; use serde_json; -use std::fs; use tracing::{event, Level}; #[derive(Deserialize, Debug)] @@ -21,6 +20,7 @@ pub struct YtDlpFormat { pub abr: Option, } +#[allow(unused)] struct VideoFormat<'a> { pub format: &'a YtDlpFormat, pub format_note: &'a String, @@ -103,18 +103,6 @@ impl YtDlpInfo { Ok(info) } - pub fn default_format(&self) -> Option<&YtDlpFormat> { - match self - .formats - .iter() - .filter(|f| f.height.is_some_and(|h| h <= Self::H_LIMIT)) - .last() - { - Some(format) => Some(format), - None => self.formats.last(), - } - } - pub fn best_audio_format(&self) -> Option<&YtDlpFormat> { let format = self .formats @@ -257,7 +245,7 @@ impl YtDlp { let file = TmpFile::new(format!("{}_{}.{}", info.id, format.format_id, format.ext).as_str())?; - spawn( + spawn_pipe( "python", &[ "-m", @@ -266,10 +254,11 @@ impl YtDlp { "-f", &format.format_id, "-o", - &file.path, + "-", "--force-overwrites", "--no-exec", ], + &file ) .await?;