From 8a53fbd8af842e2ca1bca0b352113ff7e965f51f Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 16 Feb 2025 09:46:39 +0100 Subject: feat(crates/yt_dlp/lib): Wrap `process_ie_result` function --- crates/yt_dlp/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs index cd1d0d2..129d4db 100644 --- a/crates/yt_dlp/src/lib.rs +++ b/crates/yt_dlp/src/lib.rs @@ -327,6 +327,42 @@ pub fn add_hooks<'a>(opts: Bound<'a, PyDict>, py: Python<'_>) -> PyResult, + ie_result: InfoJson, + download: bool, +) -> Result { + Python::with_gil(|py| -> Result { + let opts = json_map_to_py_dict(yt_dlp_opts, py)?; + + let instance = get_yt_dlp(py, opts)?; + + let args = { + let ie_result = json_loads_str(py, ie_result)?; + (ie_result,) + }; + + let kwargs = PyDict::new(py); + kwargs.set_item("download", download)?; + + let result = instance + .call_method("process_ie_result", args, Some(&kwargs))? + .downcast_into::() + .expect("This is a dict"); + + let result_str = json_dumps(py, result.into_any())?; + + serde_json::from_str(&result_str).map_err(Into::into) + }) +} + /// `extract_info(self, url, download=True, ie_key=None, extra_info=None, process=True, force_generic_extractor=False)` /// /// Extract and return the information dictionary of the URL -- cgit 1.4.1