mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-25 09:25:59 +00:00
스타일 정리 및 컴파일 오류 제거
This commit is contained in:
@@ -7,32 +7,35 @@ 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>());
|
||||
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,
|
||||
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);
|
||||
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);
|
||||
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,
|
||||
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
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
int InstallYtdlp();
|
||||
int InstallYtdlp(boost::asio::io_context& ctx);
|
||||
|
||||
int CheckUpdate(boost::asio::io_context& ctx);
|
||||
|
||||
|
||||
82
src/main.cc
82
src/main.cc
@@ -3,54 +3,52 @@
|
||||
#include "utils/update_checker.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
boost::asio::io_context ctx;
|
||||
boost::system::error_code ec;
|
||||
char buf[8192];
|
||||
std::string output;
|
||||
boost::asio::io_context ctx;
|
||||
boost::system::error_code ec;
|
||||
char buf[8192];
|
||||
std::string output;
|
||||
|
||||
utils::CheckUpdate(ctx);
|
||||
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" });
|
||||
/*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;
|
||||
}*/
|
||||
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(
|
||||
"yt-dlp", { "-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
|
||||
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" });
|
||||
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, 16384),
|
||||
read_ec);
|
||||
if (bytes_read > 0) {
|
||||
std::cout.write(buf, bytes_read);
|
||||
}
|
||||
if (read_ec == boost::asio::error::eof || read_ec) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
int ValidateCommand(boost::asio::io_context& ctx, std::string cmd, const std::vector<std::string>& args) {
|
||||
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) {
|
||||
@@ -19,30 +20,31 @@ int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
|
||||
return ExecuteCommand(ctx, cmd, args, ignored);
|
||||
}
|
||||
|
||||
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd, std::string& result) {
|
||||
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) {
|
||||
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::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);
|
||||
boost::asio::read(proc, boost::asio::dynamic_buffer(result), ec);
|
||||
|
||||
proc.wait();
|
||||
proc.wait();
|
||||
|
||||
return proc.exit_code();
|
||||
}
|
||||
catch (const boost::process::system_error& e) {
|
||||
return -1;
|
||||
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,
|
||||
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});
|
||||
|
||||
@@ -57,7 +57,8 @@ void DownloadFileFromHTTPS(std::string url, std::string filename) {
|
||||
boost::beast::flat_buffer buffer;
|
||||
|
||||
// 응답 파서 만들기
|
||||
boost::beast::http::response_parser<boost::beast::http::dynamic_body> parser;
|
||||
boost::beast::http::response_parser<boost::beast::http::dynamic_body>
|
||||
parser;
|
||||
|
||||
// body 제한 해제 (무제한)
|
||||
parser.body_limit((std::numeric_limits<std::uint64_t>::max)());
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
int InstallYtdlp() {
|
||||
int InstallYtdlp(boost::asio::io_context& ctx) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "ytdlp is unavailable. downloading ytdlp...";
|
||||
#ifdef WIN32
|
||||
DownloadFileFromHTTPS(
|
||||
@@ -16,21 +16,22 @@ int InstallYtdlp() {
|
||||
DownloadFileFromHTTPS(
|
||||
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp",
|
||||
"yt-dlp");
|
||||
ExecuteCommand(boost::process::environment::find_executable("chmod").c_str(),
|
||||
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++;
|
||||
int newline_pos = start_pos;
|
||||
while (newline_pos < string.size()) {
|
||||
if (string[newline_pos] == '\n') {
|
||||
return newline_pos;
|
||||
}
|
||||
return newline_pos;
|
||||
newline_pos++;
|
||||
}
|
||||
return newline_pos;
|
||||
}
|
||||
|
||||
int CheckUpdate(boost::asio::io_context& ctx) {
|
||||
@@ -39,27 +40,30 @@ int CheckUpdate(boost::asio::io_context& ctx) {
|
||||
int newline_pos = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
if (ExecuteCommand(ctx, "yt-dlp.exe", { "--version", "--newline" }, output) != 0) {
|
||||
InstallYtdlp();
|
||||
ExecuteCommand(ctx, "yt-dlp.exe", { "--version", "--newline" }, output);
|
||||
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);
|
||||
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
|
||||
<< output.substr(0, output.size() - 1);
|
||||
output = "";
|
||||
ExecuteCommand(ctx, "yt-dlp.exe", { "-U", "--newline" }, output);
|
||||
ExecuteCommand(ctx, "yt-dlp.exe", {"-U", "--newline"}, output);
|
||||
#else
|
||||
if (ExecuteCommand(ctx, "yt-dlp", { "--version", "--newline" }, output) != 0) {
|
||||
InstallYtdlp();
|
||||
ExecuteCommand(ctx, "yt-dlp", { "--version", "--newline" }, output);
|
||||
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);
|
||||
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
|
||||
<< output.substr(0, output.size() - 1);
|
||||
output = "";
|
||||
ExecuteCommand(ctx, "yt-dlp", { "-U", "--newline" }, 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++;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user