From dd135af27160f954c8f9c937d1fdb5b2a1032ccf Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 26 May 2026 18:11:35 +0200 Subject: feat(yt/download/hooks): Show progress of post-processors Otherwise, `yt` will just show everything downloaded, but does not continue. Now users see, what is _actually_ happening. --- crates/yt_dlp/src/options.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'crates/yt_dlp/src/options.rs') diff --git a/crates/yt_dlp/src/options.rs b/crates/yt_dlp/src/options.rs index 4b8906e..a87473d 100644 --- a/crates/yt_dlp/src/options.rs +++ b/crates/yt_dlp/src/options.rs @@ -21,7 +21,7 @@ use crate::{ python_error::{IntoPythonError, PythonError}, }; -pub type ProgressHookFunction = fn(py: Python<'_>) -> PyResult>; +pub type HookFunction = fn(py: Python<'_>) -> PyResult>; pub type PostProcessorFunction = fn(py: Python<'_>) -> PyResult>; /// Options, that are used to customize the download behaviour. @@ -32,7 +32,8 @@ pub type PostProcessorFunction = fn(py: Python<'_>) -> PyResult #[derive(Default, Debug)] pub struct YoutubeDLOptions { options: serde_json::Map, - progress_hook: Option, + progress_hook: Option, + post_processor_hook: Option, post_processors: Vec, } @@ -42,6 +43,7 @@ impl YoutubeDLOptions { let me = Self { options: serde_json::Map::new(), progress_hook: None, + post_processor_hook: None, post_processors: vec![], }; @@ -57,7 +59,7 @@ impl YoutubeDLOptions { } #[must_use] - pub fn with_progress_hook(self, progress_hook: ProgressHookFunction) -> Self { + pub fn with_progress_hook(self, progress_hook: HookFunction) -> Self { if let Some(_previous_hook) = self.progress_hook { todo!() } else { @@ -67,6 +69,17 @@ impl YoutubeDLOptions { } } } + #[must_use] + pub fn with_post_processor_hook(self, post_processor_hook: HookFunction) -> Self { + if let Some(_previous_hook) = self.post_processor_hook { + todo!() + } else { + Self { + post_processor_hook: Some(post_processor_hook), + ..self + } + } + } #[must_use] pub fn with_post_processor(mut self, pp: PostProcessorFunction) -> Self { @@ -135,6 +148,15 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) opts.set_item(intern!(py, "progress_hooks"), vec![ph(py).wrap_exc(py)?]) .wrap_exc(py)?; } + + // Setup the post_processor hook + if let Some(ph) = options.post_processor_hook { + opts.set_item( + intern!(py, "postprocessor_hooks"), + vec![ph(py).wrap_exc(py)?], + ) + .wrap_exc(py)?; + } } { -- cgit v1.3.1