about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-02 01:07:06 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-02 01:07:06 -0700
commit63bfecda26d87c7d09691a0b479883a4eb26bf1e (patch)
treeff990d6d0621a2c26abfe8571b9d1a850377bf57
parent1082974bf046a94b4a52df6e8b3b3649a5bb85d6 (diff)
downloadytcpp-63bfecda26d87c7d09691a0b479883a4eb26bf1e.tar.gz
division
-rw-r--r--src/invapi.cpp30
-rw-r--r--src/invapi.hpp9
-rw-r--r--src/main.cpp63
-rw-r--r--src/sqliteinterface.cpp3
-rw-r--r--src/sqliteinterface.hpp7
-rw-r--r--src/tui.cpp39
-rw-r--r--src/tui.hpp8
7 files changed, 100 insertions, 59 deletions
diff --git a/src/invapi.cpp b/src/invapi.cpp
new file mode 100644
index 0000000..d56e701
--- /dev/null
+++ b/src/invapi.cpp
@@ -0,0 +1,30 @@
+#include <string>
+#include <vector>
+
+#include <cpr/cpr.h>
+#include <nlohmann/json.hpp>
+
+using namespace std;
+using json = nlohmann::json;
+
+vector<string> getInstances() {
+
+    vector<string> result;
+    cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, 
+        cpr::Parameters{{"sort_by", "health"}});
+
+    if (r.status_code > 299) {
+        
+        cerr << "invidious.io returned error code " << r.status_code << "!!" << endl;
+        throw runtime_error("bad response");
+    }
+
+    json j = json::parse(r.text);
+    for ( json i: j ) {
+        if ( i[1]["api"] != json::value_t::null && i[1]["api"]) {
+
+            result.push_back( i[1]["uri"] );
+        }
+    }
+    return result;
+}
\ No newline at end of file
diff --git a/src/invapi.hpp b/src/invapi.hpp
new file mode 100644
index 0000000..e5c97d4
--- /dev/null
+++ b/src/invapi.hpp
@@ -0,0 +1,9 @@
+#ifndef invapi
+#define invapi
+#include "invapi.cpp"
+#include <string>
+#include <vector>
+
+std::vector<std::string> getInstances();
+
+#endif
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index fc5c887..1ca8648 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,70 +6,15 @@
 #include <exception>
 #include <vector>
 
-#include "ftxui/component/captured_mouse.hpp"  // for ftxui
-#include "ftxui/component/component.hpp"       // for Input, Renderer, Vertical
-#include "ftxui/component/component_base.hpp"  // for ComponentBase
-#include "ftxui/component/component_options.hpp"  // for InputOption
-#include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive
-#include "ftxui/dom/elements.hpp"  // for text, hbox, separator, Element, operator|, vbox, border
-#include "ftxui/util/ref.hpp"  // for Ref
+#include "tui.hpp"
+#include "invapi.hpp"
 
-using namespace std;
-using json = nlohmann::json;
-
-string renderSearchBar() {
-
-    auto screen = ftxui::ScreenInteractive::Fullscreen();
-
-    ftxui::InputOption option;
-    option.on_enter = screen.ExitLoopClosure();
-    string searchTerm;
-    ftxui::Component inputSearchTerm = ftxui::Input(&searchTerm, "SMTH", &option);
-    
-    auto component = ftxui::Container::Vertical({
-        inputSearchTerm
-    });
-    
-    auto renderer = ftxui::Renderer(component, [&] {
-        return ftxui::vbox({
-                ftxui::text(" YTCCP "),
-                ftxui::separator(),
-                ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()),
-            }) |
-            ftxui::border;
-    });
-
-    
-    screen.Loop(renderer);
-
-    return searchTerm;
-}
 
-vector<string> getInstances() {
-
-    vector<string> result;
-    cpr::Response r = cpr::Get(cpr::Url{"https://api.invidious.io/instances.json"}, 
-        cpr::Parameters{{"sort_by", "health"}});
-
-    if (r.status_code > 299) {
-        
-        cerr << "invidious.io returned error code " << r.status_code << "!!" << endl;
-        throw runtime_error("bad response");
-    }
-
-    json j = json::parse(r.text);
-    for ( json i: j ) {
-        if ( i[1]["api"] != json::value_t::null && i[1]["api"]) {
-
-            result.push_back( i[1]["uri"] );
-        }
-    }
-    return result;
-}
+using namespace std;
 
 int main() {
 
-    // cout << renderSearchBar() << endl;
+    
     vector<string> instances = getInstances();
     for (auto i: instances) {
         cout << i << " ";
diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp
new file mode 100644
index 0000000..1552063
--- /dev/null
+++ b/src/sqliteinterface.cpp
@@ -0,0 +1,3 @@
+#include <string>
+#include <sqlite3.h>
+
diff --git a/src/sqliteinterface.hpp b/src/sqliteinterface.hpp
new file mode 100644
index 0000000..a7f469e
--- /dev/null
+++ b/src/sqliteinterface.hpp
@@ -0,0 +1,7 @@
+#ifndef invapi
+#define invapi
+#include "sqliteinterface.cpp"
+
+ 
+
+#endif  
\ No newline at end of file
diff --git a/src/tui.cpp b/src/tui.cpp
new file mode 100644
index 0000000..99e61f9
--- /dev/null
+++ b/src/tui.cpp
@@ -0,0 +1,39 @@
+#include <string>
+
+#include "ftxui/component/captured_mouse.hpp"  // for ftxui
+#include "ftxui/component/component.hpp"       // for Input, Renderer, Vertical
+#include "ftxui/component/component_base.hpp"  // for ComponentBase
+#include "ftxui/component/component_options.hpp"  // for InputOption
+#include "ftxui/component/screen_interactive.hpp"  // for Component, ScreenInteractive
+#include "ftxui/dom/elements.hpp"  // for text, hbox, separator, Element, operator|, vbox, border
+#include "ftxui/util/ref.hpp"  // for Ref
+
+using namespace std;
+
+string renderSearchBar() {
+
+    auto screen = ftxui::ScreenInteractive::Fullscreen();
+
+    ftxui::InputOption option;
+    option.on_enter = screen.ExitLoopClosure();
+    string searchTerm;
+    ftxui::Component inputSearchTerm = ftxui::Input(&searchTerm, "SMTH", &option);
+    
+    auto component = ftxui::Container::Vertical({
+        inputSearchTerm
+    });
+    
+    auto renderer = ftxui::Renderer(component, [&] {
+        return ftxui::vbox({
+                ftxui::text(" YTCCP "),
+                ftxui::separator(),
+                ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()),
+            }) |
+            ftxui::border;
+    });
+
+    
+    screen.Loop(renderer);
+
+    return searchTerm;
+}
\ No newline at end of file
diff --git a/src/tui.hpp b/src/tui.hpp
new file mode 100644
index 0000000..df9433c
--- /dev/null
+++ b/src/tui.hpp
@@ -0,0 +1,8 @@
+#ifndef tui
+#define tui
+#include "tui.cpp"
+#include <string>
+
+std::string renderSearchBar();
+
+#endif
\ No newline at end of file