about summary refs log tree commit diff stats
path: root/crates/yt_dlp/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crates/yt_dlp/src/lib.rs1
-rw-r--r--crates/yt_dlp/src/options.rs8
-rw-r--r--crates/yt_dlp/src/package_hacks/mod.rs11
-rw-r--r--crates/yt_dlp/src/package_hacks/urllib3.rs35
-rw-r--r--crates/yt_dlp/src/package_hacks/urllib3_polyfill.py13
5 files changed, 67 insertions, 1 deletions
diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs
index c412704..a03e444 100644
--- a/crates/yt_dlp/src/lib.rs
+++ b/crates/yt_dlp/src/lib.rs
@@ -33,6 +33,7 @@ pub mod progress_hook;
 pub mod python_error;
 
 mod logging;
+mod package_hacks;
 
 #[macro_export]
 macro_rules! json_get {
diff --git a/crates/yt_dlp/src/options.rs b/crates/yt_dlp/src/options.rs
index 182b8a1..dc3c154 100644
--- a/crates/yt_dlp/src/options.rs
+++ b/crates/yt_dlp/src/options.rs
@@ -22,7 +22,8 @@ use rustpython::{
 };
 
 use crate::{
-    YoutubeDL, json_loads, logging::setup_logging, post_processors, python_error::process_exception,
+    YoutubeDL, json_loads, logging::setup_logging, package_hacks, post_processors,
+    python_error::process_exception,
 };
 
 /// Wrap your function with [`mk_python_function`].
@@ -138,6 +139,11 @@ impl YoutubeDL {
         let output_options = options.options.clone();
 
         let (yt_dlp_module, youtube_dl_class) = match interpreter.enter(|vm| {
+            {
+                // Add missing (and required) values to the stdlib
+                package_hacks::urllib3::apply_hacks(vm)?;
+            }
+
             let yt_dlp_module = vm.import("yt_dlp", 0)?;
             let class = yt_dlp_module.get_attr("YoutubeDL", vm)?;
 
diff --git a/crates/yt_dlp/src/package_hacks/mod.rs b/crates/yt_dlp/src/package_hacks/mod.rs
new file mode 100644
index 0000000..53fe323
--- /dev/null
+++ b/crates/yt_dlp/src/package_hacks/mod.rs
@@ -0,0 +1,11 @@
+// yt - A fully featured command line YouTube client
+//
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of Yt.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+pub(super) mod urllib3;
diff --git a/crates/yt_dlp/src/package_hacks/urllib3.rs b/crates/yt_dlp/src/package_hacks/urllib3.rs
new file mode 100644
index 0000000..28ae37a
--- /dev/null
+++ b/crates/yt_dlp/src/package_hacks/urllib3.rs
@@ -0,0 +1,35 @@
+// yt - A fully featured command line YouTube client
+//
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of Yt.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+use rustpython::vm::{PyResult, VirtualMachine};
+
+// NOTE(@bpeetz): Remove this, once rust-python supports these features. <2025-06-27>
+pub(crate) fn apply_hacks(vm: &VirtualMachine) -> PyResult<()> {
+    {
+        // Urllib3 tries to import this value, regardless if it is set.
+        let ssl_module = vm.import("ssl", 0)?;
+        ssl_module.set_attr("VERIFY_X509_STRICT", vm.ctx.new_int(0x20), vm)?;
+    }
+
+    {
+        // Urllib3 tries to set the SSLContext.verify_flags value, regardless if it exists or not.
+        // So we need to provide a polyfill.
+
+        let scope = vm.new_scope_with_builtins();
+
+        vm.run_code_string(
+            scope,
+            include_str!("urllib3_polyfill.py"),
+            "<embedded urllib3 polyfill workaround code>".to_owned(),
+        )?;
+    }
+
+    Ok(())
+}
diff --git a/crates/yt_dlp/src/package_hacks/urllib3_polyfill.py b/crates/yt_dlp/src/package_hacks/urllib3_polyfill.py
new file mode 100644
index 0000000..610fd99
--- /dev/null
+++ b/crates/yt_dlp/src/package_hacks/urllib3_polyfill.py
@@ -0,0 +1,13 @@
+# yt - A fully featured command line YouTube client
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Yt.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+import ssl
+
+ssl.SSLContext.verify_flags = 0