39 Commits

Author SHA1 Message Date
b123b2ecdb 테스트 구조 완성, 코딩 스타일 교정 기능 추가 쓸데없는 설정파일들 정리 2025-09-01 02:29:37 +09:00
e26d20a869 스타일 정리 및 컴파일 오류 제거 2025-08-31 02:29:42 +09:00
f3974bb86f 쓸데없는 공유 라이브러리 제거 및 콘솔 실행 커맨드 안정화 2025-08-31 02:22:36 +09:00
f846dd7195 Merge branch 'refactor' of github.com:HappyTanuki/BumbleCee into refactor 2025-08-30 02:53:11 +09:00
0bff043d6e ytdlp 자동 다운로드 및 업데이트 로직 구현 2025-08-30 02:51:58 +09:00
7b75fc8861 윈도우 빌드용 매크로 추가 2025-08-29 05:56:36 +09:00
177221bf73 리눅스 빌드 성공 2025-08-29 05:53:47 +09:00
51a49a4470 ffmpeg 부를 때 무조건 extern c 하기... 2025-08-29 05:44:56 +09:00
a2821394bd 일단 빌드 되니 좋았쓰! 2025-08-29 04:53:35 +09:00
a03ed2dc78 정리 중.. 2025-08-28 21:34:21 +09:00
c59fef1d0b 일단 저장 2025-08-28 20:46:37 +09:00
125fbcc49c TODO 추가가 2025-03-09 17:29:09 +09:00
4915a5c3b8 TODO리스트는 늘어만 간다.. 2025-03-09 17:27:42 +09:00
4435337f40 TODO 추가가 2025-03-07 17:25:58 +09:00
77d16c1cdb 아마도? 쉘 인젝션 취약점 픽스 2025-03-07 17:19:58 +09:00
5760f1afdc todo 추가가 2025-02-13 17:42:17 +09:00
bb6cd89f51 Update README.md 2025-02-13 17:31:17 +09:00
2a238f804d 사람 나갈 때 음악 꺼지는 문제 해결결 2025-02-13 17:22:42 +09:00
ea7d42638e 코드 리팩터링 중.. 2025-02-13 17:18:03 +09:00
30f97e3dfb 3차 코드 리팩터터 2025-02-13 17:01:38 +09:00
17236f32b5 도커파일 이미지 크기최적화 2025-02-13 16:54:10 +09:00
00134ee7b1 2차 리팩터터 2025-02-13 16:50:03 +09:00
52146c1f6a 코드 가독성 리팩터 2025-02-13 16:43:11 +09:00
bf0268c1e9 Merge branch 'master' of github.com:HappyTanuki/BumbleCee 2025-02-03 01:42:06 +09:00
2f5185e0c3 큐 출력 스타일 변경 2025-02-03 01:42:02 +09:00
96a4096971 Update README.md 2025-02-03 01:32:55 +09:00
ec65b550e6 Update README.md 2025-02-03 01:32:19 +09:00
14db2a31e8 와 이제 진짜 진짜 버그 다 고친 듯? 2025-02-02 23:55:47 +09:00
1af829c711 Merge branch 'master' of github.com:HappyTanuki/BumbleCee 2025-02-02 07:51:56 +09:00
46c59d40de 도커허브 업로드 자동화 구현 2025-02-02 07:51:52 +09:00
b08641f87e Update README.md 2025-02-02 07:10:21 +09:00
1ca928c4df Update README.md 2025-02-02 07:09:57 +09:00
2935a844a0 아직 read loop ended는 못잡았지만 아무튼 완성(진) 일단 셔플 빼그 기능은 다 작동하니 된 게 아닐까? 2025-02-02 06:37:31 +09:00
0cb7ea8225 완성(준) 2025-02-01 23:50:49 +09:00
7e43900f22 스트리밍 구현 끝 2025-02-01 03:36:31 +09:00
c2cb16c6d7 일단은 임시저장, 스트리밍의 실마리를 잡았다 2025-01-30 22:57:01 +09:00
3186561818 임시저장 2025-01-30 01:11:26 +09:00
30569f4472 비동기 다운로드 구현 완료 2024-10-19 05:06:21 +09:00
b4476c68d7 중간저장(다시 큐 방식으로 돌아가되, 실시간 스트리밍 방식으로 비동기 처리를 구현할 것임) 2024-10-19 01:12:19 +09:00
51 changed files with 749 additions and 1320 deletions

8
.clang-format Normal file
View File

@@ -0,0 +1,8 @@
# Google C/C++ Code Style Settings
Language: Cpp
BasedOnStyle: Google
Standard: c++20
IndentWidth: 2
UseTab: Never
ColumnLimit: 80

14
.gitignore vendored
View File

@@ -1,7 +1,9 @@
build/*
out/
.vs/
.idea/
tmp/
config.json
Music
Temp/
Music
*.json
yt-dlp
ffmpeg
password
.vs
out

View File

@@ -1,21 +0,0 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"DDPP_CORO=on"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-DDPP_CORO"
]
}
],
"version": 4
}

51
.vscode/launch.json vendored
View File

@@ -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": "/home/happytanuki/BumbleCee/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
}
]
}
]
}

142
.vscode/settings.json vendored
View File

@@ -1,80 +1,112 @@
{
"editor.rulers": [
{
"column": 80
}
],
"cmake.generator": "Ninja",
"files.associations": {
"iostream": "cpp",
"any": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"condition_variable": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string_view": "cpp",
"random": "cpp",
"*.tcc": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"istream": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"concepts": "cpp",
"coroutine": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"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",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"latch": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"cinttypes": "cpp",
"bitset": "cpp",
"set": "cpp",
"regex": "cpp",
"format": "cpp",
"span": "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",
"__locale": "cpp",
"ios": "cpp",
"locale": "cpp",
"print": "cpp"
},
"files.exclude": {
"**/*.rpyc": true,
"**/*.rpa": true,
"**/*.rpymc": true,
"**/cache/": true
}
}

35
.vscode/tasks.json vendored
View File

@@ -1,35 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "make",
"command": "make",
"args": [],
"options": {
"cwd": "/home/happytanuki/BumbleCee/build/"
},
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["cmake"]
},
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
],
"options": {
"cwd": "/home/happytanuki/BumbleCee/build/"
},
"group": {
"kind": "build",
"isDefault": false
}
},
]
}

8
BuildDockerAndUpload.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
(
cd build
cmake .. && make
)
docker login -u happytanuki12 --password-stdin < password
docker build --tag happytanuki12/bumblebee:latest .
docker push happytanuki12/bumblebee:latest

View File

@@ -1,80 +1,163 @@
cmake_minimum_required (VERSION 3.6)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
cmake_minimum_required (VERSION 3.16)
set(BOT_NAME "BumbleCee")
project(${BOT_NAME} LANGUAGES CXX)
project(${BOT_NAME})
aux_source_directory("src" coresrc)
aux_source_directory("src/Commands" commands)
add_executable(${BOT_NAME} ${coresrc} ${commands})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
string(ASCII 27 Esc)
set(BOOST_EXCLUDE_LIBRARIES nowide)
set(BUILD_TESTING ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(DPP_BUILD_TEST OFF)
set_target_properties(${BOT_NAME} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
)
enable_testing()
target_compile_definitions(${BOT_NAME} PUBLIC DPP_CORO)
target_compile_features(${BOT_NAME} PUBLIC cxx_std_20)
if(WIN32)
set(OPENSSL_ROOT_DIR "C:/Program Files/OpenSSL-Win64")
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
find_package(DPP)
if(APPLE)
if(CMAKE_APPLE_SILICON_PROCESSOR)
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl")
else()
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
find_package(OpenSSL REQUIRED)
else()
find_package(OpenSSL REQUIRED)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MTd/libcrypto.lib")
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MTd/libssl.lib")
else()
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MT/libcrypto.lib")
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MT/libssl.lib")
endif()
endif()
target_include_directories(${BOT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${OPENSSL_INCLUDE_DIR}
/usr/include/opus
)
find_package(OpenSSL REQUIRED)
target_link_libraries(${BOT_NAME}
dl
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
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)
FetchContent_Declare(
dpp
opus
oggz
mariadbcpp
${CMAKE_THREAD_LIBS_INIT}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
GIT_REPOSITORY "https://github.com/brainboxdotcc/DPP.git"
GIT_TAG "v10.1.3"
GIT_SHALLOW 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 바이너리 다운로드 및 링크
# -------------------------------------------------------------
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(FFMPEG_URL "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-lgpl-shared.zip")
set(FFMPEG_ARCHIVE_NAME "ffmpeg-windows")
set(FFMPEG_LIB_DIR "lib")
set(FFMPEG_INCLUDE_DIR "include")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(FFMPEG_URL "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-lgpl-shared.tar.xz")
set(FFMPEG_ARCHIVE_NAME "ffmpeg-linux")
set(FFMPEG_LIB_DIR "lib")
set(FFMPEG_INCLUDE_DIR "include")
else()
message(FATAL_ERROR "Unsupported platform for FFmpeg precompiled binaries.")
endif()
FetchContent_Declare(
ffmpeg
URL ${FFMPEG_URL}
DOWNLOAD_EXTRACT_TIMESTAMP ON
SOURCE_DIR ${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}
)
message(STATUS "Fetching and making available ffmpeg...")
FetchContent_MakeAvailable(ffmpeg)
set(FFMPEG_LIBRARY_PATH ${ffmpeg_SOURCE_DIR}/${FFMPEG_LIB_DIR})
set(FFMPEG_INCLUDE_PATH ${ffmpeg_SOURCE_DIR}/${FFMPEG_INCLUDE_DIR})
find_library(AVCODEC_LIBRARY NAMES avcodec PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
message(STATUS "AVCODEC_LIBRARY = ${AVCODEC_LIBRARY}")
find_library(AVFORMAT_LIBRARY NAMES avformat PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
message(STATUS "AVFORMAT_LIBRARY = ${AVFORMAT_LIBRARY}")
find_library(AVUTIL_LIBRARY NAMES avutil PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
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 OR NOT SWRESAMPLE_LIBRARY)
message(FATAL_ERROR "FFmpeg 라이브러리를 찾을 수 없습니다. 다운로드 경로를 확인해주세요.")
endif()
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.cxx" "src/*.cc")
add_library(${BOT_NAME}_lib ${SOURCES})
target_include_directories(${BOT_NAME}_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
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}_lib PUBLIC ws2_32)
endif()
if(UNIX AND NOT APPLE)
set_target_properties(${BOT_NAME}_lib PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN"
SKIP_BUILD_RPATH FALSE
BUILD_RPATH "$ORIGIN"
)
endif()
add_executable(${BOT_NAME} ${SOURCES})
target_link_libraries(${BOT_NAME} PUBLIC ${BOT_NAME}_lib)
file(GLOB FFMPEG_SHARED
"${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/bin/*.dll" # Windows
"${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/lib/*.so*" # Linux
)
if (DPP_FOUND)
target_link_libraries(${BOT_NAME} ${DPP_LIBRARIES})
target_include_directories(${BOT_NAME} PUBLIC ${DPP_INCLUDE_DIR})
else()
message(WARNING "Could not find DPP install. Building from source instead.")
option(DPP_BUILD_TEST "" OFF)
include(FetchContent)
foreach(ffmpeg_shared ${FFMPEG_SHARED})
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${ffmpeg_shared}"
"$<TARGET_FILE_DIR:${BOT_NAME}>"
COMMENT "Copying ${ffmpeg_shared} to output directory"
)
endforeach()
FetchContent_Declare(
libdpp
GIT_REPOSITORY https://github.com/brainboxdotcc/DPP.git
GIT_TAG master)
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:dpp>"
"$<TARGET_FILE_DIR:${BOT_NAME}>"
COMMENT "Copying dpp DLL/so files to output directory"
)
FetchContent_GetProperties(libdpp)
if(NOT libdpp_POPULATED)
FetchContent_Populate(libdpp)
target_include_directories(${BOT_NAME} PUBLIC
${libdpp_SOURCE_DIR}/include
)
add_subdirectory(
${libdpp_SOURCE_DIR}
${libdpp_BINARY_DIR}
EXCLUDE_FROM_ALL)
endif()
target_link_libraries(${BOT_NAME} dpp)
endif()
add_subdirectory(tests)

21
Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM debian:sid
WORKDIR /
RUN apt-get update && \
apt-get install -y curl libopus0 tini liboggz2 xz-utils ffmpeg python3 \
python3-pip python3-certifi python3-brotli python3-websockets python3-requests python3-mutagen && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install --break-system-packages --no-cache-dir curl_cffi
RUN pip3 install --break-system-packages --no-cache-dir pycryptodome
RUN curl -Lo dpp.deb https://dl.dpp.dev/latest
RUN curl -Lo dpp-legacy.deb https://github.com/brainboxdotcc/DPP/releases/download/v10.0.35/libdpp-10.0.35-linux-x64.deb
RUN dpkg -i dpp.deb
RUN dpkg -i dpp-legacy.deb
RUN rm dpp.deb
RUN curl -LO https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
RUN chmod +x ./yt-dlp
COPY ./build/BumbleCee /BumbleCee
COPY ./streamOpus.sh /streamOpus.sh
RUN chmod +x BumbleCee
RUN chmod +x streamOpus.sh
ENTRYPOINT ["/usr/bin/tini", "--", "./BumbleCee"]

View File

@@ -1,18 +1,25 @@
# 이게 뭔가요?
[![CodeFactor](https://www.codefactor.io/repository/github/happytanuki/bumblecee/badge)](https://www.codefactor.io/repository/github/happytanuki/bumblecee)
C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악봇입니다!
<div align="center">
<a href="https://github.com/brainboxdotcc/DPP" alt="DPP"> <img src="DPP-markdown-logo.png" /> </a>
</div>
# 어떻게 써요?
1. 실행파일 경로에 config.json 파일을 만들고 다음과 같이 입력하세요:
```
{"token": "디스코드에서 발급받은 개인 봇 토큰"}
{
"CLEAR_PREVIOUS_COMMAND": true,
"FFMPEG_CMD": "ffmpeg",
"LOGLEVEL": "debug",
"TOKEN": "발급받은 토큰",
"YTDLP_CMD": "./yt-dlp"
}
```
2. Music 디렉터리를 만드세요
3. Music/Archive 파일을 만드세요
4. 봇을 실행시키고 초대하셔서 사용하시면 됩니다.
2. 봇을 초대하시고 사용하시면 됩니다.
# 명령어
## /p
@@ -36,3 +43,6 @@ C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악
음성 채팅을 떠납니다.
사용법:
/l
# docker
happytanuki12/bumblebee:latest

View File

@@ -1,49 +0,0 @@
W8UNLOOogU4
749DIRUHhNY
o75PUTiHEXU
pS5d77DQHOI
65xX7zyr-fA
2eNEQ0cQtkI
UgS7vgquBvo
IFCDLIKSArs
yPdqcADl5U4
6aEglYFwjrA
n8F-E5f-cos
1zwaZkOXXqw
vjSrFwbwu6w
vwZAqxL8rgs
zOkIe3RcTCs
mzVbYUBo8_Y
rgNdeflYdYw
CjaM8qWzssk
kNDbaYEp0tU
smObR_8q5UQ
27NtZwyog7g
vHfAjfKVMew
b_bjtIeqIR4
YTaX7BWlk9g
BBj3SCImk_A
Yb_IhN4TGp8
-m-crWZHLi0
4ciZKNHSoUs
4tlUwgtgdZA
oPGtAA2HaS8
dLlD-dZNACM
9LW9DpmhrPE
pMTRBNMX2mw
Kt451YtL-Vs
tc0FL9JROGQ
NinLIDs9qmU
KMdTrqzEI0I
HbXaUmWaU5Q
xtFAmapbTbY
B7luArOaIl0
HMqhXxH5-RQ
mQFokUq9LYs
HyL8Z94W6es
prAnOH-q_Bo
LRPGqNeav_M
M4-XU0a2hf0
BryspbM6s3E
JVTS3fyoAEQ
KAaUyVJoNAE

7
docker-compose.yml Normal file
View File

@@ -0,0 +1,7 @@
services:
bumblebee:
image: happytanuki12/bumblebee:latest
container_name: BumbleBee
volumes:
- ./config.json:/config.json
restart: unless-stopped

View File

@@ -1,27 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <dpp/dpp.h>
#include <memory>
#include <mariadb/conncpp.hpp>
class IBot {
public:
IBot(std::string token, int clusterCount = 0);
virtual void start();
virtual void onCommand(const dpp::slashcommand_t &event);
virtual void onReady(const dpp::ready_t &event);
std::shared_ptr<dpp::cluster> botCluster;
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
std::function<void(const dpp::log_t&)> logger() {
return [&](const dpp::log_t& event){
if (event.severity >= dpp::ll_error)
std::cerr << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl;
else if (event.severity - logLevel >= 0)
std::clog << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl;
};
};
dpp::loglevel logLevel = dpp::ll_debug;
};

View File

@@ -1,38 +0,0 @@
#pragma once
#include <string>
#include <Bot.hpp>
#include <dpp/dpp.h>
#include <memory>
#include <unordered_map>
#include <FQueueElement.hpp>
class BumbleCeepp : public IBot {
public:
BumbleCeepp(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount = 0);
~BumbleCeepp();
void enqueueMusic(FQueueElement item, dpp::discord_voice_client* vc);
std::shared_ptr<dpp::embed> findEmbed(std::string musicID);
bool insertDB(
std::string webpage_url,
std::string title,
std::string uploader,
std::string id,
std::string thumbnail,
time_t duration);
std::shared_ptr<dpp::embed> makeEmbed(
std::string webpage_url,
std::string title,
std::string uploader,
std::string id,
std::string thumbnail,
time_t duration);
bool repeat;
std::string nowPlayingMusic;
private:
//<guild_id, queueMutex> 쌍임.
std::unordered_map<dpp::snowflake, std::mutex> enqueuingMutexMap;
sql::Connection* conn;
};

View File

@@ -1,22 +0,0 @@
#pragma once
#include <dpp/dpp.h>
#include <vector>
#include <list>
class BumbleCeepp;
namespace commands {
class ICommand {
public:
ICommand(dpp::snowflake botID, BumbleCeepp* Bot)
{
this->botID = botID;
this->Bot = Bot;
}
virtual void operator()(const dpp::slashcommand_t &event) = 0;
std::vector<dpp::slashcommand> commandObjectVector;
dpp::snowflake botID;
BumbleCeepp* Bot;
};
}

View File

@@ -1,7 +0,0 @@
#pragma once
#include <Commands/Play.hpp>
#include <Commands/Repeat.hpp>
#include <Commands/Queue.hpp>
#include <Commands/Skip.hpp>
#include <Commands/Leave.hpp>
#include <Commands/Delete.hpp>

View File

@@ -1,13 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace commands {
class Delete : public ICommand {
public:
Delete(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace commands {
class Leave : public ICommand {
public:
Leave(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};
}

View File

@@ -1,14 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace commands {
class Play : public ICommand {
public:
Play(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
void on_DLCompleted(std::string musicID, dpp::embed embed, const dpp::slashcommand_t& event);
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace commands {
class Queue : public ICommand {
public:
Queue(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace commands {
class Repeat : public ICommand {
public:
Repeat(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace commands {
class Skip : public ICommand {
public:
Skip(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};
}

View File

@@ -1,9 +0,0 @@
#pragma once
#include <string>
#include <dpp/dpp.h>
struct FQueueElement {
std::string ID;
dpp::embed embed;
bool skip = false;
};

23
include/precomp.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef BUMBLEBEE_INCLUDE_PRECOMP_H_
#define BUMBLEBEE_INCLUDE_PRECOMP_H_
#ifdef WIN32
#include <winsock2.h>
#endif
#include <iostream>
#include <queue>
#include "boost/asio.hpp"
#include "boost/beast/http.hpp"
#include "boost/beast/ssl.hpp"
#include "boost/log/trivial.hpp"
#include "boost/process.hpp"
extern "C" {
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
}
#endif // BUMBLEBEE_INCLUDE_PRECOMP_H_

41
include/utils/console.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef BUMBLEBEE_INCLUDE_UTILS_CONSOLE_H_
#define BUMBLEBEE_INCLUDE_UTILS_CONSOLE_H_
#include "precomp.h"
namespace utils {
// @brief 명령어가 실행 가능한지 체크합니다
// @param cmd 실행할 명령
// @return int error_code
int ValidateCommand(
boost::asio::io_context& ctx, std::string cmd,
const std::vector<std::string>& args = std::vector<std::string>());
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
// @param cmd 실행할 명령
// @param args 아규먼트
// @return int error_code
int ExecuteCommand(
boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args = std::vector<std::string>());
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
// @param cmd 실행할 명령
// @param result 실행결과
// @return int error_code
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
std::string& result);
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
// @param cmd 실행할 명령
// @param args 아규먼트
// @param result 실행결과
// @return int error_code
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args, std::string& result);
// @brief 명령어를 쉘에서 실행하고 결과를 파이프로 연결하여 반환합니다
// @param cmd 실행할 명령
// @param args 아규먼트
// @return boost::process::popen
boost::process::popen OpenPipe(
boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args = std::vector<std::string>());
} // namespace utils
#endif

View File

@@ -0,0 +1,10 @@
#ifndef BUMBLEBEE_INCLUDE_UTILS_FILE_DOWNLOADER_H_
#define BUMBLEBEE_INCLUDE_UTILS_FILE_DOWNLOADER_H_
#include "precomp.h"
namespace utils {
void DownloadFileFromHTTPS(std::string url, std::string filename);
}
#endif

View File

@@ -0,0 +1,14 @@
#ifndef BUMBLEBEE_INCLUDE_UTILS_UPDATE_CHECKER_H_
#define BUMBLEBEE_INCLUDE_UTILS_UPDATE_CHECKER_H_
#include "precomp.h"
namespace utils {
int InstallYtdlp(boost::asio::io_context& ctx);
int CheckUpdate(boost::asio::io_context& ctx);
} // namespace utils
#endif

1
out

File diff suppressed because one or more lines are too long

View File

@@ -1,39 +0,0 @@
#include <Bot.hpp>
#include <Commands/CommandType.hpp>
IBot::IBot(std::string token, int clusterCount)
{
botCluster = std::make_shared<dpp::cluster>(token, dpp::i_default_intents, clusterCount);
botCluster->on_log(logger());
botCluster->on_slashcommand([&](const dpp::slashcommand_t& event){onCommand(event);});
botCluster->on_ready([&](const dpp::ready_t &event){onReady(event);});
}
void IBot::onCommand(const dpp::slashcommand_t &event)
{
auto _event = event;
for (auto command : commandsArray)
for (auto alias : command->commandObjectVector)
if (event.command.get_command_name() == alias.name)
(*command)(_event);
}
void IBot::onReady(const dpp::ready_t &event)
{
if (!dpp::run_once<struct register_bot_commands>())
return;
//BotCluster->global_bulk_command_delete();
for (auto command : commandsArray)
for (auto alias : command->commandObjectVector)
botCluster->global_command_create(alias);
botCluster->log(dpp::loglevel::ll_info, "Command added to all clusters.");
}
void IBot::start()
{
botCluster->start(dpp::st_wait);
}

View File

@@ -1,245 +0,0 @@
#include "BumbleCeepp.hpp"
#include <string>
#include <FQueueElement.hpp>
#include <Commands/Commands.hpp>
#include <oggz/oggz.h>
BumbleCeepp::BumbleCeepp(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount)
: IBot(token, clusterCount)
{
sql::Properties pro({
{"user", DBID},
{"password", DBPassword}
});
conn = sql::mariadb::get_driver_instance()->connect(DBURL, pro);
commandsArray.push_back(std::make_shared<commands::Play>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Repeat>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Queue>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Skip>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Leave>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Delete>(botCluster->me.id, this));
botCluster->on_voice_track_marker([&](const dpp::voice_track_marker_t &marker)
{
marker.voice_client->log(dpp::loglevel::ll_debug, "nowPlaying " + nowPlayingMusic);
std::shared_ptr<dpp::embed> embed;
if (nowPlayingMusic == "") {
nowPlayingMusic = marker.track_meta;
embed = findEmbed(nowPlayingMusic);
}
else {
embed = findEmbed(nowPlayingMusic);
nowPlayingMusic = marker.track_meta;
}
auto voice_members = dpp::find_guild(marker.voice_client->server_id)->voice_members;
dpp::snowflake connectedChannel = marker.voice_client->channel_id;
int memberCount = 0;
for (auto member : voice_members)
if ( member.second.channel_id == connectedChannel )
memberCount++;
if (!memberCount)
{
auto joinedShard = marker.from;
std::cout << "voicechat is empty.";
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
return;
}
<<<<<<< HEAD
if (!memberCount)
{
auto joinedShard = marker.from;
marker.voice_client->log(dpp::loglevel::ll_info, "voicechat is empty.");
=======
marker.voice_client->log(dpp::loglevel::ll_debug, "Playing " + marker.track_meta + "on channel id " + marker.voice_client->channel_id.str() + ".");
int remainingSongsCount = marker.voice_client->get_tracks_remaining();
marker.voice_client->log(dpp::loglevel::ll_debug, "Marker count : " + std::to_string(remainingSongsCount));
if (remainingSongsCount <= 1 && !marker.voice_client->is_playing())
{
auto joinedShard = marker.from;
std::cout << "Queue ended\n";
if (!joinedShard)
return;
if (repeat) {
std::shared_ptr<dpp::embed> embed = findEmbed(nowPlayingMusic);
enqueueMusic({nowPlayingMusic, *embed}, marker.voice_client);
}
else {
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
return;
}
}
<<<<<<< HEAD
marker.voice_client->log(dpp::loglevel::ll_debug, "Playing " + marker.track_meta + "on channel id " + marker.voice_client->channel_id.str() + ".");
int remainingSongsCount = marker.voice_client->get_tracks_remaining();
marker.voice_client->log(dpp::loglevel::ll_info, "Marker count : " + remainingSongsCount);
if (remainingSongsCount <= 1 && !marker.voice_client->is_playing())
{
auto joinedShard = marker.from;
marker.voice_client->log(dpp::loglevel::ll_info, "Queue ended");
if (!joinedShard)
return;
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
=======
if (repeat) {
if (!embed) {
botCluster->log(dpp::loglevel::ll_error, std::string("알 수 없는 오류 발생!"));
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
return;
}
enqueueMusic({nowPlayingMusic, *embed}, marker.voice_client);
}
});
}
BumbleCeepp::~BumbleCeepp()
{
conn->close();
}
void BumbleCeepp::enqueueMusic(FQueueElement item, dpp::discord_voice_client* vc)
{
vc->insert_marker(item.ID);
vc->log(dpp::loglevel::ll_debug, "Enqueueuing " + item.ID + "on channel id " + vc->channel_id.str() + ".");
std::lock_guard<std::mutex> lock(enqueuingMutexMap[vc->server_id]);
OGGZ *track_og = oggz_open(("Music/" + item.ID + ".ogg").c_str(), OGGZ_READ);
/* If there was an issue reading the file, tell the user and stop */
if (!track_og) {
fprintf(stderr, "Error opening file\n");
return;
}
/* set read callback, this callback will be called on packets with the serialno,
* -1 means every packet will be handled with this callback.
*/
oggz_set_read_callback(
track_og, -1,
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
dpp::discord_voice_client *vc = (dpp::discord_voice_client *)user_data;
/* send the audio */
vc->send_audio_opus(packet->op.packet, packet->op.bytes);
/* make sure to always return 0 here, read more on oggz documentation */
return 0;
},
/* this will be the value of void *user_data */
(void *)vc
);
// read loop
while (vc && !vc->terminating) {
/* you can tweak this to whatever. Here I use BUFSIZ, defined in
* stdio.h as 8192.
*/
static const constexpr long CHUNK_READ = BUFSIZ * 2;
const long read_bytes = oggz_read(track_og, CHUNK_READ);
/* break on eof */
if (!read_bytes) {
break;
}
}
/* Don't forget to free the memory */
oggz_close(track_og);
vc->log(dpp::loglevel::ll_debug, "Enqueued " + item.ID + "on channel id " + vc->channel_id.str() + ".");
}
std::shared_ptr<dpp::embed> BumbleCeepp::findEmbed(std::string musicID)
{
sql::ResultSet* res;
std::shared_ptr<dpp::embed> returnValue;
try {
std::unique_ptr<sql::PreparedStatement> stmnt(conn->prepareStatement("SELECT * FROM songs_info WHERE ID = ?"));
stmnt->setString(1, musicID);
res = stmnt->executeQuery();
if (!res->next()) {
return nullptr;
}
returnValue = makeEmbed(
res->getString("webpage_url").c_str(),
res->getString("title").c_str(),
res->getString("uploader").c_str(),
musicID,
res->getString("thumbnail").c_str(),
res->getInt("duration"));
}
catch(sql::SQLException& e){
botCluster->log(dpp::loglevel::ll_error, std::string("SQLError: ") + e.what());
return nullptr;
}
return returnValue;
}
bool BumbleCeepp::insertDB(
std::string webpage_url, std::string title, std::string uploader, std::string id, std::string thumbnail, time_t duration)
{
try {
std::unique_ptr<sql::PreparedStatement> stmnt(
conn->prepareStatement("REPLACE INTO songs_info (ID, webpage_url, title, uploader, thumbnail, duration) VALUE (?, ?, ?, ?, ?, ?)"));
stmnt->setString(1, id);
stmnt->setString(2, webpage_url);
stmnt->setString(3, title);
stmnt->setString(4, uploader);
stmnt->setString(5, thumbnail);
stmnt->setInt(6, duration);
stmnt->executeQuery();
return true;
}
catch(sql::SQLException& e){
botCluster->log(dpp::loglevel::ll_debug, std::string("SQLError: ") + e.what());
return false;
}
}
std::shared_ptr<dpp::embed> BumbleCeepp::makeEmbed(
std::string webpage_url, std::string title, std::string uploader, std::string id, std::string thumbnail, time_t duration)
{
char SongLengthStr[10];
tm t;
t.tm_mday = duration / 86400;
t.tm_hour = (duration % 86400)/3600;
t.tm_min = (duration % 3600)/60;
t.tm_sec = duration%60;
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
dpp::embed returnValue = dpp::embed()
.set_color(dpp::colors::sti_blue)
.set_title(title)
.set_description(uploader)
.set_url(webpage_url)
.set_image(thumbnail)
.add_field(
"길이",
SongLengthStr,
true
);
insertDB(webpage_url, title, uploader, id, thumbnail, duration);
return std::make_shared<dpp::embed>(returnValue);
}

View File

@@ -1,58 +0,0 @@
#include <Commands/Delete.hpp>
#include <iostream>
commands::Delete::Delete(dpp::snowflake botID, BumbleCeepp* Bot)
: ICommand(botID, Bot)
{
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botID);
Command.add_option(
dpp::command_option(dpp::co_string, "pos", "큐 번호", botID)
);
commandObjectVector.push_back(Command);
}
void commands::Delete::operator()(const dpp::slashcommand_t& event)
{
if (std::holds_alternative<std::monostate>(event.get_parameter("pos"))) {
event.reply("삭제할 노래의 인덱스가 정확하지 않습니다.");
return;
}
std::string Pos = std::get<std::string>(event.get_parameter("pos"));
event.thinking();
auto index = atoi(Pos.c_str());
auto vc = event.from->connecting_voice_channels.find(event.command.guild_id)->second->voiceclient;
int remainingSongsCount = vc->get_tracks_remaining() - 1;
std::vector<std::string> queuedSongs = vc->get_marker_metadata();
vc->log(dpp::loglevel::ll_info, "Queue size : " + remainingSongsCount);
if (index < 0 || remainingSongsCount+1 < index || (!vc->is_playing() && index == 0)) {
std::cout << "invalid index : " << index << ", " + Pos + "\n";
event.edit_original_response(dpp::message(event.command.channel_id, "이상한 인덱스 위치. Pos : " + Pos));
return;
}
dpp::embed embed = (*Bot->findEmbed(queuedSongs[index - 1]))
.set_timestamp(time(0));
dpp::message msg(event.command.channel_id, "다음 항목을 큐에서 삭제했습니다!:");
if (index == 0) {
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
return;
}
v->voiceclient->skip_to_next_marker();
}
msg.add_embed(embed);
event.edit_original_response(msg);
}

View File

@@ -1,25 +0,0 @@
#include <Commands/Leave.hpp>
#include <iostream>
commands::Leave::Leave(dpp::snowflake botID, BumbleCeepp* Bot)
: ICommand(botID, Bot)
{
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botID);
commandObjectVector.push_back(command);
}
void commands::Leave::operator()(const dpp::slashcommand_t& event)
{
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
return;
}
v->voiceclient->stop_audio();
event.from->disconnect_voice(event.command.guild_id);
dpp::message msg(event.command.channel_id, "음성 채팅방을 떠납니다!");
event.reply(msg);
}

View File

@@ -1,212 +0,0 @@
#include <Commands/Play.hpp>
#include <dpp/dpp.h>
#include <dpp/nlohmann/json.hpp>
#include <string>
#include <filesystem>
#include <ctime>
#include <thread>
using json = nlohmann::json;
std::string getResultFromCommand(std::string cmd) {
std::string result;
FILE* stream;
const int maxBuffer = 256; // 버퍼의 크기는 적당하게
char buffer[maxBuffer];
cmd.append(" 2>&1"); // 표준에러를 표준출력으로 redirect
stream = popen(cmd.c_str(), "r"); // 주어진 command를 shell로 실행하고 파이프 연결 (fd 반환)
if (stream) {
while (fgets(buffer, maxBuffer, stream) != NULL) result.append(buffer); // fgets: fd (stream)를 길이 (maxBuffer)만큼 읽어 버퍼 (buffer)에 저장
pclose(stream); // 파이프 닫는 것 잊지 마시고요!
}
return result;
}
commands::Play::Play(dpp::snowflake botID, BumbleCeepp* Bot)
: ICommand(botID, Bot)
{
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botID);
command.add_option(
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botID)
);
commandObjectVector.push_back(command);
}
<<<<<<< HEAD
static void _Internal_Enqueue_Func(const dpp::slashcommand_t& event, BumbleCeepp* Bot){
std::string Query = std::get<std::string>(event.get_parameter("query"));
event.from->log(dpp::loglevel::ll_info, "음악 다운로드 시작");
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
event.from->log(dpp::loglevel::ll_info, "음악 다운로드 완료");
=======
void commands::Play::operator()(const dpp::slashcommand_t& event)
{
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
{
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
return;
}
/* Attempt to connect to a voice channel, returns false if we fail to connect. */
if (!event.from->get_voice(event.command.guild_id))
{
dpp::guild* g = dpp::find_guild(event.command.guild_id);
bool memberIsInVoice = g->connect_member_voice(event.command.get_issuing_user().id);
if (!memberIsInVoice)
{
event.reply("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!");
return;
}
}
std::string Query = std::get<std::string>(event.get_parameter("query"));
event.thinking();
event.from->log(dpp::loglevel::ll_debug, "음악 ID 쿼리: " + Query);
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
std::string musicIDs = getResultFromCommand(("python3 youtube-search.py \"" + Query + "\" & wait").c_str());
if (!musicIDs.length())
{
<<<<<<< HEAD
event.from->log(dpp::loglevel::ll_info, "Red ID : " + ID);
infofile.open("Music/" + ID + ".info.json");
infofile >> document;
infofile.close();
FQueueElement Data = {
ID,
Bot->makeEmbed(
document["webpage_url"],
document["title"],
document["uploader"],
document["id"],
document["thumbnail"],
int(document["duration"]))
};
RequestedMusic.push(Data);
=======
event.from->log(dpp::loglevel::ll_debug, "유튜브 검색 결과 없음");
event.edit_response("검색 결과가 없습니다.");
return;
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
}
std::stringstream sstream(musicIDs);
std::string musicID;
while (getline(sstream, musicID, '\n')) {
event.from->log(dpp::loglevel::ll_debug, "musicID: " + musicID);
event.from->log(dpp::loglevel::ll_debug, "DB쿼리 시도..");
std::shared_ptr<dpp::embed> embed = Bot->findEmbed(musicID);
if (embed == nullptr) {
event.from->log(dpp::loglevel::ll_debug, "DB쿼리 실패");
event.from->log(dpp::loglevel::ll_debug, "다운로드 시작");
std::system(("python3 yt-download.py \"" + musicID + "\" & wait").c_str());
<<<<<<< HEAD
if (v && v->voiceclient && v->voiceclient->is_ready())
{
auto _copiedQueue = RequestedMusic;
while (!_copiedQueue.empty())
{
Bot->enqueueMusic(_copiedQueue.front(), v->voiceclient);
_copiedQueue.pop();
=======
event.from->log(dpp::loglevel::ll_debug, "musicID: " + musicID);
std::ifstream infofile;
infofile.open((std::string("Music/") + musicID + ".info.json").c_str());
event.from->log(dpp::loglevel::ll_debug, std::string("json file name: ") + "Music/" + musicID + ".info.json");
json document;
infofile >> document;
infofile.close();
embed = Bot->makeEmbed(
document["webpage_url"],
document["title"],
document["uploader"],
document["id"],
document["thumbnail"],
int(document["duration"]));
on_DLCompleted(musicID, *embed, event);
}
else {
event.from->log(dpp::loglevel::ll_debug, "DB쿼리 완료");
on_DLCompleted(musicID, *embed, event);
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
}
}
return;
}
void commands::Play::on_DLCompleted(std::string musicID, dpp::embed embed, const dpp::slashcommand_t& event)
{
static std::string raw_event;
if (raw_event != event.raw_event){
raw_event = event.raw_event;
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
msg.add_embed(embed);
event.edit_response(msg);
}
else {
dpp::message followMsg(event.command.channel_id, "");
dpp::embed followEmbed = dpp::embed()
.add_field(
embed.title,
embed.description,
true
)
.add_field(
"",
""
);
followMsg.add_embed(followEmbed);
event.from->creator->message_create(followMsg);
}
}
void commands::Play::operator()(const dpp::slashcommand_t& event)
{
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
{
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
return;
}
/* Attempt to connect to a voice channel, returns false if we fail to connect. */
if (!event.from->get_voice(event.command.guild_id))
{
if (!dpp::find_guild(event.command.guild_id)->connect_member_voice(event.command.get_issuing_user().id))
{
return event.reply("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!");
}
}
event.thinking();
std::thread t1(_Internal_Enqueue_Func, event, Bot);
t1.detach();
auto voiceconn = event.from->get_voice(event.command.guild_id);
if (!voiceconn || !voiceconn->voiceclient || !voiceconn->voiceclient->is_ready()) {
event.from->creator->on_voice_ready([this, musicID, embed](const dpp::voice_ready_t& Voice){
this->Bot->enqueueMusic({musicID, embed}, Voice.voice_client);
});
}
else {
Bot->enqueueMusic({musicID, embed}, voiceconn->voiceclient);
}
}

View File

@@ -1,90 +0,0 @@
#include <Commands/Queue.hpp>
#include <iostream>
#include <sstream>
#include <cmath>
commands::Queue::Queue(dpp::snowflake botID, BumbleCeepp* Bot)
: ICommand(botID, Bot)
{
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botID);
commandObjectVector.push_back(command);
}
void commands::Queue::operator()(const dpp::slashcommand_t& event) {
dpp::message msg;
msg.set_channel_id(event.command.channel_id);
auto voiceconn = event.from->get_voice(event.command.guild_id);
if (!voiceconn || !voiceconn->voiceclient) {
event.reply("음성 채팅방에 참가하지 않은 상태입니다.");
return;
}
auto vc = voiceconn->voiceclient;
int remainingSongsCount = vc->get_tracks_remaining() - 1;
if (remainingSongsCount <= 0 && !vc->is_playing()) {
//재생 중인 노래가 없고 큐에 노래가 없는 상황
dpp::embed embed = dpp::embed()
.set_color(dpp::colors::sti_blue)
.set_title("큐가 비었습니다!")
.set_timestamp(time(0));
if (Bot->repeat)
embed.add_field(":repeat:","");
msg.add_embed(embed);
}
else {
msg.set_content("지금 재생 중:");
dpp::embed curMusicEmbed = *Bot->findEmbed(Bot->nowPlayingMusic);
msg.add_embed(curMusicEmbed);
}
event.reply(msg, [&](const dpp::confirmation_callback_t& _event) {
auto shard_id = dpp::find_guild(event.command.guild_id)->shard_id;
dpp::cluster* cluster = const_cast<dpp::cluster *>(_event.bot);
auto shard = cluster->get_shard(shard_id);
auto iter = shard->connecting_voice_channels.find(event.command.guild_id);
std::vector<std::string> queuedSongs = iter->second->voiceclient->get_marker_metadata();
int j;
for (int i = 0; i < (queuedSongs.size()+4) / 5; i++)
{
dpp::embed followEmbed = dpp::embed();
for (j = i * 5; j < i * 5 + 5 && j < queuedSongs.size(); j++)
{
dpp::embed originalEmbed = *Bot->findEmbed(queuedSongs[j]);
followEmbed.add_field(
std::to_string(j + 1),
"",
true
)
.add_field(
originalEmbed.title,
originalEmbed.description,
true
)
.add_field(
"",
""
);
}
if (j >= queuedSongs.size())
{
followEmbed.set_timestamp(time(0));
if (Bot->repeat)
followEmbed.add_field(":repeat:","");
}
dpp::message followMsg;
followMsg.channel_id = event.command.channel_id;
followMsg.add_embed(followEmbed);
event.from->creator->message_create(followMsg);
}
});
}

View File

@@ -1,25 +0,0 @@
#include <Commands/Repeat.hpp>
#include <dpp/dpp.h>
#include <string>
commands::Repeat::Repeat(dpp::snowflake botID, BumbleCeepp* Bot)
: ICommand(botID, Bot)
{
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botID);
commandObjectVector.push_back(command);
}
void commands::Repeat::operator()(const dpp::slashcommand_t& event) {
if (Bot->repeat) {
event.reply("반복을 껐습니다.");
Bot->repeat = false;
}
else {
event.reply("반복을 켰습니다.");
Bot->repeat = true;
}
return;
}

View File

@@ -1,24 +0,0 @@
#include <Commands/Skip.hpp>
#include <dpp/dpp.h>
#include <string>
commands::Skip::Skip(dpp::snowflake botID, BumbleCeepp* Bot)
: ICommand(botID, Bot)
{
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botID);
commandObjectVector.push_back(command);
}
void commands::Skip::operator()(const dpp::slashcommand_t& event) {
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
return;
}
v->voiceclient->skip_to_next_marker();
event.reply("스킵했습니다!");
return;
}

10
src/main.cc Normal file
View File

@@ -0,0 +1,10 @@
#include "precomp.h"
#include "utils/console.h"
#include "utils/update_checker.h"
int main(int argc, char* argv[]) {
boost::asio::io_context ctx;
utils::CheckUpdate(ctx);
return 0;
}

View File

@@ -1,19 +0,0 @@
#include <BumbleCeepp.hpp>
#include <dpp/nlohmann/json.hpp>
#include <memory>
using json = nlohmann::json;
int main()
{
json configdocument;
std::ifstream configfile("config.json");
configfile >> configdocument;
std::shared_ptr<BumbleCeepp> bumbleBee = std::make_shared<BumbleCeepp>(
configdocument["token"], configdocument["dbURL"], configdocument["user"], configdocument["password"]);
bumbleBee->start();
return 0;
}

File diff suppressed because one or more lines are too long

View File

@@ -1,20 +0,0 @@
import yt_dlp
import json
import sys
if len(sys.argv) != 2:
sys.exit()
ydl_opts = {
'quiet': True,
'clean_infojson': False,
'default_search': 'ytsearch',
'format': '251',
'outtmpl': {'default': 'Temp/%(id)s.temp'},
'overwrites': False,
'writeinfojson': True }
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(sys.argv[1], download=False)
with open("out", "w") as f:
f.write(json.dumps(ydl.sanitize_info(info)))

53
src/utils/console.cc Normal file
View File

@@ -0,0 +1,53 @@
#include "utils/console.h"
#include "precomp.h"
namespace utils {
int ValidateCommand(boost::asio::io_context& ctx, std::string cmd,
const std::vector<std::string>& args) {
try {
ExecuteCommand(ctx, cmd, args);
} catch (const boost::process::system_error& e) {
return -1;
}
return 0;
}
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args) {
std::string ignored;
return ExecuteCommand(ctx, cmd, args, ignored);
}
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
std::string& result) {
std::vector<std::string> ignored;
return ExecuteCommand(ctx, cmd, ignored, result);
}
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
const std::vector<std::string>& args, std::string& result) {
try {
boost::system::error_code ec;
boost::process::popen proc(
ctx, cmd, args, boost::process::process_stdio{{}, nullptr, nullptr});
boost::asio::read(proc, boost::asio::dynamic_buffer(result), ec);
proc.wait();
return proc.exit_code();
} catch (const boost::process::system_error& e) {
return -1;
}
}
boost::process::popen OpenPipe(boost::asio::io_context& ctx,
const std::string& cmd,
const std::vector<std::string>& args) {
return boost::process::popen(
ctx, cmd, args, boost::process::process_stdio{nullptr, nullptr, nullptr});
};
} // namespace utils

View File

@@ -0,0 +1,119 @@
#include "utils/file_downloader.h"
#include <fstream>
#include "boost/asio/ssl.hpp"
#include "boost/beast.hpp"
#include "precomp.h"
namespace utils {
void DownloadFileFromHTTPS(std::string url, std::string filename) {
int max_redirects = 5;
std::string current_host;
std::string current_path;
if (url.find("https://") == 0) {
url.erase(0, 8); // https:// 제거
auto pos = url.find('/');
if (pos != std::string::npos) {
current_host = url.substr(0, pos);
current_path = url.substr(pos);
} else {
current_host = url;
current_path = "/";
}
} else {
// 상대 경로일 경우
current_path = url;
}
for (int redirect = 0; redirect < max_redirects; ++redirect) {
boost::asio::io_context ioc;
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);
ctx.set_default_verify_paths();
boost::beast::ssl_stream<boost::beast::tcp_stream> stream(ioc, ctx);
// DNS 해석
boost::asio::ip::tcp::resolver resolver(ioc);
auto const results = resolver.resolve(current_host, "443");
// TCP 연결
boost::beast::get_lowest_layer(stream).connect(results);
// SSL 핸드셰이크
stream.handshake(boost::asio::ssl::stream_base::client);
// HTTP GET 요청
boost::beast::http::request<boost::beast::http::string_body> req{
boost::beast::http::verb::get, current_path, 11};
req.set(boost::beast::http::field::host, current_host);
req.set(boost::beast::http::field::user_agent, "Mozilla/5.0");
boost::beast::http::write(stream, req);
boost::beast::flat_buffer buffer;
// 응답 파서 만들기
boost::beast::http::response_parser<boost::beast::http::dynamic_body>
parser;
// body 제한 해제 (무제한)
parser.body_limit((std::numeric_limits<std::uint64_t>::max)());
// 응답 읽기
boost::beast::http::read(stream, buffer, parser);
auto res = parser.release();
int status = res.result_int();
if (status / 100 == 3) {
// 리다이렉트 처리
auto loc = res[boost::beast::http::field::location];
if (loc.empty()) {
throw std::runtime_error("Redirect without Location header");
}
// 새 호스트/경로 파싱
std::string new_url(loc);
if (new_url.find("https://") == 0) {
new_url.erase(0, 8); // https:// 제거
auto pos = new_url.find('/');
if (pos != std::string::npos) {
current_host = new_url.substr(0, pos);
current_path = new_url.substr(pos);
} else {
current_host = new_url;
current_path = "/";
}
} else {
// 상대 경로일 경우
current_path = new_url;
}
continue;
}
if (status != 200) {
throw std::runtime_error("HTTP request failed with status " +
std::to_string(status));
}
// 파일 저장
std::ofstream file(filename, std::ios::binary);
if (!file) {
throw std::runtime_error("Could not open file for writing: " + filename);
}
for (auto const& buffer_part : res.body().data()) {
file.write(reinterpret_cast<const char*>(buffer_part.data()),
buffer_part.size());
}
return;
}
throw std::runtime_error("Too many redirects");
}
} // namespace utils

View File

@@ -0,0 +1,71 @@
#include "utils/update_checker.h"
#include "precomp.h"
#include "utils/console.h"
#include "utils/file_downloader.h"
namespace utils {
int InstallYtdlp(boost::asio::io_context& ctx) {
BOOST_LOG_TRIVIAL(warning) << "ytdlp is unavailable. downloading ytdlp...";
#ifdef WIN32
DownloadFileFromHTTPS(
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe",
"yt-dlp.exe");
#else
DownloadFileFromHTTPS(
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp",
"yt-dlp");
ExecuteCommand(ctx,
boost::process::environment::find_executable("chmod").string(),
{"+x", "yt-dlp"});
#endif
return 0;
}
static int FindNewLinePos(std::string& string, int start_pos) {
int newline_pos = start_pos;
while (newline_pos < string.size()) {
if (string[newline_pos] == '\n') {
return newline_pos;
}
newline_pos++;
}
return newline_pos;
}
int CheckUpdate(boost::asio::io_context& ctx) {
std::string output = "";
int old_newline_pos = 0;
int newline_pos = 0;
#ifdef WIN32
if (ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output) !=
0) {
InstallYtdlp(ctx);
ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output);
}
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
<< output.substr(0, output.size() - 1);
output = "";
ExecuteCommand(ctx, "yt-dlp.exe", {"-U", "--newline"}, output);
#else
if (ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output) != 0) {
InstallYtdlp(ctx);
ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output);
}
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
<< output.substr(0, output.size() - 1);
output = "";
ExecuteCommand(ctx, "yt-dlp", {"-U", "--newline"}, output);
#endif
while (newline_pos < output.size()) {
old_newline_pos = newline_pos;
newline_pos = FindNewLinePos(output, newline_pos);
BOOST_LOG_TRIVIAL(info) << output.substr(old_newline_pos, newline_pos - 1);
newline_pos++;
}
return 0;
}
} // namespace utils

View File

@@ -1,47 +0,0 @@
import yt_dlp
import sys
import os
import json
if len(sys.argv) != 2:
sys.exit()
ydl_opts = {
'quiet': True,
'clean_infojson': False,
'default_search': 'ytsearch',
'format': '251',
'outtmpl': {'default': 'Temp/%(id)s.temp'},
'overwrites': False,
'writeinfojson': True }
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(sys.argv[1], download=False)
id = list()
with open("out", "w") as f:
f.write(json.dumps(ydl.sanitize_info(info)))
with open("Music/Archive", "r") as f:
ArchiveList = f.read().split("\n")
if "entries" in info:
if len(info["entries"]) != 0:
for entry in info["entries"]:
if entry["id"] not in ArchiveList:
ydl.download(entry["webpage_url"])
os.system("echo " + entry["id"] + " >> Music/Archive")
os.system("yes n 2>/dev/null | ffmpeg -hide_banner -loglevel error -i \"" + "Temp/" + entry["id"] + ".temp" + "\" -c copy Music/" + entry["id"] + ".ogg")
os.system("mv Temp/" + entry["id"] + ".temp.info.json Music/" + entry["id"] + ".info.json")
id.append(entry["id"])
else:
if info["id"] not in ArchiveList:
ydl.download(info["webpage_url"])
os.system("echo " + info["id"] + " >> Music/Archive")
os.system("yes n 2>/dev/null | ffmpeg -hide_banner -loglevel error -i \"" + "Temp/" + info["id"] + ".temp" + "\" -c copy Music/" + info["id"] + ".ogg")
os.system("mv Temp/" + info["id"] + ".temp.info.json Music/" + info["id"] + ".info.json")
id.append(info["id"])
os.system("rm -f Temp/*.temp")
os.system("rm -f Temp/*.json")
with open("Temp/CurMusic", "w") as f:
for item in id:
f.write(item + "\n")

12
streamOpus.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
YTDLP_CMD=$1
FFMPEG_CMD=$2
URL=$3
$YTDLP_CMD -o - --quiet --ignore-errors -f bestaudio $URL 2>/dev/null | \
$FFMPEG_CMD -hwaccel vaapi -i - -loglevel quiet -hide_banner -c:a copy -f opus - || \
$YTDLP_CMD -o - --quiet --ignore-errors -f bestaudio $URL 2>/dev/null | \
$FFMPEG_CMD -hwaccel vaapi -i - -loglevel quiet -hide_banner -f opus -c:a libopus -b:a 128k -ar 48000 -ac 2 -
# -loglevel quiet

8
tests/CMakeLists.txt Normal file
View File

@@ -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()

View File

@@ -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;
}

8
tests/update.cc Normal file
View File

@@ -0,0 +1,8 @@
#include "precomp.h"
#include "utils/update_checker.h"
int main() {
boost::asio::io_context ctx;
utils::CheckUpdate(ctx);
return 0;
}

View File

@@ -1,54 +0,0 @@
import sys
if len(sys.argv) != 2:
sys.exit()
import urllib.parse
def uri_validator(x):
try:
result = urllib.parse.urlparse(x)
return all([result.scheme, result.netloc])
except AttributeError:
return False
#URL인 경우
if uri_validator(sys.argv[1]) == True:
result = urllib.parse.urlparse(sys.argv[1])
#youtu.be짧은 주소인 경우
if (result.netloc == 'youtu.be'):
print(result.path[1:13])
#플레이리스트인 경우
if result.path == '/playlist':
import re, requests
response = requests.get("https://www.youtube.com/playlist?" + result.query)
pattern = re.compile('"videoId":"(.{11})"')
IDlist = set(pattern.findall(response.text))
# list_to_return = list()
# list_to_return.append(IDlist[0])
# list_to_return_count = 0
# for it in range(0, len(list_to_return)):
# if (list_to_return[list_to_return_count] == IDlist[it]):
# continue
# else:
# list_to_return[list_to_return_count] = IDlist[it]
# list_to_return_count += 1
for it in IDlist:
print(it)
#영상인 경우
elif result.path == '/watch':
print(result.query[2:13])
else:
from youtube_search import YoutubeSearch
results = YoutubeSearch(sys.argv[1], max_results=10).to_dict()
#검색 결과가 없는 경우 확인 불가
print(results[0]["id"])

BIN
yt-dlp

Binary file not shown.

View File

@@ -1,19 +0,0 @@
import yt_dlp
import sys
import os
if len(sys.argv) != 2:
sys.exit()
ydl_opts = {
'quiet': True,
'format': '251',
'outtmpl': {'default': 'Temp/' + sys.argv[1]},
'writeinfojson': True
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info("https://www.youtube.com/watch?v=" + sys.argv[1])
os.system("yes n 2>/dev/null | ffmpeg -hide_banner -loglevel error -i \"" + "Temp/" + sys.argv[1] + "\" -c copy Music/" + sys.argv[1] + ".ogg > /dev/null 2> /dev/null")
os.system("mv Temp/" + sys.argv[1] + ".info.json Music/" + sys.argv[1] + ".info.json > /dev/null 2> /dev/null")
os.system("rm -rf Temp/ > /dev/null 2> /dev/null")