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