diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-02-16 09:46:39 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-02-16 09:46:39 +0100 |
commit | 8a53fbd8af842e2ca1bca0b352113ff7e965f51f (patch) | |
tree | ecd42526fdf1ebcbd7aa07100c4fc0f473d8eb7c /crates/yt_dlp | |
parent | fix(crates/yt_dlp/lib): Actually resolve the `entries` generator object (diff) | |
download | yt-8a53fbd8af842e2ca1bca0b352113ff7e965f51f.zip |
feat(crates/yt_dlp/lib): Wrap `process_ie_result` function
Diffstat (limited to 'crates/yt_dlp')
-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 |