diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-11-07 18:25:55 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-11-07 18:25:55 +0100 |
| commit | 936002297daabce66ff48a2dd4dcf673191e5694 (patch) | |
| tree | 84d2480302233419f5efbe8a685fbf09652eda37 | |
| parent | refactor({yt/cmds/{download,select},colors/custom}): Remove clippy warnings (diff) | |
| download | yt-936002297daabce66ff48a2dd4dcf673191e5694.zip | |
fix({yt/yt_dlp/match_filters,yt_dlp/options}): Make match_filters actually work
Diffstat (limited to '')
| -rw-r--r-- | crates/yt/src/yt_dlp/match_filters.rs | 38 | ||||
| -rw-r--r-- | crates/yt_dlp/src/options.rs | 6 |
2 files changed, 25 insertions, 19 deletions
diff --git a/crates/yt/src/yt_dlp/match_filters.rs b/crates/yt/src/yt_dlp/match_filters.rs index ae5675b..b4a0984 100644 --- a/crates/yt/src/yt_dlp/match_filters.rs +++ b/crates/yt/src/yt_dlp/match_filters.rs @@ -1,24 +1,27 @@ -use yt_dlp::{ - hooks::__priv::pyo3::types::{PyNone, PyString}, json_get, wrap_match_filter, -}; +use yt_dlp::{hooks::__priv::pyo3::types::PyString, json_get}; enum MatchFilterOutput { - Ignore { msg: &'static str }, + Ignore { + msg: &'static str, + }, Download, + #[expect(unused)] InteractiveChoice, - Cancel { msg: String }, + #[expect(unused)] + Cancel { + msg: String, + }, } +#[expect(clippy::unnecessary_wraps, clippy::needless_pass_by_value)] fn ignore_member_only( arg: serde_json::Map<String, serde_json::Value>, ) -> yt_dlp::hooks::__priv::pyo3::PyResult<MatchFilterOutput> { - panic!("Called"); - - let ava = json_get!(arg, "availability", as_str); - if ava == "pubilc" { + let availability = json_get!(arg, "availability", as_str); + if availability == "pubilc" { Ok(MatchFilterOutput::Download) } else { - Ok(MatchFilterOutput::Ignore { msg: "Not public"}) + Ok(MatchFilterOutput::Ignore { msg: "Not public" }) } } @@ -29,10 +32,13 @@ pub(crate) fn ignore_member_only_wrapped( yt_dlp::hooks::__priv::pyo3::Bound<'_, yt_dlp::hooks::__priv::pyo3::types::PyCFunction>, > { #[yt_dlp::hooks::__priv::pyo3::pyfunction] - #[pyo3(crate = "yt_dlp::hooks::__priv::pyo3")] + #[pyo3(crate = "yt_dlp::hooks::__priv::pyo3", signature = (info_dict, /, incomplete))] + #[expect(clippy::needless_pass_by_value)] fn inner<'a>( - input: yt_dlp::hooks::__priv::pyo3::Bound<'_, yt_dlp::hooks::__priv::pyo3::types::PyDict>, - any: yt_dlp::hooks::__priv::pyo3::Bound<'_, yt_dlp::hooks::__priv::pyo3::types::PyAny>, + info_dict: yt_dlp::hooks::__priv::pyo3::Bound< + '_, + yt_dlp::hooks::__priv::pyo3::types::PyDict, + >, incomplete: yt_dlp::hooks::__priv::pyo3::Bound< 'a, yt_dlp::hooks::__priv::pyo3::types::PyBool, @@ -41,15 +47,15 @@ pub(crate) fn ignore_member_only_wrapped( Option<yt_dlp::hooks::__priv::pyo3::Bound<'a, PyString>>, > { let processed_input = { - let new_dict = yt_dlp::hooks::__priv::filter_dict(input); + let new_dict = yt_dlp::hooks::__priv::filter_dict(info_dict); yt_dlp::hooks::__priv::json_dumps(&new_dict) }; match ignore_member_only(processed_input)? { - MatchFilterOutput::Ignore { msg } => Ok(Some(PyString::new(incomplete.py(), &msg))), + MatchFilterOutput::Ignore { msg } => Ok(Some(PyString::new(incomplete.py(), msg))), MatchFilterOutput::Download => Ok(None), MatchFilterOutput::InteractiveChoice => todo!(), - MatchFilterOutput::Cancel { msg } => todo!(), + MatchFilterOutput::Cancel { msg: _ } => todo!(), } } diff --git a/crates/yt_dlp/src/options.rs b/crates/yt_dlp/src/options.rs index cdbdb45..5fdcb18 100644 --- a/crates/yt_dlp/src/options.rs +++ b/crates/yt_dlp/src/options.rs @@ -12,7 +12,7 @@ use std::sync; use pyo3::{ Bound, IntoPyObjectExt, PyAny, PyResult, Python, intern, - types::{PyAnyMethods, PyCFunction, PyDict, PyList, PyTuple}, + types::{PyAnyMethods, PyCFunction, PyDict, PyTuple}, }; use pyo3_pylogger::setup_logging; @@ -159,13 +159,13 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) }); } - { + if !options.match_filters.is_empty() { // TODO: Make this work with more than one match filter. <2026-11-07> assert_eq!(options.match_filters.len(), 1); opts.set_item( intern!(py, "match_filter"), - pp(py) + options.match_filters[0](py) .wrap_exc(py, "convertion match filter function to python")? .into_bound_py_any(py) .wrap_exc(py, "converting match filter function to any type")?, |
