about summary refs log tree commit diff stats
path: root/src/YtdlpWrapper.cpp
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-14 21:25:55 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-14 21:25:55 -0700
commit44803a87a143c8a94d5dbc10e0942d947a12c023 (patch)
treee164c2415635444e26e8f852ec48b238fcf08be3 /src/YtdlpWrapper.cpp
parent87d0da3a93b7f596ecfd62886efb2f1d965be0dd (diff)
downloadytcpp-44803a87a143c8a94d5dbc10e0942d947a12c023.tar.gz
failure to get pybind to work
Diffstat (limited to 'src/YtdlpWrapper.cpp')
-rw-r--r--src/YtdlpWrapper.cpp12
1 files changed, 8 insertions, 4 deletions
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<std::string>(info));
+    py::object info = get_ytdl().attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false));
+    return json::parse(info.cast<std::string>());
 }