From df6ccef6603d81fe140bfd7c726a1b1e1f72f097 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Tue, 18 Apr 2023 20:44:50 -0700 Subject: start adding structs --- CMakeLists.txt | 2 +- src/YtdlpWrapper.cpp | 2 +- src/YtdlpWrapper.hpp | 35 ++++++++++++++++++++++++++++++++++- src/invapi.cpp | 1 + src/main.cpp | 13 +++++++------ src/sqliteinterface.cpp | 2 +- src/sqliteinterface.hpp | 8 ++++---- 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 #include +namespace Video { + + struct format { + + std::optional quality; + std::string url; + std::string vcodec; + std::string acodec; + }; + + struct thumbnail { + + std::string url; + std::int preference; + std::int id; + std::optional resolution; + } + + struct video { + + std::string id; + std::string title; + std::string url; + std::string channel; + std::int duration; + std::optional viewcount; + std::optional 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 #include +#include #include #include 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 #include +#include #include #include #include #include #include -#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 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 #include - +#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 +#include #endif \ No newline at end of file -- cgit 1.4.1-2-gfad0