diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3749ae7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,8 @@ +# Google C/C++ Code Style Settings + +Language: Cpp +BasedOnStyle: Google +Standard: c++20 +IndentWidth: 2 +UseTab: Never +ColumnLimit: 80 \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 7bc07ec..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Environment-dependent path to Maven home directory -/mavenHomeManager.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/BumbleCee.iml b/.idea/BumbleCee.iml deleted file mode 100644 index d6ebd48..0000000 --- a/.idea/BumbleCee.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 31e1ebc..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 75bf592..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index ab4cd9e..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**", - "${workspaceFolder}/include" - ], - "defines": [ - "DDPP_CORO=on" - ], - "compilerPath": "/usr/bin/gcc", - "cStandard": "c17", - "cppStandard": "c++20", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index a238240..4317700 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,29 +1,32 @@ { + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "name": "Debug", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/build/BumbleCee", - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } - ], - "preLaunchTask": "${defaultBuildTask}" - } + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/Debug Clang 18.1.3 x86_64-pc-linux-gnu/tests/${fileBasenameNoExtension}", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index cdc8dc4..388d3b0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,16 @@ { - "C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json", + "editor.rulers": [ + { + "column": 80 + } + ], + "cmake.generator": "Ninja", "files.associations": { "cctype": "cpp", "clocale": "cpp", "cmath": "cpp", + "csetjmp": "cpp", + "csignal": "cpp", "cstdarg": "cpp", "cstddef": "cpp", "cstdio": "cpp", @@ -12,37 +19,53 @@ "ctime": "cpp", "cwchar": "cpp", "cwctype": "cpp", + "any": "cpp", "array": "cpp", "atomic": "cpp", + "strstream": "cpp", + "barrier": "cpp", "bit": "cpp", "bitset": "cpp", + "cfenv": "cpp", "charconv": "cpp", "chrono": "cpp", + "cinttypes": "cpp", + "codecvt": "cpp", "compare": "cpp", + "complex": "cpp", "concepts": "cpp", "condition_variable": "cpp", + "coroutine": "cpp", "cstdint": "cpp", "deque": "cpp", "forward_list": "cpp", "list": "cpp", "map": "cpp", + "set": "cpp", "string": "cpp", "unordered_map": "cpp", + "unordered_set": "cpp", "vector": "cpp", "exception": "cpp", + "expected": "cpp", "algorithm": "cpp", "functional": "cpp", "iterator": "cpp", "memory": "cpp", "memory_resource": "cpp", + "numeric": "cpp", "optional": "cpp", "random": "cpp", "ratio": "cpp", + "regex": "cpp", + "source_location": "cpp", "string_view": "cpp", "system_error": "cpp", "tuple": "cpp", "type_traits": "cpp", "utility": "cpp", + "rope": "cpp", + "slist": "cpp", "format": "cpp", "fstream": "cpp", "future": "cpp", @@ -51,20 +74,39 @@ "iosfwd": "cpp", "iostream": "cpp", "istream": "cpp", + "latch": "cpp", "limits": "cpp", "mutex": "cpp", "new": "cpp", + "numbers": "cpp", "ostream": "cpp", + "ranges": "cpp", + "scoped_allocator": "cpp", "semaphore": "cpp", "shared_mutex": "cpp", + "span": "cpp", + "spanstream": "cpp", "sstream": "cpp", + "stacktrace": "cpp", "stdexcept": "cpp", + "stdfloat": "cpp", "stop_token": "cpp", "streambuf": "cpp", + "syncstream": "cpp", "thread": "cpp", + "typeindex": "cpp", "typeinfo": "cpp", + "valarray": "cpp", "variant": "cpp", - "__config": "cpp", - "rope": "cpp" + "__locale": "cpp", + "ios": "cpp", + "locale": "cpp", + "print": "cpp" + }, + "files.exclude": { + "**/*.rpyc": true, + "**/*.rpa": true, + "**/*.rpymc": true, + "**/cache/": true } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 5dc67cf..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - - "version": "2.0.0", - "tasks": [ - { - "type": "cppbuild", - "label": "ninja", - "command": "ninja", - "args": [], - "options": { - "cwd": "${workspaceFolder}/build/" - }, - "group": { - "kind": "build", - "isDefault": true - }, - "dependsOn": ["cmake"] - }, - { - "type": "shell", - "label": "cmake", - "command": "cmake", - "args": [ - "..", - "-G", - "Ninja" - ], - "options": { - "cwd": "${workspaceFolder}/build/" - }, - "group": { - "kind": "build", - "isDefault": false - } - }, - ] -} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ca6c244..a5e3a1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,12 +2,17 @@ cmake_minimum_required (VERSION 3.16) set(BOT_NAME "BumbleCee") project(${BOT_NAME} LANGUAGES CXX) -set(CMAKE_BUILD_TYPE Debug) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(BOOST_EXCLUDE_LIBRARIES nowide) +set(BUILD_TESTING ON) + +set(DPP_BUILD_TEST OFF) + +enable_testing() if(WIN32) set(OPENSSL_ROOT_DIR "C:/Program Files/OpenSSL-Win64") @@ -26,14 +31,15 @@ find_package(OpenSSL REQUIRED) include(FetchContent) +set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS}) + FetchContent_Declare( Boost URL "https://github.com/boostorg/boost/releases/download/boost-1.89.0/boost-1.89.0-cmake.7z" DOWNLOAD_EXTRACT_TIMESTAMP ON - CMAKE_ARGS - -DBOOST_USE_STATIC_LIBS=ON - -DBOOST_USE_STATIC_RUNTIME=ON + EXCLUDE_FROM_ALL ) +set(BUILD_SHARED_LIBS OFF CACHE BOOL "Do not build SHARED libraries" FORCE) message(STATUS "Fetching and making available Boost...") FetchContent_MakeAvailable(Boost) @@ -42,11 +48,13 @@ FetchContent_Declare( GIT_REPOSITORY "https://github.com/brainboxdotcc/DPP.git" GIT_TAG "v10.1.3" GIT_SHALLOW ON - CMAKE_ARGS -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=ON ) +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build SHARED libraries" FORCE) message(STATUS "Fetching and making available dpp...") FetchContent_MakeAvailable(dpp) +set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_OLD} CACHE BOOL "Type of libraries to build" FORCE) + # ------------------------------------------------------------- # 플랫폼별 FFmpeg 바이너리 다운로드 및 링크 # ------------------------------------------------------------- @@ -84,41 +92,42 @@ find_library(AVUTIL_LIBRARY NAMES avutil PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT message(STATUS "AVUTIL_LIBRARY = ${AVUTIL_LIBRARY}") find_library(SWSCALE_LIBRARY NAMES swscale PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH) message(STATUS "SWSCALE_LIBRARY = ${SWSCALE_LIBRARY}") +find_library(SWRESAMPLE_LIBRARY NAMES swresample PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH) +message(STATUS "SWRESAMPLE_LIBRARY = ${SWRESAMPLE_LIBRARY}") -if(NOT AVCODEC_LIBRARY OR NOT AVFORMAT_LIBRARY OR NOT AVUTIL_LIBRARY) +if(NOT AVCODEC_LIBRARY OR NOT AVFORMAT_LIBRARY OR NOT AVUTIL_LIBRARY OR NOT SWRESAMPLE_LIBRARY) message(FATAL_ERROR "FFmpeg 라이브러리를 찾을 수 없습니다. 다운로드 경로를 확인해주세요.") endif() -file(GLOB_RECURSE CORES "src/*.cpp" "src/*.cxx" "src/*.cc") +file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.cxx" "src/*.cc") -set(ALL_SOURCE_FILES - ${CORES} - ${AUDIO_SOURCES} - ${COMMANDS_SOURCES} - ${QUEUE_SOURCES} - ${SETTINGS_SOURCES} - ${UTILS_SOURCES} -) +add_library(${BOT_NAME}_lib ${SOURCES}) -add_executable(${BOT_NAME} ${ALL_SOURCE_FILES}) +target_include_directories(${BOT_NAME}_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_link_libraries(${BOT_NAME} PRIVATE dpp) -target_link_libraries(${BOT_NAME} PRIVATE Boost::filesystem) -target_link_libraries(${BOT_NAME} PRIVATE Boost::process) -target_link_libraries(${BOT_NAME} PRIVATE Boost::log) -target_link_libraries(${BOT_NAME} PRIVATE Boost::beast) -target_link_libraries(${BOT_NAME} PRIVATE OpenSSL::Crypto) -target_link_libraries(${BOT_NAME} PRIVATE OpenSSL::SSL) -target_link_libraries(${BOT_NAME} PRIVATE ${AVUTIL_LIBRARY}) -target_link_libraries(${BOT_NAME} PRIVATE ${AVCODEC_LIBRARY}) -target_link_libraries(${BOT_NAME} PRIVATE ${AVFORMAT_LIBRARY}) -target_link_libraries(${BOT_NAME} PRIVATE ${SWSCALE_LIBRARY}) +target_include_directories(${BOT_NAME}_lib PUBLIC ${OpenSSL_INCLUDE_DIRS}) +target_include_directories(${BOT_NAME}_lib PUBLIC ${FFMPEG_INCLUDE_PATH}) + +target_precompile_headers(${BOT_NAME}_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/precomp.h") + +target_link_libraries(${BOT_NAME}_lib PUBLIC dpp) +target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::filesystem) +target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::process) +target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::log) +target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::beast) +target_link_libraries(${BOT_NAME}_lib PUBLIC OpenSSL::Crypto) +target_link_libraries(${BOT_NAME}_lib PUBLIC OpenSSL::SSL) +target_link_libraries(${BOT_NAME}_lib PUBLIC ${AVUTIL_LIBRARY}) +target_link_libraries(${BOT_NAME}_lib PUBLIC ${AVCODEC_LIBRARY}) +target_link_libraries(${BOT_NAME}_lib PUBLIC ${AVFORMAT_LIBRARY}) +target_link_libraries(${BOT_NAME}_lib PUBLIC ${SWSCALE_LIBRARY}) +target_link_libraries(${BOT_NAME}_lib PUBLIC ${SWRESAMPLE_LIBRARY}) if(WIN32) - target_link_libraries(${BOT_NAME} PRIVATE ws2_32) + target_link_libraries(${BOT_NAME}_lib PUBLIC ws2_32) endif() -if(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release") - set_target_properties(${PROJECT_NAME} PROPERTIES +if(UNIX AND NOT APPLE) + set_target_properties(${BOT_NAME}_lib PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH "$ORIGIN" SKIP_BUILD_RPATH FALSE @@ -126,16 +135,29 @@ if(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release") ) endif() -target_include_directories(${BOT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +add_executable(${BOT_NAME} ${SOURCES}) -target_include_directories(${BOT_NAME} PRIVATE ${OpenSSL_INCLUDE_DIRS}) -target_include_directories(${BOT_NAME} PRIVATE ${FFMPEG_INCLUDE_PATH}) +target_link_libraries(${BOT_NAME} PUBLIC ${BOT_NAME}_lib) -target_precompile_headers(${BOT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/precomp.h") +file(GLOB FFMPEG_SHARED + "${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/bin/*.dll" # Windows + "${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/lib/*.so*" # Linux +) + +foreach(ffmpeg_shared ${FFMPEG_SHARED}) + add_custom_command(TARGET ${BOT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${ffmpeg_shared}" + "$" + COMMENT "Copying ${ffmpeg_shared} to output directory" + ) +endforeach() add_custom_command(TARGET ${BOT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/bin" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$" "$" - COMMENT "Copying FFMpeg_AVCODEC DLL/so files to output directory" -) \ No newline at end of file + COMMENT "Copying dpp DLL/so files to output directory" +) + +add_subdirectory(tests) \ No newline at end of file diff --git a/src/main.cc b/src/main.cc index 7ad2377..d174a8f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -4,51 +4,7 @@ int main(int argc, char* argv[]) { boost::asio::io_context ctx; - boost::system::error_code ec; - char buf[8192]; - std::string output; - utils::CheckUpdate(ctx); -#ifdef WIN32 - /*try { - auto ytdlp_pipe = utils::OpenPipe(ctx, - "yt-dlp.exe", { "-o", "-", "--quiet", "--ignore-errors", "-f", - "bestaudio", "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" }); - - while (true) { - boost::system::error_code read_ec; - size_t bytes_read = - boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, - 8192), read_ec); if (bytes_read > 0) { std::cout.write(buf, bytes_read); - } - if (read_ec == boost::asio::error::eof || read_ec) { - break; - } - } - } - catch (const boost::process::system_error& e) { - std::string error = e.what(); - return -1; - }*/ -#else - auto ytdlp_pipe = utils::OpenPipe( - ctx, "yt-dlp", - {"-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio", - "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR"}); - - while (true) { - boost::system::error_code read_ec; - size_t bytes_read = - boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192), read_ec); - if (bytes_read > 0) { - std::cout.write(buf, bytes_read); - } - if (read_ec == boost::asio::error::eof || read_ec) { - break; - } - } -#endif - return 0; } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..385b020 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,8 @@ +file(GLOB_RECURSE TEST_SOURCES "*.cpp" "*.cxx" "*.cc") + +foreach(test_src ${TEST_SOURCES}) + get_filename_component(test_name ${test_src} NAME_WE) + add_executable(${test_name} ${test_src}) + target_link_libraries(${test_name} PRIVATE ${BOT_NAME}_lib) + add_test(NAME ${test_name} COMMAND ${test_name}) +endforeach() \ No newline at end of file diff --git a/tests/basic_yt_dlp_download.cc b/tests/basic_yt_dlp_download.cc new file mode 100644 index 0000000..de4f5f9 --- /dev/null +++ b/tests/basic_yt_dlp_download.cc @@ -0,0 +1,52 @@ +#include "precomp.h" +#include "utils/console.h" +#include "utils/update_checker.h" + +int main() { + boost::asio::io_context ctx; + boost::system::error_code ec; + + utils::CheckUpdate(ctx); + + char buf[8192]; +#ifdef WIN32 + /*try { + auto ytdlp_pipe = utils::OpenPipe(ctx, + "yt-dlp.exe", { "-o", "-", "--quiet", "--ignore-errors", "-f", + "bestaudio", "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" }); + + while (true) { + boost::system::error_code read_ec; + size_t bytes_read = + boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, + 8192), read_ec); if (bytes_read > 0) { std::cout.write(buf, bytes_read); + } + if (read_ec == boost::asio::error::eof || read_ec) { + break; + } + } + } + catch (const boost::process::system_error& e) { + std::string error = e.what(); + return -1; + }*/ +#else + auto ytdlp_pipe = utils::OpenPipe( + ctx, "yt-dlp", + {"-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio", + "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR"}); + + while (true) { + boost::system::error_code read_ec; + size_t bytes_read = + boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192), read_ec); + if (bytes_read > 0) { + std::cout.write(buf, bytes_read); + } + if (read_ec == boost::asio::error::eof || read_ec) { + break; + } + } +#endif + return 0; +} \ No newline at end of file diff --git a/tests/update.cc b/tests/update.cc new file mode 100644 index 0000000..0d71c38 --- /dev/null +++ b/tests/update.cc @@ -0,0 +1,8 @@ +#include "precomp.h" +#include "utils/update_checker.h" + +int main() { + boost::asio::io_context ctx; + utils::CheckUpdate(ctx); + return 0; +} \ No newline at end of file diff --git a/yt-dlp b/yt-dlp deleted file mode 100755 index daca82b..0000000 Binary files a/yt-dlp and /dev/null differ