diff options
Diffstat (limited to 'crates/yt_dlp/src/lib.rs')
-rw-r--r-- | crates/yt_dlp/src/lib.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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<Bound< Ok(opts) } +/// Take the result of the ie (may be modified) and resolve all unresolved +/// references (URLs, playlist items). +/// +/// It will also download the videos if 'download'. +/// Returns the resolved `ie_result`. +#[allow(clippy::unused_async)] +#[allow(clippy::missing_panics_doc)] +pub async fn process_ie_result( + yt_dlp_opts: &Map<String, Value>, + ie_result: InfoJson, + download: bool, +) -> Result<InfoJson, YtDlpError> { + Python::with_gil(|py| -> Result<InfoJson, YtDlpError> { + 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::<PyDict>() + .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 |