about summary refs log tree commit diff stats
path: root/src/YtdlpWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/YtdlpWrapper.cpp')
-rw-r--r--src/YtdlpWrapper.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp
new file mode 100644
index 0000000..ee799e0
--- /dev/null
+++ b/src/YtdlpWrapper.cpp
@@ -0,0 +1,21 @@
+#include <string>
+#include <pybind11/embed.h>
+#include <nlohmann/json.hpp>
+
+#include "YtdlpWrapper.hpp"
+
+using json = nlohmann::json;
+namespace py = pybind11;
+using namespace py::literals;
+
+YtdlpWrapper::YtdlpWrapper() {
+
+    ytdl = py::module::import("yt_dlp").attr("YoutubeDL")(py::dict({"ignoreerrors": true}));
+}
+
+json YtdlpWrapper::getJsonSearch(const string& searchTerm) {
+
+    const auto info = ytdl.attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false));
+    return json::parse(info.cast<std::string>());
+}
+