about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-18 20:44:50 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-18 20:44:50 -0700
commitdf6ccef6603d81fe140bfd7c726a1b1e1f72f097 (patch)
tree7bfe644bc55d41084fa7f03e34df5a7e6efff1b3
parent772637e0947286e54ab97b8d55ad2c05fe9a1c86 (diff)
downloadytcpp-df6ccef6603d81fe140bfd7c726a1b1e1f72f097.tar.gz
start adding structs
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/YtdlpWrapper.cpp2
-rw-r--r--src/YtdlpWrapper.hpp35
-rw-r--r--src/invapi.cpp1
-rw-r--r--src/main.cpp13
-rw-r--r--src/sqliteinterface.cpp2
-rw-r--r--src/sqliteinterface.hpp8
7 files changed, 49 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 25833e0..f3dda8a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,7 @@ add_subdirectory(extern/pybind11)
 
 find_package(Ytdlp REQUIRED RUNTIME)
 
-add_executable(${PROJECT_NAME} src/main.cpp)
+add_executable(${PROJECT_NAME} src/main.cpp src/tui.cpp src/invapi.cpp src/YtdlpWrapper.cpp src/sqliteinterface.cpp)
 target_include_directories(${PROJECT_NAME} PRIVATE src)
 
 target_link_libraries(${PROJECT_NAME} 
diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp
index 2b87a62..9e27a1c 100644
--- a/src/YtdlpWrapper.cpp
+++ b/src/YtdlpWrapper.cpp
@@ -24,7 +24,7 @@ py::object YtdlpWrapper::get_ytdl() {
     return ytdl;
 }
 
-json YtdlpWrapper::getJsonSearch(const string& searchTerm, int limit) {
+json YtdlpWrapper::getJsonSearch(const std::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));
diff --git a/src/YtdlpWrapper.hpp b/src/YtdlpWrapper.hpp
index f7cc256..9dbd3a2 100644
--- a/src/YtdlpWrapper.hpp
+++ b/src/YtdlpWrapper.hpp
@@ -4,12 +4,45 @@
 #include <pybind11/embed.h>
 #include <nlohmann/json.hpp>
 
+namespace Video {
+
+    struct format {
+    
+        std::optional<float> quality;
+        std::string url;
+        std::string vcodec;
+        std::string acodec;
+    };
+
+    struct thumbnail {
+
+        std::string url;
+        std::int preference;
+        std::int id;
+        std::optional<std::string> resolution;
+    }
+
+    struct video {
+
+        std::string id;
+        std::string title;
+        std::string url;
+        std::string channel;
+        std::int duration;
+        std::optional<int> viewcount;
+        std::optional<std::string> description;
+
+    }
+}
+
 class YtdlpWrapper {
+
     public:
-        nlohmann::json getJsonSearch(const string& searchTerm, int limit = 1);
+        nlohmann::json getJsonSearch(const std::string& searchTerm, int limit = 1);
     private:
         pybind11::object get_ytdl();
         pybind11::object ytdl = pybind11::none();
+        pybind11::scoped_interpreter guard{};
 };
 
 
diff --git a/src/invapi.cpp b/src/invapi.cpp
index 47a9575..b96d18b 100644
--- a/src/invapi.cpp
+++ b/src/invapi.cpp
@@ -1,5 +1,6 @@
 #include <string>
 #include <vector>
+#include <iostream>
 
 #include <cpr/cpr.h>
 #include <nlohmann/json.hpp>
diff --git a/src/main.cpp b/src/main.cpp
index f258c24..992761a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,24 +1,25 @@
 #include <cpr/cpr.h>
 #include <nlohmann/json.hpp>
+#include <pybind11/embed.h>
 #include <sqlite3.h>
 #include <string>
 #include <iostream>
 #include <exception>
 #include <vector>
 
-#include "tui.cpp"
-#include "invapi.cpp"
-#include "YtdlpWrapper.cpp"
+#include "tui.hpp"
+#include "invapi.hpp"
+#include "YtdlpWrapper.hpp"
 
 
+namespace py = pybind11;
 using namespace std;
 
 int main() {
-    py::scoped_interpreter guard{};
 
     YtdlpWrapper yt;
-    // nlohmann::json j = yt.getJsonSearch("All Quiet on the Western Front Ost");
-    // cout << j << endl;
+    nlohmann::json j = yt.getJsonSearch("the very thought of you");
+    cout << j << endl;
 
     // vector<string> instances = getInstances();
     // for (auto i: instances) {
diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp
index 1552063..6b244dc 100644
--- a/src/sqliteinterface.cpp
+++ b/src/sqliteinterface.cpp
@@ -1,3 +1,3 @@
 #include <string>
 #include <sqlite3.h>
-
+#include "sqliteinterface.hpp"
diff --git a/src/sqliteinterface.hpp b/src/sqliteinterface.hpp
index a7f469e..6a38d2c 100644
--- a/src/sqliteinterface.hpp
+++ b/src/sqliteinterface.hpp
@@ -1,7 +1,7 @@
-#ifndef invapi
-#define invapi
-#include "sqliteinterface.cpp"
-
+#ifndef SQLITEINTERFACE_H
+#define SQLITEINTERFACE_H
+#include <string>
+#include <sqlite3.h>
  
 
 #endif  
\ No newline at end of file