스타일 정리 및 컴파일 오류 제거

This commit is contained in:
2025-08-31 02:29:42 +09:00
parent f3974bb86f
commit e26d20a869
6 changed files with 97 additions and 89 deletions

View File

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

View File

@@ -5,7 +5,7 @@
namespace utils {
int InstallYtdlp();
int InstallYtdlp(boost::asio::io_context& ctx);
int CheckUpdate(boost::asio::io_context& ctx);

View File

@@ -13,16 +13,14 @@ int main(int argc, char* argv[]) {
#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" });
"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);
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;
@@ -35,14 +33,14 @@ int main(int argc, char* argv[]) {
}*/
#else
auto ytdlp_pipe = utils::OpenPipe(
"yt-dlp", { "-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" });
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);
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192), read_ec);
if (bytes_read > 0) {
std::cout.write(buf, bytes_read);
}

View File

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

View File

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

View File

@@ -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,7 +16,8 @@ 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;
@@ -39,21 +40,24 @@ 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;