diff options
Diffstat (limited to 'src/YtdlpWrapper.cpp')
-rw-r--r-- | src/YtdlpWrapper.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp index 5a18ab2..cabe473 100644 --- a/src/YtdlpWrapper.cpp +++ b/src/YtdlpWrapper.cpp @@ -12,16 +12,18 @@ std::string pyDictToJsonString(const py::dict& dict) { } py::object YtdlpWrapper::get_ytdl() { - - if (ytdl.is_none()) { - ytdl = py::module::import("yt_dlp"); - } - return ytdl; + // pybind11::object ytdl = pybind11::none(); + // if (ytdl.is_none()) { + // ytdl = py::module::import("yt_dlp"); + // } + + return py::module::import("yt_dlp"); } json YtdlpWrapper::getJsonSearch(const std::string& searchTerm, int limit) { + pybind11::scoped_interpreter guard{}; py::dict info = get_ytdl() .attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true))) .attr("extract_info")("ytsearch"+std::to_string(limit)+":"+searchTerm, "download"_a=py::bool_(false)); @@ -30,6 +32,7 @@ json YtdlpWrapper::getJsonSearch(const std::string& searchTerm, int limit) { std::vector<Video::video> YtdlpWrapper::searchVideos(const std::string& searchTerm, int limit) { + pybind11::scoped_interpreter guard{}; std::vector<Video::video> resp; json info = json::parse(pyDictToJsonString( @@ -49,6 +52,7 @@ std::vector<Video::video> YtdlpWrapper::searchVideos(const std::string& searchTe Video::video YtdlpWrapper::getVideoByUrl(const std::string& url) { + pybind11::scoped_interpreter guard{}; json info = json::parse(pyDictToJsonString( get_ytdl().attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true), "noplaylist"_a=py::bool_(true))) .attr("extract_info")(url, "download"_a=py::bool_(false)) |