about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-14 21:25:55 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-14 21:25:55 -0700
commit44803a87a143c8a94d5dbc10e0942d947a12c023 (patch)
treee164c2415635444e26e8f852ec48b238fcf08be3 /src
parent87d0da3a93b7f596ecfd62886efb2f1d965be0dd (diff)
downloadytcpp-44803a87a143c8a94d5dbc10e0942d947a12c023.tar.gz
failure to get pybind to work
Diffstat (limited to 'src')
-rw-r--r--src/YtdlpWrapper.cpp12
-rw-r--r--src/YtdlpWrapper.hpp4
-rw-r--r--src/main.cpp15
-rw-r--r--src/tui.cpp3
4 files changed, 15 insertions, 19 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>());
 }
 
diff --git a/src/YtdlpWrapper.hpp b/src/YtdlpWrapper.hpp
index a9522ea..6cc045d 100644
--- a/src/YtdlpWrapper.hpp
+++ b/src/YtdlpWrapper.hpp
@@ -6,10 +6,10 @@
 
 class YtdlpWrapper {
     public:
-        YtdlpWrapper();
         nlohmann::json getJsonSearch(const string& searchTerm);
     private:
-        pybind11::object ytdl;
+        pybind11::object get_ytdl();
+        pybind11::object ytdl = pybind11::none();
 };
 
 
diff --git a/src/main.cpp b/src/main.cpp
index 4267a73..42cba4f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,23 +8,16 @@
 
 #include "tui.cpp"
 #include "invapi.cpp"
-// #include "YtdlpWrapper.cpp"
+#include "YtdlpWrapper.cpp"
 
 
 using namespace std;
 
 int main() {
 
-    Tui tui;
-    string searchTerm;
-    int searchingFor;
-    tui.renderSearchBar(searchTerm, searchingFor);
-    if (tui.isCancelled()) {
-        
-        cerr << "cancelled!" << endl;
-        return 0;
-    }
-    cout << searchTerm << "," << searchingFor << endl;
+    YtdlpWrapper yt;
+    nlohmann::json j = yt.getJsonSearch("All Quiet on the Western Front Ost");
+    cout << j << endl;
 
     // vector<string> instances = getInstances();
     // for (auto i: instances) {
diff --git a/src/tui.cpp b/src/tui.cpp
index 601f468..61ba95e 100644
--- a/src/tui.cpp
+++ b/src/tui.cpp
@@ -15,7 +15,6 @@
 using namespace std;
 
 bool Tui::renderSearchBar(string& searchTerm, int& searchingFor) {
-    cancel = false;
 
     auto screen = ftxui::ScreenInteractive::Fullscreen();
 
@@ -57,7 +56,7 @@ bool Tui::renderSearchBar(string& searchTerm, int& searchingFor) {
         }) | ftxui::border;
     });
 
-    
+    cancel = false;
     screen.Loop(renderer);
 
     return true;