From 44803a87a143c8a94d5dbc10e0942d947a12c023 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Fri, 14 Apr 2023 21:25:55 -0700 Subject: failure to get pybind to work --- src/YtdlpWrapper.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/YtdlpWrapper.cpp') diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp index e0598a0..eca1cbc 100644 --- a/src/YtdlpWrapper.cpp +++ b/src/YtdlpWrapper.cpp @@ -8,14 +8,18 @@ using json = nlohmann::json; namespace py = pybind11; using namespace py::literals; -YtdlpWrapper::YtdlpWrapper() { +py::object YtdlpWrapper::get_ytdl() { + + if (ytdl.is_none()) { + ytdl = py::module::import("yt_dlp").attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true))); + } - ytdl = py::module::import("yt_dlp").attr("YoutubeDL")(py::dict({"ignoreerrors": true})); + return ytdl; } json YtdlpWrapper::getJsonSearch(const string& searchTerm) { - const auto info = ytdl.attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false)); - return json::parse(static_cast(info)); + py::object info = get_ytdl().attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false)); + return json::parse(info.cast()); } -- cgit 1.4.1-2-gfad0