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 --- .gitmodules | 4 ++++ CMakeLists.txt | 11 +++++++--- extern/pybind11 | 1 + src/YtdlpWrapper.cpp | 21 +++++++++++++++++++ src/YtdlpWrapper.hpp | 17 ++++++++++++++++ src/main.cpp | 22 ++++++++++++++------ src/tui.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++---------- src/tui.hpp | 23 +++++++++++++++++---- 8 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 .gitmodules create mode 160000 extern/pybind11 create mode 100644 src/YtdlpWrapper.cpp create mode 100644 src/YtdlpWrapper.hpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7d822b4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "extern/pybind11"] + path = extern/pybind11 + url = https://github.com/pybind/pybind11 + branch = stable diff --git a/CMakeLists.txt b/CMakeLists.txt index 4500127..bf5b4da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.26.0) project(ytcpp LANGUAGES CXX VERSION 0.0.1 + HOMEPAGE_URL https://crow.port0.org/git/comradecrow/ytcpp.git ) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) @@ -15,11 +16,10 @@ endif() include(FetchContent) FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git GIT_TAG c4713a704ca12237485ecbfec185f76c2a81bd09) -FetchContent_MakeAvailable(cpr) FetchContent_Declare(ftxui GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui.git - GIT_TAG v4.0.0 + GIT_TAG d301fab1f4ecdd3544ed99b9c98e647d5804c341 ) FetchContent_GetProperties(ftxui) @@ -29,10 +29,14 @@ if(NOT ftxui_POPULATED) endif() FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz) -FetchContent_MakeAvailable(json) + +FetchContent_MakeAvailable(json cpr) find_package(SQLite3 REQUIRED) +# find_package(pybind11 REQUIRED) +add_subdirectory(extern/pybind11) + add_executable(${PROJECT_NAME} src/main.cpp) target_include_directories(${PROJECT_NAME} PRIVATE src) @@ -43,4 +47,5 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ftxui::component PRIVATE nlohmann_json::nlohmann_json PRIVATE SQLite::SQLite3 + PRIVATE pybind11::embed ) diff --git a/extern/pybind11 b/extern/pybind11 new file mode 160000 index 0000000..be97c5a --- /dev/null +++ b/extern/pybind11 @@ -0,0 +1 @@ +Subproject commit be97c5a98b4b252c524566f508b5c79410d118c6 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