about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-03-26 02:07:01 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-03-26 02:07:01 -0700
commit6cbff5d60cb708eb7f1eb0a598a6bb99d4b3a9e7 (patch)
tree042004653f503b4f5b64b9337d8defbe5763c276 /src
parentf12eca235e59c0ea64d2c569674ea7ad31753215 (diff)
downloadytcpp-6cbff5d60cb708eb7f1eb0a598a6bb99d4b3a9e7.tar.gz
very broken
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..923f30f
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,76 @@
+#include <cpr/cpr.h>
+#include <nlohmann/json.hpp>
+#include <string>
+#include <iostream>
+#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
+
+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", "api"}});
+
+    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"]) {
+            result.push_back(i.front());
+        }
+    }
+    return result;
+}
+
+int main() {
+
+    cout << renderSearchBar() << endl;
+    vector<string> instances = getInstances();
+    for (auto i: instances) {
+        cout << i << " ";
+    }
+    cout << endl;
+}
\ No newline at end of file