about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-24 16:42:27 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-24 16:42:27 -0700
commit407a6f2507c784918a1c77ade4114c706f2c1e34 (patch)
tree7f3d55c555ee8c06f30e103607aa2d333df6c7b2
parent9af660d1fe3506ff129fbb62576a74ec20f9a5f2 (diff)
downloadytcpp-407a6f2507c784918a1c77ade4114c706f2c1e34.tar.gz
changes
-rw-r--r--.gitignore3
-rw-r--r--CMakeLists.txt8
-rw-r--r--src/YtdlpWrapper.cpp15
-rw-r--r--src/YtdlpWrapper.hpp15
-rw-r--r--src/main.cpp27
-rw-r--r--src/sqliteinterface.cpp29
-rw-r--r--src/sqliteinterface.hpp13
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 <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
ef='#n563'>563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650