From 507c9611232e7b820789ec776159c703acd499ab Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 15 Jul 2025 06:57:31 +0200 Subject: 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. --- crates/yt_dlp/src/lib.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'crates/yt_dlp') 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 { - 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)?; @@ -288,6 +312,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}; -- cgit 1.4.1