mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
스트리밍 구현 끝
This commit is contained in:
68
src/Audio/MusicPlayManager.cpp
Normal file
68
src/Audio/MusicPlayManager.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <Audio/MusicPlayManager.hpp>
|
||||
#include <ogg/ogg.h>
|
||||
#include <oggz/oggz.h>
|
||||
|
||||
namespace bumbleBee {
|
||||
|
||||
void MusicPlayManager::on_voice_ready(const dpp::voice_ready_t& event) {
|
||||
std::unique_lock<std::mutex> queueEmptyLock(queueEmptyMutex);
|
||||
queuedCondition.wait(queueEmptyLock, [&]{
|
||||
return queue->queue.size() != 0;
|
||||
});
|
||||
|
||||
auto np = queue->nowplaying();
|
||||
auto music = *np;
|
||||
|
||||
std::string command = "./streamOpus.sh ./yt-dlp ffmpeg https://youtu.be/";
|
||||
command += music.id;
|
||||
|
||||
OGGZ* og = oggz_open_stdio(popen(command.c_str(), "r"), OGGZ_READ);
|
||||
|
||||
oggz_set_read_callback(
|
||||
og, -1,
|
||||
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
|
||||
auto voiceConn = (dpp::discord_voice_client *)user_data;
|
||||
|
||||
voiceConn->send_audio_opus(packet->op.packet, packet->op.bytes);
|
||||
|
||||
return 0;
|
||||
},
|
||||
(void *)event.voice_client
|
||||
);
|
||||
|
||||
while (event.voice_client && !event.voice_client->terminating) {
|
||||
static const constexpr long CHUNK_READ = BUFSIZ * 2;
|
||||
|
||||
const long read_bytes = oggz_read(og, CHUNK_READ);
|
||||
|
||||
/* break on eof */
|
||||
if (!read_bytes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//event.from->creator->log(dpp::ll_info, std::string("Sending ") + music.id + " complete!");
|
||||
oggz_close(og);
|
||||
|
||||
event.voice_client->insert_marker("end");
|
||||
|
||||
queueEmptyLock.unlock();
|
||||
}
|
||||
|
||||
void MusicPlayManager::on_voice_track_marker(const dpp::voice_track_marker_t& event) {
|
||||
queue->next_music();
|
||||
}
|
||||
|
||||
void MusicPlayManager::on_voice_client_disconnect(const dpp::voice_client_disconnect_t& event) {
|
||||
event.voice_client->stop_audio();
|
||||
}
|
||||
|
||||
void MusicPlayManager::queue_music(const std::shared_ptr<MusicQueueElement> music) {
|
||||
queue->enqueue(music);
|
||||
}
|
||||
|
||||
void MusicPlayManager::send_audio_to_voice(const MusicQueueElement& music, const dpp::voice_ready_t &event) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,39 +2,80 @@
|
||||
#include <memory>
|
||||
#include <Settings/SettingsManager.hpp>
|
||||
#include <Utils/VersionsCheckUtils.hpp>
|
||||
#include <Audio/MusicPlayManager.hpp>
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee{
|
||||
BumbleBee::BumbleBee() {
|
||||
settingsManager::load();
|
||||
this->cluster = std::make_shared<dpp::cluster>(settingsManager::TOKEN);
|
||||
dbDriver = sql::mariadb::get_driver_instance();
|
||||
this->dbURL = std::make_shared<sql::SQLString>(settingsManager::DBURL);
|
||||
sql::Properties pro({
|
||||
{"user", std::string(settingsManager::DBUSER)},
|
||||
{"password", std::string(settingsManager::DBPASSWORD)}
|
||||
});
|
||||
this->dbProperties = std::make_shared<sql::Properties>(pro);
|
||||
if (!settingsManager::load()) {
|
||||
std::cout << "Please configure confing.json" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cluster->on_log(dpp::utility::cout_logger());
|
||||
cluster = std::make_shared<dpp::cluster>(settingsManager::getTOKEN());
|
||||
|
||||
cluster->on_log([](const dpp::log_t& event) {
|
||||
if (event.severity >= settingsManager::getLOGLEVEL()) {
|
||||
std::cout << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << "\n";
|
||||
}
|
||||
});
|
||||
cluster->on_slashcommand([this](const dpp::slashcommand_t& event){on_slashcommand(event);});
|
||||
cluster->on_ready([this](const dpp::ready_t &event){on_ready(event);});
|
||||
|
||||
queue = std::make_shared<MusicQueue>();
|
||||
|
||||
VersionsCheckUtils::validateYTDLPFFMPEGBinary(cluster);
|
||||
VersionsCheckUtils::updateytdlp(cluster);
|
||||
|
||||
musicManager = std::make_shared<MusicPlayManager>(cluster);
|
||||
|
||||
commands["d"] = std::make_shared<commands::Delete> (cluster->cluster_id, musicManager);
|
||||
commands["l"] = std::make_shared<commands::Leave> (cluster->cluster_id, musicManager);
|
||||
commands["p"] = std::make_shared<commands::Play> (cluster->cluster_id, musicManager);
|
||||
commands["q"] = std::make_shared<commands::Queue> (cluster->cluster_id, musicManager);
|
||||
commands["r"] = std::make_shared<commands::Repeat> (cluster->cluster_id, musicManager);
|
||||
commands["s"] = std::make_shared<commands::Skip> (cluster->cluster_id, musicManager);
|
||||
|
||||
for (auto command : commands) {
|
||||
for (auto aliase : command.second->aliases) {
|
||||
commands[aliase] = std::shared_ptr<commands::ICommand>(command.second);
|
||||
commands[aliase]->set_name(aliase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BumbleBee::start() { this->cluster->start(dpp::st_wait); }
|
||||
|
||||
void BumbleBee::on_slashcommand(const dpp::slashcommand_t &event) {
|
||||
for (auto command : commands)
|
||||
for (auto alias : command->nameAndAliases)
|
||||
if (event.command.get_command_name() == alias.name)
|
||||
(*command)(event);
|
||||
if (commands.find(event.command.get_command_name()) != commands.end()) {
|
||||
event.thinking();
|
||||
auto command = commands.at(event.command.get_command_name());
|
||||
std::thread t([](const dpp::slashcommand_t &event, std::shared_ptr<commands::ICommand> command){
|
||||
command->execute(event);
|
||||
}, event, command);
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void BumbleBee::on_ready(const dpp::ready_t &event) {
|
||||
cluster->log(dpp::loglevel::ll_info, "Bot ready.");
|
||||
|
||||
if (event.guilds.size() == 0) {
|
||||
cluster->log(dpp::loglevel::ll_info, "Bot is not on any server! Please invite this bot to any server.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (dpp::run_once<struct register_bot_commands>()) {
|
||||
if (settingsManager::getCLCOMMAND()) {
|
||||
cluster->log(dpp::loglevel::ll_info, "Clear Pre-installed commands");
|
||||
cluster->global_bulk_command_delete([](const dpp::confirmation_callback_t &t){
|
||||
std::cout << "cleared Pre-installed commands. Please restart Bot" << std::endl;
|
||||
settingsManager::setCLCOMMAND(false);
|
||||
exit(0);
|
||||
});
|
||||
return;
|
||||
}
|
||||
for (auto command : commands)
|
||||
cluster->global_command_create(*command.second);
|
||||
}
|
||||
cluster->log(dpp::loglevel::ll_info, "Command created.");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
#include <BumbleBeeCommand.hpp>
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Delete::operator()(const dpp::slashcommand_t &event) {
|
||||
void Delete::execute(const dpp::slashcommand_t &event) {
|
||||
event.edit_original_response(dpp::message("delete"));
|
||||
}
|
||||
|
||||
void Delete::init() {
|
||||
aliases.push_back("delete");
|
||||
}
|
||||
}
|
||||
10
src/Commands/Leave.cpp
Normal file
10
src/Commands/Leave.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Leave::execute(const dpp::slashcommand_t &event) {
|
||||
event.edit_original_response(dpp::message("leave"));
|
||||
}
|
||||
|
||||
void Leave::init() {
|
||||
}
|
||||
}
|
||||
70
src/Commands/Play.cpp
Normal file
70
src/Commands/Play.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
#include <Utils/ConsoleUtils.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Play::execute(const dpp::slashcommand_t &event) {
|
||||
dpp::guild *g = dpp::find_guild(event.command.guild_id);
|
||||
|
||||
if (!g) { //wtf?
|
||||
event.edit_original_response(dpp::message("GUILD NOT FOUND!! WHAT IS THIS SORCERY??"));
|
||||
return;
|
||||
}
|
||||
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
|
||||
{
|
||||
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
|
||||
return;
|
||||
}
|
||||
if (!event.from->get_voice(event.command.guild_id) && !g->connect_member_voice(event.command.usr.id)) {
|
||||
event.edit_original_response(dpp::message("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!"));
|
||||
return;
|
||||
}
|
||||
std::string query = std::get<std::string>(event.get_parameter("query"));
|
||||
|
||||
std::queue<std::string> ids = ConsoleUtils::getResultFromCommand("./yt-dlp --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
|
||||
|
||||
std::queue<MusicQueueElement> musics;
|
||||
|
||||
dpp::message origMsg;
|
||||
|
||||
if (ids.size() >= 2) {
|
||||
event.from->creator->log(dpp::ll_info, "Playlist detected.");
|
||||
while (!ids.empty()) {
|
||||
if (ids.front() == "") {
|
||||
ids.pop();
|
||||
continue;
|
||||
}
|
||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + ids.front());
|
||||
|
||||
MusicQueueElement music(
|
||||
ids.front(),
|
||||
query,
|
||||
event.command.usr
|
||||
);
|
||||
|
||||
musics.push(music);
|
||||
ids.pop();
|
||||
}
|
||||
}
|
||||
|
||||
MusicQueueElement music(
|
||||
ids.front(),
|
||||
query,
|
||||
event.command.usr
|
||||
);
|
||||
musics.push(music);
|
||||
|
||||
while (!musics.empty()) {
|
||||
auto element = musics.front();
|
||||
musicManager->queue_music(std::make_shared<MusicQueueElement>(element));
|
||||
musics.pop();
|
||||
}
|
||||
|
||||
event.edit_original_response(dpp::message("play"));
|
||||
musicManager->queuedCondition.notify_one();
|
||||
}
|
||||
|
||||
void Play::init() {
|
||||
add_option(dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", true));
|
||||
}
|
||||
}
|
||||
10
src/Commands/Queue.cpp
Normal file
10
src/Commands/Queue.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Queue::execute(const dpp::slashcommand_t &event) {
|
||||
event.edit_original_response(dpp::message("queue"));
|
||||
}
|
||||
|
||||
void Queue::init() {
|
||||
}
|
||||
}
|
||||
10
src/Commands/Repeat.cpp
Normal file
10
src/Commands/Repeat.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Repeat::execute(const dpp::slashcommand_t &event) {
|
||||
event.edit_original_response(dpp::message("repeat"));
|
||||
}
|
||||
|
||||
void Repeat::init() {
|
||||
}
|
||||
}
|
||||
10
src/Commands/Shuffle.cpp
Normal file
10
src/Commands/Shuffle.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Shuffle::execute(const dpp::slashcommand_t &event) {
|
||||
event.edit_original_response(dpp::message("shuffle"));
|
||||
}
|
||||
|
||||
void Shuffle::init() {
|
||||
}
|
||||
}
|
||||
10
src/Commands/Skip.cpp
Normal file
10
src/Commands/Skip.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
void Skip::execute(const dpp::slashcommand_t &event) {
|
||||
event.edit_original_response(dpp::message("skip"));
|
||||
}
|
||||
|
||||
void Skip::init() {
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,44 @@
|
||||
#include <MusicQueue.hpp>
|
||||
#include <Queue/MusicQueue.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace bumbleBee {
|
||||
|
||||
void MusicQueue::enqueue(std::shared_ptr<MusicQueueElement> Element) {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
queue.push_back(Element);
|
||||
queue.push_back(Element);
|
||||
if (queue.size() == 1) // 이전에 하나도 없었다는 말이므로.
|
||||
currentPlayingPosition = queue.begin(); // 첫번째 곡으로 iterator를 옮겨준다.
|
||||
}
|
||||
|
||||
std::shared_ptr<MusicQueueElement> MusicQueue::dequeue() {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
auto value = std::move(queue.front());
|
||||
auto value = queue.front();
|
||||
queue.pop_front();
|
||||
return value;
|
||||
}
|
||||
std::shared_ptr<MusicQueueElement> MusicQueue::findById(std::string id) {
|
||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::findById(std::string id) {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
int index = 0;
|
||||
for (auto iter = queue.begin(); iter != queue.end(); iter++) {
|
||||
if ((*iter).get()->id == id)
|
||||
return *iter;
|
||||
return iter;
|
||||
}
|
||||
return std::shared_ptr<MusicQueueElement>();
|
||||
return queue.end();
|
||||
}
|
||||
std::weak_ptr<MusicQueueElement> MusicQueue::nowplaying()
|
||||
{
|
||||
std::shared_ptr<MusicQueueElement> MusicQueue::nowplaying() {
|
||||
return *currentPlayingPosition;
|
||||
}
|
||||
std::weak_ptr<MusicQueueElement> MusicQueue::next_music() {
|
||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::next_music() {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
if (currentPlayingPosition == queue.end())
|
||||
return *currentPlayingPosition;
|
||||
|
||||
++currentPlayingPosition;
|
||||
|
||||
if (repeat && currentPlayingPosition == queue.end()) {
|
||||
if (currentPlayingPosition == std::prev(queue.end()) || !repeat)
|
||||
return queue.end();
|
||||
if (currentPlayingPosition == std::prev(queue.end()) || repeat)
|
||||
currentPlayingPosition = queue.begin();
|
||||
}
|
||||
return *currentPlayingPosition;
|
||||
else
|
||||
++currentPlayingPosition;
|
||||
return currentPlayingPosition;
|
||||
}
|
||||
std::weak_ptr<MusicQueueElement> MusicQueue::jump_to_index(int idx) {
|
||||
std::shared_ptr<MusicQueueElement> MusicQueue::jump_to_index(int idx) {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
int index = 0;
|
||||
for (auto iter = queue.begin(); iter != queue.end(); iter++) {
|
||||
@@ -50,4 +49,4 @@ std::weak_ptr<MusicQueueElement> MusicQueue::jump_to_index(int idx) {
|
||||
}
|
||||
return std::shared_ptr<MusicQueueElement>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,82 @@
|
||||
#include <Settings/SettingsManager.hpp>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <Utils/ConsoleUtils.hpp>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace bumbleBee {
|
||||
|
||||
std::string settingsManager::TOKEN = "";
|
||||
std::string settingsManager::YTDLP_CMD = "./yt-dlp";
|
||||
std::string settingsManager::FFMPEG_CMD = "./ffmpeg/bin/ffmpeg";
|
||||
std::string settingsManager::DBURL = "";
|
||||
std::string settingsManager::DBUSER = "";
|
||||
std::string settingsManager::DBPASSWORD = "";
|
||||
dpp::loglevel settingsManager::LOGLEVEL = dpp::ll_debug;
|
||||
bool settingsManager::CLCOMMAND = false;
|
||||
|
||||
void settingsManager::load() {
|
||||
bool settingsManager::validateToken() {
|
||||
nlohmann::json response;
|
||||
if (ConsoleUtils::getResultFromCommand("which curl").size() == 0) {
|
||||
std::cout << "curl is unavaliable. unresolable error please install curl." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string stresult = ConsoleUtils::getResultFromCommand("curl -sX GET \"https://discord.com/api/v10/users/@me\" -H \"Authorization: Bot " +
|
||||
TOKEN + "\"").front();
|
||||
std::stringstream ss(stresult);
|
||||
ss >> response;
|
||||
|
||||
if (response.contains("message") && response["message"] == "401: Unauthorized") {
|
||||
std::cout << "Token is invalid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool settingsManager::load() {
|
||||
nlohmann::json configdocument;
|
||||
try {
|
||||
std::ifstream configfile("config.json");
|
||||
if (!configfile) {
|
||||
saveToFile();
|
||||
return false;
|
||||
}
|
||||
configfile >> configdocument;
|
||||
|
||||
TOKEN = configdocument["TOKEN"];
|
||||
|
||||
if (!validateToken())
|
||||
return false;
|
||||
|
||||
YTDLP_CMD = configdocument["YTDLP_CMD"];
|
||||
FFMPEG_CMD = configdocument["FFMPEG_CMD"];
|
||||
DBURL = configdocument["DBURL"];
|
||||
DBUSER = configdocument["DBUSER"];
|
||||
DBPASSWORD = configdocument["DBPASSWORD"];
|
||||
|
||||
std::string level = configdocument["LOGLEVEL"];
|
||||
|
||||
std::transform(level.begin(), level.end(), level.begin(), ::tolower);
|
||||
if (level == "trace")
|
||||
LOGLEVEL = dpp::ll_trace;
|
||||
else if (level == "debug")
|
||||
LOGLEVEL = dpp::ll_debug;
|
||||
else if (level == "warning")
|
||||
LOGLEVEL = dpp::ll_warning;
|
||||
else if (level == "error")
|
||||
LOGLEVEL = dpp::ll_error;
|
||||
else if (level == "critical")
|
||||
LOGLEVEL = dpp::ll_critical;
|
||||
else // 값이 병신같을때 기본값으로 ll_info 부여
|
||||
LOGLEVEL = dpp::ll_info;
|
||||
|
||||
CLCOMMAND = configdocument["CLEAR_PREVIOUS_COMMAND"];
|
||||
}
|
||||
catch (const nlohmann::json::type_error& e) {
|
||||
saveToFile();
|
||||
std::ifstream configfile("config.json");
|
||||
configfile >> configdocument;
|
||||
|
||||
TOKEN = configdocument["TOKEN"];
|
||||
YTDLP_CMD = configdocument["YTDLP_CMD"];
|
||||
FFMPEG_CMD = configdocument["FFMPEG_CMD"];
|
||||
DBURL = configdocument["DBURL"];
|
||||
DBUSER = configdocument["DBUSER"];
|
||||
DBPASSWORD = configdocument["DBPASSWORD"];
|
||||
return load();
|
||||
}
|
||||
catch (const nlohmann::json::parse_error& e) {
|
||||
saveToFile();
|
||||
std::ifstream configfile("config.json");
|
||||
configfile >> configdocument;
|
||||
|
||||
TOKEN = configdocument["TOKEN"];
|
||||
YTDLP_CMD = configdocument["YTDLP_CMD"];
|
||||
FFMPEG_CMD = configdocument["FFMPEG_CMD"];
|
||||
DBURL = configdocument["DBURL"];
|
||||
DBUSER = configdocument["DBUSER"];
|
||||
DBPASSWORD = configdocument["DBPASSWORD"];
|
||||
return load();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void settingsManager::saveToFile() {
|
||||
@@ -54,9 +85,29 @@ void settingsManager::saveToFile() {
|
||||
configdocument["TOKEN"] = TOKEN;
|
||||
configdocument["YTDLP_CMD"] = YTDLP_CMD;
|
||||
configdocument["FFMPEG_CMD"] = FFMPEG_CMD;
|
||||
configdocument["DBURL"] = DBURL;
|
||||
configdocument["DBUSER"] = DBUSER;
|
||||
configdocument["DBPASSWORD"] = DBPASSWORD;
|
||||
|
||||
switch (LOGLEVEL) {
|
||||
case dpp::ll_trace:
|
||||
configdocument["LOGLEVEL"] = "trace";
|
||||
break;
|
||||
case dpp::ll_debug:
|
||||
configdocument["LOGLEVEL"] = "debug";
|
||||
break;
|
||||
case dpp::ll_info:
|
||||
configdocument["LOGLEVEL"] = "info";
|
||||
break;
|
||||
case dpp::ll_warning:
|
||||
configdocument["LOGLEVEL"] = "warning";
|
||||
break;
|
||||
case dpp::ll_error:
|
||||
configdocument["LOGLEVEL"] = "error";
|
||||
break;
|
||||
default:
|
||||
configdocument["LOGLEVEL"] = "critical";
|
||||
break;
|
||||
}
|
||||
|
||||
configdocument["CLEAR_PREVIOUS_COMMAND"] = CLCOMMAND;
|
||||
|
||||
std::ofstream configFile("config.json");
|
||||
if (configFile.is_open()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <AsyncDownloadManager.hpp>
|
||||
#include <Utils/AsyncDownloadManager.hpp>
|
||||
#include <sstream>
|
||||
#include "Utils/ConsoleUtils.hpp"
|
||||
#include "Settings/SettingsManager.hpp"
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <memory>
|
||||
|
||||
namespace bumbleBee {
|
||||
|
||||
void AsyncDownloadManager::enqueueAsyncDL(std::pair<std::string, dpp::message> query) {
|
||||
std::lock_guard<std::mutex> lock(dlQueueMutex);
|
||||
downloadQueue.push(query);
|
||||
@@ -39,7 +38,7 @@ void AsyncDownloadManager::downloadWorker() {
|
||||
cluster->log(dpp::ll_info, "AsyncDownloadManager: " + query + " accepted.");
|
||||
|
||||
std::queue<std::string> ids =
|
||||
ConsoleUtils::getResultFromCommand(settingsManager::YTDLP_CMD +
|
||||
ConsoleUtils::getResultFromCommand(settingsManager::getYTDLP_CMD() +
|
||||
" --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
|
||||
|
||||
if (ids.size() >= 2) {
|
||||
@@ -53,18 +52,18 @@ void AsyncDownloadManager::downloadWorker() {
|
||||
enqueue(std::make_pair("https://youtu.be/" + ids.front(), oRes));
|
||||
ids.pop();
|
||||
}
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::queue<std::string> urls =
|
||||
ConsoleUtils::getResultFromCommand(settingsManager::YTDLP_CMD +
|
||||
ConsoleUtils::getResultFromCommand(settingsManager::getYTDLP_CMD() +
|
||||
" -f ba* --print urls https://youtu.be/" + ids.front());
|
||||
|
||||
cluster->log(dpp::ll_debug, "url: " + urls.front());
|
||||
|
||||
FILE* stream;
|
||||
|
||||
musicQueue->enqueue(std::make_shared<MusicQueueElement>(oRes, ids.front(), urls.front(), stream));
|
||||
// musicQueue->enqueue(std::make_shared<MusicQueueElement>(oRes, ids.front(), urls.front(), stream));
|
||||
|
||||
std::string downloadID = ids.front();
|
||||
|
||||
@@ -76,12 +75,10 @@ void AsyncDownloadManager::downloadWorker() {
|
||||
|
||||
cluster->log(dpp::ll_info, "Thread id: " + tid.str() + ": " + downloadID + " accepted.");
|
||||
|
||||
std::string command = std::string("./streamAndDownload.sh " + settingsManager::YTDLP_CMD + " " + downloadID + " " + settingsManager::FFMPEG_CMD);
|
||||
std::string command = std::string("./streamOpus.sh " + settingsManager::getYTDLP_CMD() + " " + downloadID + " " + settingsManager::getFFMPEG_CMD());
|
||||
stream = popen(command.c_str(), "r");
|
||||
pclose(stream);
|
||||
stream = NULL;
|
||||
|
||||
cluster->log(dpp::ll_info, "Thread id: " + tid.str() + ": " + downloadID + " download complete.");
|
||||
|
||||
cluster->log(dpp::ll_info, "Thread id: " + tid.str() + " Opened stream: " + downloadID);
|
||||
});
|
||||
th.detach();
|
||||
}
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -1,18 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <BumbleBee.hpp>
|
||||
#include <AsyncDownloadManager.hpp>
|
||||
#include <thread>
|
||||
|
||||
int main() {
|
||||
bumbleBee::BumbleBee bot;
|
||||
|
||||
bumbleBee::AsyncDownloadManager& manager = bumbleBee::AsyncDownloadManager::getInstance(5, bot.cluster, bot.queue);
|
||||
manager.enqueue(std::make_pair("https://music.youtube.com/watch?v=4NnqIu_v1QA&si=buZP2UwzQtJLENmb", nullptr));
|
||||
|
||||
std::thread th([](){sleep(60);});
|
||||
th.join();
|
||||
manager.stop();
|
||||
|
||||
std::cout << "\n\n\n\n\nend\n\n\n\n\n\n\n";
|
||||
//bot.start();
|
||||
bot.start();
|
||||
}
|
||||
Reference in New Issue
Block a user