#include #include #include #include "YtdlpWrapper.hpp" 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(); } py::object YtdlpWrapper::get_ytdl() { if (ytdl.is_none()) { ytdl = py::module::import("yt_dlp"); ytdl = ytdl.attr("YoutubeDL")(py::dict("ignoreerrors"_a=py::bool_(true))); } return ytdl; } json YtdlpWrapper::getJsonSearch(const string& searchTerm, int limit) { py::dict info = get_ytdl().attr("extract_info")("ytsearch"+std::to_string(limit)+":"+searchTerm, "download"_a=py::bool_(false)); return json::parse(pyDictToJsonString(info)); }