From 9d53072e32c60aa51784182a0a608ce204cab9e6 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Wed, 12 Apr 2023 14:32:15 -0700 Subject: breaking changes broke everything --- src/YtdlpWrapper.cpp | 21 +++++++++++++++++++ src/YtdlpWrapper.hpp | 17 ++++++++++++++++ src/main.cpp | 22 ++++++++++++++------ src/tui.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++---------- src/tui.hpp | 23 +++++++++++++++++---- 5 files changed, 119 insertions(+), 21 deletions(-) create mode 100644 src/YtdlpWrapper.cpp create mode 100644 src/YtdlpWrapper.hpp (limited to 'src') diff --git a/src/YtdlpWrapper.cpp b/src/YtdlpWrapper.cpp new file mode 100644 index 0000000..ee799e0 --- /dev/null +++ b/src/YtdlpWrapper.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +#include "YtdlpWrapper.hpp" + +using json = nlohmann::json; +namespace py = pybind11; +using namespace py::literals; + +YtdlpWrapper::YtdlpWrapper() { + + ytdl = py::module::import("yt_dlp").attr("YoutubeDL")(py::dict({"ignoreerrors": true})); +} + +json YtdlpWrapper::getJsonSearch(const string& searchTerm) { + + const auto info = ytdl.attr("extract_info")("ytsearch:"+searchTerm, "download"_a=py::bool_(false)); + return json::parse(info.cast()); +} + diff --git a/src/YtdlpWrapper.hpp b/src/YtdlpWrapper.hpp new file mode 100644 index 0000000..1e31569 --- /dev/null +++ b/src/YtdlpWrapper.hpp @@ -0,0 +1,17 @@ +#ifndef YtdlpWrapper +#define YtdlpWrapper +#include "YtdlpWrapper.cpp" +#include +#include +#include + +class YtdlpWrapper { + public: + YtdlpWrapper(); + nlohmann::json getJsonSearch(const string& searchTerm); + private: + pybind11::object ytdl; +}; + + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1ca8648..5bc7679 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,18 +6,28 @@ #include #include -#include "tui.hpp" +#include "tui.cpp" #include "invapi.hpp" +#include "YtdlpWrapper.hpp" using namespace std; int main() { - - vector instances = getInstances(); - for (auto i: instances) { - cout << i << " "; + Tui tui; + string searchTerm; + int searchingFor; + tui.renderSearchBar(searchTerm, searchingFor); + if (tui.isCancelled()) { + + return 0; } - cout << endl; + cout << searchTerm << "," << searchingFor << endl; + + // vector instances = getInstances(); + // for (auto i: instances) { + // cout << i << " "; + // } + // cout << endl; } \ No newline at end of file diff --git a/src/tui.cpp b/src/tui.cpp index 99e61f9..8356c81 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component.hpp" // for Input, Renderer, Vertical @@ -8,32 +10,65 @@ #include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border #include "ftxui/util/ref.hpp" // for Ref +#include "tui.hpp" + using namespace std; -string renderSearchBar() { +bool Tui::renderSearchBar(string& searchTerm, int& searchingFor) { 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 - }); + vector searchingForOptions = { "Videos", "Channels", "Playlists" }; + ftxui::Component selectSearchFor = ftxui::Toggle(&searchingForOptions, &searchingFor); + + string cancelLabel = "Cancel"; + ftxui::Component cancelButton = ftxui::Button(&cancelLabel, screen.ExitLoopClosure()); + string searchLabel = "Search"; + ftxui::Component searchButton = ftxui::Button(&searchLabel, screen.ExitLoopClosure()); + + ftxui::Component component = ftxui::Container::Vertical({ + inputSearchTerm, + selectSearchFor, + cancelButton, + searchButton + }); + auto renderer = ftxui::Renderer(component, [&] { return ftxui::vbox({ - ftxui::text(" YTCCP "), - ftxui::separator(), - ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()), - }) | - ftxui::border; + ftxui::text(" YTCCP "), + ftxui::separator(), + ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()), + ftxui::separator(), + ftxui::hbox(ftxui::text(" Search For: "), selectSearchFor->Render()), + ftxui::separator(), + ftxui::hbox({ + cancelButton->Render() | + ftxui::size(ftxui::WIDTH, ftxui::LESS_THAN, 20), + ftxui::filler(), + searchButton->Render() | + ftxui::size(ftxui::WIDTH, ftxui::LESS_THAN, 20), + }), + }) | ftxui::border; }); screen.Loop(renderer); - return searchTerm; + return true; +} + +bool Tui::isCancelled() { + + return cancel; +} + +void Tui::cancelAndExit(ftxui::ScreenInteractive& screen) { + + cancel = true; + screen.ExitLoopClosure(); } \ No newline at end of file diff --git a/src/tui.hpp b/src/tui.hpp index df9433c..af4d24c 100644 --- a/src/tui.hpp +++ b/src/tui.hpp @@ -1,8 +1,23 @@ -#ifndef tui -#define tui -#include "tui.cpp" +#ifndef Tui +#define Tui #include +#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 + +class Tui { + public: + bool renderSearchBar(std::string&, int&); + bool isCancelled(); + private: + void cancelAndExit(ftxui::ScreenInteractive&); + bool cancel; + +}; -std::string renderSearchBar(); #endif \ No newline at end of file -- cgit 1.4.1-2-gfad0