diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 76 |
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 |