mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 01:45:15 +00:00
스트리밍 구현 끝
This commit is contained in:
60
include/Utils/AsyncDownloadManager.hpp
Normal file
60
include/Utils/AsyncDownloadManager.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#ifndef _ASYNCDOWNLOADMANAGER_HPP_
|
||||
#define _ASYNCDOWNLOADMANAGER_HPP_
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <dpp/dpp.h>
|
||||
#include <Queue/MusicQueue.hpp>
|
||||
|
||||
namespace bumbleBee {
|
||||
/// @brief 싱글톤 멀티스레딩 다운로드 매니저
|
||||
class [[deprecated]] AsyncDownloadManager {
|
||||
public:
|
||||
static AsyncDownloadManager& getInstance(int worker_count, std::weak_ptr<dpp::cluster> weak_cluster) {
|
||||
static AsyncDownloadManager dl(worker_count);
|
||||
dl.weak_cluster = weak_cluster;
|
||||
return dl;
|
||||
}
|
||||
void enqueue(std::pair<std::string, dpp::message> query) {
|
||||
std::thread th(&bumbleBee::AsyncDownloadManager::enqueueAsyncDL, this, query);
|
||||
th.detach();
|
||||
}
|
||||
void stop() {
|
||||
auto cluster = weak_cluster.lock();
|
||||
cluster->log(dpp::ll_info, "AsyncDownloadManager stop/destructor called.");
|
||||
terminate = true;
|
||||
dlQueueCondition.notify_all();
|
||||
|
||||
for (auto& t : worker_thread) {
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
~AsyncDownloadManager(){
|
||||
stop();
|
||||
}
|
||||
|
||||
private:
|
||||
AsyncDownloadManager(int worker_count){
|
||||
worker_thread.reserve(worker_count);
|
||||
terminate = false;
|
||||
for (int i=0; i<worker_count; i++) {
|
||||
worker_thread.emplace_back([this](){this->downloadWorker();});
|
||||
}
|
||||
}
|
||||
|
||||
void enqueueAsyncDL(std::pair<std::string, dpp::message> query);
|
||||
void downloadWorker();
|
||||
|
||||
std::queue<std::pair<std::string, dpp::message>> downloadQueue;
|
||||
std::condition_variable dlQueueCondition;
|
||||
std::mutex dlQueueMutex;
|
||||
std::weak_ptr<dpp::cluster> weak_cluster;
|
||||
std::vector<std::thread> worker_thread;
|
||||
bool terminate;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
static void validateYTDLPFFMPEGBinary(std::shared_ptr<dpp::cluster> cluster) {
|
||||
cluster->log(dpp::ll_info, "Checking if yt-dlp and ffmpeg is available...");
|
||||
std::queue<std::string> result = ConsoleUtils::getResultFromCommand(settingsManager::FFMPEG_CMD + " -version");
|
||||
std::queue<std::string> result = ConsoleUtils::getResultFromCommand(settingsManager::getFFMPEG_CMD() + " -version");
|
||||
std::string front = result.front();
|
||||
if (front[0] != 'f' ||
|
||||
front[1] != 'f' ||
|
||||
@@ -40,8 +40,9 @@ public:
|
||||
system("tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz");
|
||||
system("rm ffmpeg-master-latest-linux64-gpl.tar.xz");
|
||||
system("mv ffmpeg-master-latest-linux64-gpl ffmpeg");
|
||||
settingsManager::setFFMPEG_CMD("./ffmpeg/bin/ffmpeg");
|
||||
}
|
||||
result = ConsoleUtils::getResultFromCommand(settingsManager::YTDLP_CMD + " --version");
|
||||
result = ConsoleUtils::getResultFromCommand(settingsManager::getYTDLP_CMD() + " --version");
|
||||
front = result.front();
|
||||
if ((front[0]-'0' < 0 || front[0]-'0' > 9) ||
|
||||
(front[1]-'0' < 0 || front[1]-'0' > 9) ||
|
||||
@@ -58,6 +59,7 @@ public:
|
||||
|
||||
system("curl -LO https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp");
|
||||
system("chmod +x ./yt-dlp");
|
||||
settingsManager::setYTDLP_CMD("./yt-dlp");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user