diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-15 06:57:31 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-15 06:58:44 +0200 |
commit | 507c9611232e7b820789ec776159c703acd499ab (patch) | |
tree | 8c8d480d87ad064b1e6c028c6ce17f6d6b98906e /crates/yt_dlp/src | |
parent | refactor(crates/yt): Allow `missing_panic_docs` and use expect (diff) | |
download | yt-507c9611232e7b820789ec776159c703acd499ab.zip |
fix(crates/yt/downloader): Correctly treat the download as blocking
This change _might_ also allow aborting the current download, but I'm not yet sure.
Diffstat (limited to 'crates/yt_dlp/src')
-rw-r--r-- | crates/yt_dlp/src/lib.rs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs index d0cfbdd..dc602db 100644 --- a/crates/yt_dlp/src/lib.rs +++ b/crates/yt_dlp/src/lib.rs @@ -12,7 +12,7 @@ use std::path::PathBuf; -use log::info; +use log::{debug, info}; use pyo3::{ Bound, Py, PyAny, Python, intern, types::{PyAnyMethods, PyDict, PyIterator, PyList}, @@ -273,12 +273,36 @@ impl YoutubeDL { }) } + /// Close this [`YoutubeDL`] instance, and stop all currently running downloads. + /// + /// # Errors + /// If python operations fail. + pub fn close(&self) -> Result<(), close::Error> { + Python::with_gil(|py| { + debug!("Closing YoutubeDL."); + + let inner = self + .inner + .bind(py) + .getattr(intern!(py, "close")) + .wrap_exc(py)?; + + inner.call0().wrap_exc(py)?; + + Ok(()) + }) + } + fn prepare_info_json<'py>( &self, info: &Bound<'py, PyDict>, py: Python<'py>, ) -> Result<InfoJson, prepare::Error> { - let sanitize = self.inner.bind(py).getattr(intern!(py, "sanitize_info")).wrap_exc(py)?; + let sanitize = self + .inner + .bind(py) + .getattr(intern!(py, "sanitize_info")) + .wrap_exc(py)?; let value = sanitize.call((info,), None).wrap_exc(py)?; @@ -289,6 +313,16 @@ impl YoutubeDL { } #[allow(missing_docs)] +pub mod close { + use crate::python_error::PythonError; + + #[derive(Debug, thiserror::Error)] + pub enum Error { + #[error(transparent)] + Python(#[from] PythonError), + } +} +#[allow(missing_docs)] pub mod process_ie_result { use crate::{prepare, python_error::PythonError}; |