aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorComradeCrow <comradecrow@vivaldi.net>2023-05-17 16:05:13 -0700
committerComradeCrow <comradecrow@vivaldi.net>2023-05-17 16:05:13 -0700
commit8b4fa2a3b6b1a3d75fd4ae5a61266e159d22e095 (patch)
tree6bc2c757656071d39b840f6a0db27c53b33eedd5 /include
parent8972e4b0fdc216bf4ea1c0f7e699689d6c84de6a (diff)
downloadytcpp-8b4fa2a3b6b1a3d75fd4ae5a61266e159d22e095.tar.gz
Changes
Start Documenting, add more cpack stuff
Diffstat (limited to 'include')
-rw-r--r--include/YtdlpWrapper.hpp20
-rw-r--r--include/invapi.hpp27
-rw-r--r--include/sqliteinterface.hpp21
-rw-r--r--include/tui.hpp23
-rw-r--r--include/video.hpp79
5 files changed, 170 insertions, 0 deletions
diff --git a/include/YtdlpWrapper.hpp b/include/YtdlpWrapper.hpp
new file mode 100644
index 0000000..9ee2410
--- /dev/null
+++ b/include/YtdlpWrapper.hpp
@@ -0,0 +1,20 @@
+#ifndef YTDLPWRAPPER_H
+#define YTDLPWRAPPER_H
+#include <string>
+#include <vector>
+#include <iostream>
+#include <pybind11/embed.h>
+#include <nlohmann/json.hpp>
+
+class YtdlpWrapper {
+
+ public:
+ nlohmann::json getJsonSearch(const std::string& searchTerm, int limit = 1);
+ Video::video getVideoByUrl(const std::string& url);
+ std::vector<Video::video> searchVideos(const std::string& searchterm, int limit = 1);
+ private:
+ pybind11::object get_ytdl();
+};
+
+
+#endif \ No newline at end of file
diff --git a/include/invapi.hpp b/include/invapi.hpp
new file mode 100644
index 0000000..3fb4c05
--- /dev/null
+++ b/include/invapi.hpp
@@ -0,0 +1,27 @@
+#ifndef INVAPI_H
+#define INVAPI_H
+#include <string>
+#include <vector>
+#include <cpr/cpr.h>
+
+#include "sqliteinterface.hpp"
+
+class InvidiousApi {
+
+ public:
+
+ InvidiousApi(const std::string& url);
+ static std::vector<std::string> getInstances();
+ static void saveInstancesToDb(SqliteInterface& sqldb);
+ std::string getInstance();
+ void setInstance(const std::string& newUrl);
+
+ void test();
+ private:
+
+ std::string instanceUrl;
+ cpr::Session session;
+};
+
+
+#endif \ No newline at end of file
diff --git a/include/sqliteinterface.hpp b/include/sqliteinterface.hpp
new file mode 100644
index 0000000..cc4adb4
--- /dev/null
+++ b/include/sqliteinterface.hpp
@@ -0,0 +1,21 @@
+#ifndef SQLITEINTERFACE_H
+#define SQLITEINTERFACE_H
+#include <string>
+#include <sqlite3.h>
+#include "video.hpp"
+
+class SqliteInterface {
+
+ public:
+ SqliteInterface();
+ ~SqliteInterface();
+ void openDB();
+ void closeDB();
+ void createTables();
+ void saveVideo(const Video::video&);
+ void saveInstance(const std::string& uri, float health, const std::string& location);
+ private:
+ sqlite3* db;
+};
+
+#endif \ No newline at end of file
diff --git a/include/tui.hpp b/include/tui.hpp
new file mode 100644
index 0000000..112135c
--- /dev/null
+++ b/include/tui.hpp
@@ -0,0 +1,23 @@
+#ifndef TUI_H
+#define TUI_H
+#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:
+ ftxui::Closure cancelAndExit(ftxui::ScreenInteractive&);
+ bool cancel{false};
+
+};
+
+
+#endif \ No newline at end of file
diff --git a/include/video.hpp b/include/video.hpp
new file mode 100644
index 0000000..456eda9
--- /dev/null
+++ b/include/video.hpp
@@ -0,0 +1,79 @@
+#ifndef VIDEO_H
+#define VIDEO_H
+#include <string>
+#include <optional>
+#include <vector>
+#include <nlohmann/json.hpp>
+
+
+///
+/// \brief Video namespace.
+/// Contains the format, thumbnail, and video structs.
+///
+namespace Video {
+
+ ///
+ /// \brief Format structure.
+ /// This saves a video format, with the necessary url and information.
+ ///
+ struct format {
+
+ std::string format; /**< Name of the format provided by Youtube */
+ std::string url;
+ std::string vcodec;
+ std::string acodec;
+ std::string ext; /**< File Extention */
+ std::optional<float> quality;
+ std::optional<std::string> resolution;
+ std::optional<int> height;
+ std::optional<int> width;
+ };
+
+ ///
+ /// \brief Thumbnail structure.
+ /// This saves a video thumbnail, with the necessary url and information.
+ ///
+ struct thumbnail {
+
+ std::string url;
+ int preference; /**< The lower the prefrence, the worse the quality */
+ std::string id;
+ std::optional<std::string> resolution;
+ std::optional<int> height;
+ std::optional<int> width;
+ };
+
+ ///
+ /// \brief Video structure.
+ /// The video structure will be used to store video objects, and will be used to
+ /// save to DB, and as a common format between invidious.io and yt-dlp.
+ ///
+ struct video {
+
+ std::string id;
+ std::string title;
+ std::string url;
+ std::string channelId;
+ std::string channelUrl;
+ std::vector<format> formats;
+ std::vector<thumbnail> thumbnails;
+ std::optional<std::string> uploader;
+ std::optional<std::string> uploaderId;
+ std::optional<std::string> uploaderUrl;
+ std::optional<int> duration;
+ std::optional<int> viewcount;
+ std::optional<std::string> description;
+ };
+
+ void to_json(nlohmann::json& j, const format& f);
+ void to_json(nlohmann::json& j, const std::vector<format>& v);
+ void to_json(nlohmann::json& j, const thumbnail& t);
+ void to_json(nlohmann::json& j, const std::vector<thumbnail>& v);
+ void to_json(nlohmann::json& j, const video& v);
+ void from_json(const nlohmann::json& j, format& f);
+ void from_json(const nlohmann::json& j, std::vector<format>& v);
+ void from_json(const nlohmann::json& j, thumbnail& t);
+ void from_json(const nlohmann::json& j, std::vector<thumbnail>& v);
+ void from_json(const nlohmann::json& j, video& v);
+};
+#endif \ No newline at end of file