about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-18 16:54:45 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-18 16:54:45 -0700
commit6737e6ac61634781638338b3753385e78aa1d571 (patch)
tree3d5db707eb03bc4a6f4c2909dc5983db068bf2b1 /src
parent44803a87a143c8a94d5dbc10e0942d947a12c023 (diff)
downloadytcpp-6737e6ac61634781638338b3753385e78aa1d571.tar.gz
yt-dlp is working
Diffstat (limited to 'src')
-rw-r--r--src/YtdlpWrapper.cpp14
-rw-r--r--src/main.cpp1
2 files changed, 12 insertions, 3 deletions
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp
index eca1cbc..ca1d4a4 100644
--- a/src/YtdlpWrapper.cpp
+++ b/src/YtdlpWrapper.cpp
@@ -8,10 +8,17 @@ using json = nlohmann::json;
 namespace py = pybind11;
 using namespace py::literals;
 
+std::string pyDictToJsonString(const py::dict& dict) {
+
+    pybind11::object json = py::module::import("json");
+    return json.attr("dumps")(dict).cast<std::string>();
+}
+
 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");
+        ytdl = ytdl.attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true)));
     }
 
     return ytdl;
@@ -19,7 +26,8 @@ py::object YtdlpWrapper::get_ytdl() {
 
 json YtdlpWrapper::getJsonSearch(const string& searchTerm) {
 
-    py::object info = get_ytdl().attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false));
-    return json::parse(info.cast<std::string>());
+    // py::object info = get_ytdl().attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false));
+    py::dict info("test"_a=py::bool_(true), "test2"_a=py::str("yoyoyo"), "test3"_a=py::none());
+    return json::parse(pyDictToJsonString(info));
 }
 
diff --git a/src/main.cpp b/src/main.cpp
index 42cba4f..a03461f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,6 +14,7 @@
 using namespace std;
 
 int main() {
+    py::scoped_interpreter guard{};
 
     YtdlpWrapper yt;
     nlohmann::json j = yt.getJsonSearch("All Quiet on the Western Front Ost");