From 407a6f2507c784918a1c77ade4114c706f2c1e34 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Mon, 24 Apr 2023 16:42:27 -0700 Subject: changes --- .gitignore | 3 +++ CMakeLists.txt | 8 ++++++-- src/YtdlpWrapper.cpp | 15 +++++++++++++++ src/YtdlpWrapper.hpp | 15 ++++++++++++++- src/main.cpp | 27 +++++++++++++++------------ src/sqliteinterface.cpp | 29 +++++++++++++++++++++-------- src/sqliteinterface.hpp | 13 +++++++++++-- 7 files changed, 85 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 6dc2dea..799ab96 100644 --- a/.gitignore +++ b/.gitignore @@ -198,3 +198,6 @@ cython_debug/ # VS Code files .vscode/ +#debugging files +/*.json + diff --git a/CMakeLists.txt b/CMakeLists.txt index 85a79c9..aac7d57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,14 +47,18 @@ if(UNIX) elseif(WIN32) file(TO_CMAKE_PATH "$ENV{LOCALAPPDATA}\\${PROJECT_NAME}" DEF_APPDATA) else() - message(SEND_ERROR "OS not recognized !") + message(SEND_ERROR "OS not recognized!") file(TO_CMAKE_PATH "./data" DEF_APPDATA) endif() 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_compile_definitions(${PROJECT_NAME} PRIVATE DEF_APPDATA="${DEF_APPDATA}") + +target_compile_definitions(${PROJECT_NAME} + PRIVATE DEF_APPDATA="${DEF_APPDATA}" + PRIVATE VERSION="${VERSION}" +) target_link_libraries(${PROJECT_NAME} PRIVATE cpr::cpr diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp index 9e27a1c..7368c14 100644 --- a/src/YtdlpWrapper.cpp +++ b/src/YtdlpWrapper.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include @@ -30,3 +32,16 @@ json YtdlpWrapper::getJsonSearch(const std::string& searchTerm, int limit) { return json::parse(pyDictToJsonString(info)); } +std::vector YtdlpWrapper::searchVideos(const std::string& searchTerm, int limit) { + + std::vector resp; + + json info = getJsonSearch(searchTerm, limit); + + for (json i: info["entries"]) { + std::cout << i["id"] << std::endl; + } + + return resp; +} + diff --git a/src/YtdlpWrapper.hpp b/src/YtdlpWrapper.hpp index b1633ca..f2e916e 100644 --- a/src/YtdlpWrapper.hpp +++ b/src/YtdlpWrapper.hpp @@ -9,6 +9,7 @@ namespace Video { struct format { std::optional quality; + std::optional ext; std::string url; std::string vcodec; std::string acodec; @@ -20,6 +21,17 @@ namespace Video { int preference; int id; std::optional resolution; + std::optional height; + std::optional width; + }; + + struct channel { + + std::string channelUrl; + std::optional channelId; + std::optional uploader; + std::optional uploaderId; + std::optional uploaderUrl; }; struct video { @@ -27,7 +39,7 @@ namespace Video { std::string id; std::string title; std::string url; - std::string channel; + channel uploader; std::optional duration; std::optional viewcount; std::optional description; @@ -40,6 +52,7 @@ class YtdlpWrapper { public: nlohmann::json getJsonSearch(const std::string& searchTerm, int limit = 1); + std::vector searchVideos(const std::string& searchterm, int limit = 1); private: pybind11::object get_ytdl(); pybind11::object ytdl = pybind11::none(); diff --git a/src/main.cpp b/src/main.cpp index c08ba75..8c9503d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include #include "tui.hpp" #include "invapi.hpp" @@ -13,16 +13,19 @@ #include "sqliteinterface.hpp" -namespace py = pybind11; +// namespace py = pybind11; using namespace std; -int main() { +int main(int argc, char **argv) { - // YtdlpWrapper yt; + YtdlpWrapper yt; + yt.searchVideos("the very thought of you", 5); // nlohmann::json j = yt.getJsonSearch("the very thought of you"); // cout << j << endl; - openDB(); + // cout << VERSION << endl; + + // SqliteInterface data; // vector instances = getInstances(); // for (auto i: instances) { diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp index 1ae59be..328a44c 100644 --- a/src/sqliteinterface.cpp +++ b/src/sqliteinterface.cpp @@ -8,18 +8,20 @@ namespace fs = std::filesystem; using namespace std; -void openDB() { +void SqliteInterface::openDB() { fs::path appdata = DEF_APPDATA; if ( ! fs::exists(appdata) ) { error_code ec; fs::create_directories(appdata, ec); - cout << ec << endl; - } - cout << fs::exists(appdata) << endl; + if (ec.value() != 0) { - sqlite3 *db; + char errmsg[] = "Can't create folder: "; + strcat(errmsg, ec.message().c_str()); + throw runtime_error(errmsg); + } + } fs::path filename = appdata / "ytcpp.db"; int rc = sqlite3_open(filename.c_str(), &db); @@ -29,9 +31,20 @@ void openDB() { char errmsg[] = "Can't open database: "; strcat(errmsg, sqlite3_errmsg(db)); throw runtime_error(errmsg); - } else { - - std::cout << "Opened database successfully" << std::endl; } +} + +void SqliteInterface::closeDB() { + sqlite3_close(db); +} + +SqliteInterface::SqliteInterface() { + + openDB(); +} + +SqliteInterface::~SqliteInterface() { + + closeDB(); } \ No newline at end of file diff --git a/src/sqliteinterface.hpp b/src/sqliteinterface.hpp index 4a18f85..5dc25d3 100644 --- a/src/sqliteinterface.hpp +++ b/src/sqliteinterface.hpp @@ -2,6 +2,15 @@ #define SQLITEINTERFACE_H #include #include - -void openDB(); +class SqliteInterface { + + public: + SqliteInterface(); + ~SqliteInterface(); + void openDB(); + void closeDB(); + private: + sqlite3* db; +}; + #endif \ No newline at end of file -- cgit 1.4.1-2-gfad0