From 8b4fa2a3b6b1a3d75fd4ae5a61266e159d22e095 Mon Sep 17 00:00:00 2001 From: ComradeCrow Date: Wed, 17 May 2023 16:05:13 -0700 Subject: Changes Start Documenting, add more cpack stuff --- include/YtdlpWrapper.hpp | 20 ++++++++++++ include/invapi.hpp | 27 ++++++++++++++++ include/sqliteinterface.hpp | 21 ++++++++++++ include/tui.hpp | 23 +++++++++++++ include/video.hpp | 79 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 170 insertions(+) create mode 100644 include/YtdlpWrapper.hpp create mode 100644 include/invapi.hpp create mode 100644 include/sqliteinterface.hpp create mode 100644 include/tui.hpp create mode 100644 include/video.hpp (limited to 'include') 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 +#include +#include +#include +#include + +class YtdlpWrapper { + + public: + nlohmann::json getJsonSearch(const std::string& searchTerm, int limit = 1); + Video::video getVideoByUrl(const std::string& url); + std::vector 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 +#include +#include + +#include "sqliteinterface.hpp" + +class InvidiousApi { + + public: + + InvidiousApi(const std::string& url); + static std::vector 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 +#include +#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 +#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 +#include +#include +#include + + +/// +/// \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 quality; + std::optional resolution; + std::optional height; + std::optional 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 resolution; + std::optional height; + std::optional 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 formats; + std::vector thumbnails; + std::optional uploader; + std::optional uploaderId; + std::optional uploaderUrl; + std::optional duration; + std::optional viewcount; + std::optional description; + }; + + void to_json(nlohmann::json& j, const format& f); + void to_json(nlohmann::json& j, const std::vector& v); + void to_json(nlohmann::json& j, const thumbnail& t); + void to_json(nlohmann::json& j, const std::vector& 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& v); + void from_json(const nlohmann::json& j, thumbnail& t); + void from_json(const nlohmann::json& j, std::vector& v); + void from_json(const nlohmann::json& j, video& v); +}; +#endif \ No newline at end of file -- cgit