diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/YtdlpWrapper.cpp | 14 | ||||
-rw-r--r-- | src/main.cpp | 1 |
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"); |