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 --- CMakeLists.txt | 15 ++++++++- LICENSE | 9 ------ LICENSE.txt | 9 ++++++ include/YtdlpWrapper.hpp | 20 ++++++++++++ include/invapi.hpp | 27 ++++++++++++++++ include/sqliteinterface.hpp | 21 ++++++++++++ include/tui.hpp | 23 +++++++++++++ include/video.hpp | 79 +++++++++++++++++++++++++++++++++++++++++++++ src/YtdlpWrapper.hpp | 20 ------------ src/invapi.hpp | 27 ---------------- src/main.cpp | 12 +++---- src/sqliteinterface.hpp | 21 ------------ src/tui.hpp | 23 ------------- src/video.hpp | 61 ---------------------------------- 14 files changed, 199 insertions(+), 168 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE.txt 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 delete mode 100644 src/YtdlpWrapper.hpp delete mode 100644 src/invapi.hpp delete mode 100644 src/sqliteinterface.hpp delete mode 100644 src/tui.hpp delete mode 100644 src/video.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e3f249..033e0b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,12 @@ project(ytcpp HOMEPAGE_URL https://crow.port0.org/git/comradecrow/ytcpp.git ) +if(PROJECT_IS_TOP_LEVEL) + include(CTest) + enable_testing() +endif() +# set(PROJECT_SOURCE_DIR "src") +set(PROJECT_INCLUDE_DIR "include") set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) @@ -57,7 +63,7 @@ add_executable(${PROJECT_NAME} src/video.cpp ) -target_include_directories(${PROJECT_NAME} PRIVATE src) +target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE_DIR}) target_compile_definitions(${PROJECT_NAME} PRIVATE DEF_APPDATA="${DEF_APPDATA}" @@ -74,3 +80,10 @@ target_link_libraries(${PROJECT_NAME} PRIVATE SQLite::SQLite3 PRIVATE pybind11::embed ) + +# set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +# set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_VENDOR "ComradeCrow") +set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE.txt) +set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md) +include(CPack) \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 11c45b7..0000000 --- a/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) 2023 comradecrow - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..11c45b7 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 comradecrow + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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 diff --git a/src/YtdlpWrapper.hpp b/src/YtdlpWrapper.hpp deleted file mode 100644 index 9ee2410..0000000 --- a/src/YtdlpWrapper.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#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/src/invapi.hpp b/src/invapi.hpp deleted file mode 100644 index 3fb4c05..0000000 --- a/src/invapi.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#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/src/main.cpp b/src/main.cpp index 1bac482..ea955f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,11 +18,11 @@ #include #endif -#include "tui.hpp" -#include "video.hpp" -#include "invapi.hpp" -#include "YtdlpWrapper.hpp" -#include "sqliteinterface.hpp" +#include +#include +#include +#include +#include // namespace py = pybind11; @@ -137,7 +137,7 @@ int main(int argc, char **argv) { // validateStructConversions(); parseSysArgs(argc, argv); - // SqliteInterface sqldb; + SqliteInterface sqldb; // InvidiousApi invapi("https://httpbin.org/get"); // invapi.test(); } \ No newline at end of file diff --git a/src/sqliteinterface.hpp b/src/sqliteinterface.hpp deleted file mode 100644 index cc4adb4..0000000 --- a/src/sqliteinterface.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#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/src/tui.hpp b/src/tui.hpp deleted file mode 100644 index 112135c..0000000 --- a/src/tui.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#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/src/video.hpp b/src/video.hpp deleted file mode 100644 index fd57d0b..0000000 --- a/src/video.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef VIDEO_H -#define VIDEO_H -#include -#include -#include -#include - -namespace Video { - - struct format { - - std::string format; - std::string url; - std::string vcodec; - std::string acodec; - std::string ext; - std::optional quality; - std::optional resolution; - std::optional height; - std::optional width; - }; - - struct thumbnail { - - std::string url; - int preference; - std::string id; - std::optional resolution; - std::optional height; - std::optional width; - }; - - 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 1.4.1-2-gfad0