diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-04-24 16:42:27 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-04-24 16:42:27 -0700 |
commit | 407a6f2507c784918a1c77ade4114c706f2c1e34 (patch) | |
tree | 7f3d55c555ee8c06f30e103607aa2d333df6c7b2 /src | |
parent | 9af660d1fe3506ff129fbb62576a74ec20f9a5f2 (diff) | |
download | ytcpp-407a6f2507c784918a1c77ade4114c706f2c1e34.tar.gz |
changes
Diffstat (limited to 'src')
-rw-r--r-- | src/YtdlpWrapper.cpp | 15 | ||||
-rw-r--r-- | src/YtdlpWrapper.hpp | 15 | ||||
-rw-r--r-- | src/main.cpp | 27 | ||||
-rw-r--r-- | src/sqliteinterface.cpp | 29 | ||||
-rw-r--r-- | src/sqliteinterface.hpp | 13 |
5 files changed, 76 insertions, 23 deletions
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 <string> +#include <vector> +#include <iostream> #include <pybind11/embed.h> #include <nlohmann/json.hpp> @@ -30,3 +32,16 @@ json YtdlpWrapper::getJsonSearch(const std::string& searchTerm, int limit) { return json::parse(pyDictToJsonString(info)); } +std::vector<Video::video> YtdlpWrapper::searchVideos(const std::string& searchTerm, int limit) { + + std::vector<Video::video> 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<float> quality; + std::optional<std::string> ext; std::string url; std::string vcodec; std::string acodec; @@ -20,6 +21,17 @@ namespace Video { int preference; int id; std::optional<std::string> resolution; + std::optional<int> height; + std::optional<int> width; + }; + + struct channel { + + std::string channelUrl; + std::optional<std::string> channelId; + std::optional<std::string> uploader; + std::optional<std::string> uploaderId; + std::optional<std::string> 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<int> duration; std::optional<int> viewcount; std::optional<std::string> description; @@ -40,6 +52,7 @@ class YtdlpWrapper { public: nlohmann::json getJsonSearch(const std::string& searchTerm, int limit = 1); + std::vector<Video::video> 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 <cpr/cpr.h> -#include <nlohmann/json.hpp> -#include <pybind11/embed.h> -#include <sqlite3.h> -#include <string> -#include <iostream> -#include <exception> -#include <vector> +// #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.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<string> 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 <string> #include <sqlite3.h> - -void openDB(); +class SqliteInterface { + + public: + SqliteInterface(); + ~SqliteInterface(); + void openDB(); + void closeDB(); + private: + sqlite3* db; +}; + #endif \ No newline at end of file |