diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-11-07 15:20:36 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-11-07 15:20:36 +0100 |
| commit | c1b75cf60e0d116db8f43c7023fb507149091019 (patch) | |
| tree | e3becc3c45a5985066c38c86ff4b7846f75d27d8 /crates/yt_dlp/src/info_json.rs | |
| parent | fix(yt/storage/db/insert/subs): Warn when trying to mark an sub with the same... (diff) | |
| download | yt-c1b75cf60e0d116db8f43c7023fb507149091019.zip | |
fix(yt_dlp/info_json): Allow loading and dumping any type
Diffstat (limited to 'crates/yt_dlp/src/info_json.rs')
| -rw-r--r-- | crates/yt_dlp/src/info_json.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/yt_dlp/src/info_json.rs b/crates/yt_dlp/src/info_json.rs index df49218..c25ecab 100644 --- a/crates/yt_dlp/src/info_json.rs +++ b/crates/yt_dlp/src/info_json.rs @@ -9,15 +9,40 @@ // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. use pyo3::{ - Bound, Python, intern, + Bound, PyAny, Python, intern, types::{PyAnyMethods, PyDict}, }; +use serde_json::json; + +use crate::json_cast; pub type InfoJson = serde_json::Map<String, serde_json::Value>; /// # Panics /// If expectation about python operations fail. #[must_use] +pub fn json_loads_any(input: serde_json::Value, py: Python<'_>) -> Bound<'_, PyAny> { + let json = json!( {"tmp": input} ); + let json = json_cast!(json, as_object); + let dict = json_loads(json.to_owned(), py); + dict.get_item(intern!(py, "tmp")) + .expect("was just assigned") +} + +/// # Panics +/// If expectation about python operations fail. +#[must_use] +pub fn json_dumps_any(input: Bound<'_, PyAny>, py: Python<'_>) -> serde_json::Value { + let tmp_dict = PyDict::new(py); + tmp_dict.set_item("tmp", input).expect("This should never throw an exception"); + let mut out = json_dumps(&tmp_dict); + + out.remove("tmp").expect("was just assigned") +} + +/// # Panics +/// If expectation about python operations fail. +#[must_use] pub fn json_loads( input: serde_json::Map<String, serde_json::Value>, py: Python<'_>, |
