about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-04-12 14:32:15 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-04-12 14:32:15 -0700
commit9d53072e32c60aa51784182a0a608ce204cab9e6 (patch)
tree4b547c106f0cb015533b839f6f1cfa81693f5e3b /src
parent63bfecda26d87c7d09691a0b479883a4eb26bf1e (diff)
downloadytcpp-9d53072e32c60aa51784182a0a608ce204cab9e6.tar.gz
breaking changes
broke everything
Diffstat (limited to 'src')
-rw-r--r--src/YtdlpWrapper.cpp21
-rw-r--r--src/YtdlpWrapper.hpp17
-rw-r--r--src/main.cpp22
-rw-r--r--src/tui.cpp57
-rw-r--r--src/tui.hpp23
5 files changed, 119 insertions, 21 deletions
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 <string>
+#include <pybind11/embed.h>
+#include <nlohmann/json.hpp>
+
+#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<std::string>());
+}
+
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 <string>
+#include <pybind11/embed.h>
+#include <nlohmann/json.hpp>
+
+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 <exception>
 #include <vector>
 
-#include "tui.hpp"
+#include "tui.cpp"
 #include "invapi.hpp"
+#include "YtdlpWrapper.hpp"
 
 
 using namespace std;
 
 int main() {
 
-    
-    vector<string> 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<string> 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 <string>
+#include <memory> 
+#include <vector>
 
 #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<string> 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 <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
+
+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