diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-04-02 01:07:06 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-04-02 01:07:06 -0700 |
commit | 63bfecda26d87c7d09691a0b479883a4eb26bf1e (patch) | |
tree | ff990d6d0621a2c26abfe8571b9d1a850377bf57 /src | |
parent | 1082974bf046a94b4a52df6e8b3b3649a5bb85d6 (diff) | |
download | ytcpp-63bfecda26d87c7d09691a0b479883a4eb26bf1e.tar.gz |
division
Diffstat (limited to 'src')
-rw-r--r-- | src/invapi.cpp | 30 | ||||
-rw-r--r-- | src/invapi.hpp | 9 | ||||
-rw-r--r-- | src/main.cpp | 63 | ||||
-rw-r--r-- | src/sqliteinterface.cpp | 3 | ||||
-rw-r--r-- | src/sqliteinterface.hpp | 7 | ||||
-rw-r--r-- | src/tui.cpp | 39 | ||||
-rw-r--r-- | src/tui.hpp | 8 |
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 |