about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
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
n class='oid'>7f98e013 ^
c6ff761a ^


a48b9fce ^
c6ff761a ^

7f98e013 ^
c6ff761a ^


d9f5a2bd ^
c6ff761a ^

c6ff761a ^
7f98e013 ^
c6ff761a ^


a48b9fce ^

c6ff761a ^
7f98e013 ^
c6ff761a ^


a48b9fce ^

c6ff761a ^
7f98e013 ^
c6ff761a ^







a48b9fce ^
c6ff761a ^

7f98e013 ^
c6ff761a ^


a48b9fce ^
c6ff761a ^

7f98e013 ^
c6ff761a ^


d9f5a2bd ^
c6ff761a ^

c6ff761a ^
7f98e013 ^
c6ff761a ^




7f98e013 ^
c6ff761a ^



a48b9fce ^
c6ff761a ^

c6ff761a ^
7f98e013 ^
c6ff761a ^







a48b9fce ^
c6ff761a ^

7f98e013 ^
c6ff761a ^


a48b9fce ^
c6ff761a ^

7f98e013 ^
c6ff761a ^



a48b9fce ^
c6ff761a ^

7f98e013 ^
c6ff761a ^


d9f5a2bd ^
c6ff761a ^

c6ff761a ^
7f98e013 ^
c6ff761a ^




7f98e013 ^
c6ff761a ^


a48b9fce ^
c6ff761a ^

c6ff761a ^
7f98e013 ^
c6ff761a ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207