Some updates
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include <misc/strobf.h>
|
||||
#include <misc/scope_guard.h>
|
||||
#include <bbcode/bbcodes.h>
|
||||
#include <src/music/MusicPlaylist.h>
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
using namespace std::chrono;
|
||||
@@ -818,15 +819,33 @@ command_result ConnectedClient::handleCommandPlaylistSongList(ts::Command &cmd)
|
||||
Command notify(this->notify_response_command("notifyplaylistsonglist"));
|
||||
notify["playlist_id"] = playlist->playlist_id();
|
||||
|
||||
auto extract_metadata = cmd.hasParm("extract-metadata");
|
||||
|
||||
size_t index = 0;
|
||||
for(const auto& song : songs) {
|
||||
notify[index]["song_id"] = song->id;
|
||||
notify[index]["song_id"] = song->song_id;
|
||||
notify[index]["song_invoker"] = song->invoker;
|
||||
notify[index]["song_previous_song_id"] = song->previous_song_id;
|
||||
notify[index]["song_url"] = song->url;
|
||||
notify[index]["song_url"] = song->original_url;
|
||||
notify[index]["song_url_loader"] = song->url_loader;
|
||||
notify[index]["song_loaded"] = song->loaded;
|
||||
notify[index]["song_metadata"] = song->metadata;
|
||||
notify[index]["song_loaded"] = song->metadata.is_loaded();
|
||||
notify[index]["song_metadata"] = song->metadata.json_string;
|
||||
|
||||
if(extract_metadata) {
|
||||
auto metadata = song->metadata.loaded_data;
|
||||
if(extract_metadata && song->metadata.is_loaded() && metadata) {
|
||||
notify[index]["song_metadata_title"] = metadata->title;
|
||||
notify[index]["song_metadata_description"] = metadata->description;
|
||||
notify[index]["song_metadata_url"] = metadata->url;
|
||||
notify[index]["song_metadata_length"] = metadata->length.count();
|
||||
if(auto thumbnail = static_pointer_cast<::music::ThumbnailUrl>(metadata->thumbnail); thumbnail && thumbnail->type() == ::music::THUMBNAIL_URL) {
|
||||
notify[index]["song_metadata_thumbnail_url"] = thumbnail->url();
|
||||
} else {
|
||||
notify[index]["song_metadata_thumbnail_url"] = "none";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
this->sendCommand(notify);
|
||||
@@ -862,18 +881,30 @@ command_result ConnectedClient::handleCommandPlaylistSongAdd(ts::Command &cmd) {
|
||||
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_song_needed_add_power, permission::i_playlist_song_add_power); perr)
|
||||
return command_result{perr};
|
||||
|
||||
if(!cmd[0].has("invoker"))
|
||||
cmd["invoker"] = "";
|
||||
if(cmd[0].has("invoker"))
|
||||
cmd["type"] = "";
|
||||
else if(!cmd[0].has("type"))
|
||||
cmd["type"] = "";
|
||||
|
||||
if(!cmd[0].has("previous")) {
|
||||
auto songs = playlist->list_songs();
|
||||
if(songs.empty())
|
||||
cmd["previous"] = "0";
|
||||
else
|
||||
cmd["previous"] = songs.back()->id;
|
||||
cmd["previous"] = songs.back()->song_id;
|
||||
}
|
||||
|
||||
auto& type = cmd[0]["type"];
|
||||
std::string loader_string{""};
|
||||
if((type.castable<int>() && type.as<int>() == 0) || type.as<string>() == "yt") {
|
||||
loader_string = "YouTube";
|
||||
} else if((type.castable<int>() && type.as<int>() == 1) || type.as<string>() == "ffmpeg") {
|
||||
loader_string = "FFMpeg";
|
||||
} else if((type.castable<int>() && type.as<int>() == 2) || type.as<string>() == "channel") {
|
||||
loader_string = "ChannelProvider";
|
||||
}
|
||||
|
||||
auto song = playlist->add_song(_this.lock(), cmd["url"], cmd["invoker"], cmd["previous"]);
|
||||
auto song = playlist->add_song(_this.lock(), cmd["url"], loader_string, cmd["previous"]);
|
||||
if(!song) return command_result{error::vs_critical};
|
||||
|
||||
return command_result{error::ok};
|
||||
@@ -927,6 +958,7 @@ command_result ConnectedClient::handleCommandPlaylistSongRemove(ts::Command &cmd
|
||||
|
||||
/****** legacy ******/
|
||||
command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
||||
#if false
|
||||
CMD_REQ_SERVER;
|
||||
CMD_RESET_IDLE;
|
||||
CMD_CHK_AND_INC_FLOOD_POINTS(25);
|
||||
@@ -947,7 +979,7 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
||||
auto songs = playlist->list_songs();
|
||||
int begin_index{0};
|
||||
for(auto it = songs.begin(); it != songs.end(); it++)
|
||||
if((*it)->id == playlist->currently_playing())
|
||||
if((*it)->song_id == playlist->currently_playing())
|
||||
break;
|
||||
else
|
||||
begin_index--;
|
||||
@@ -957,12 +989,12 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
||||
notify = Command(this->notify_response_command("notifymusicqueueentry"));
|
||||
|
||||
auto song = *it;
|
||||
notify[command_index]["song_id"] = song->id;
|
||||
notify[command_index]["song_url"] = song->url;
|
||||
notify[command_index]["song_id"] = song->song_id;
|
||||
notify[command_index]["song_url"] = song->original_url;
|
||||
notify[command_index]["song_invoker"] = song->invoker;
|
||||
notify[command_index]["song_loaded"] = song->loaded;
|
||||
notify[command_index]["song_loaded"] = song->metadata.is_loaded();
|
||||
|
||||
auto entry = song->load_future ? song->load_future->getValue({}) : nullptr;
|
||||
auto entry = song->load_future && song->load_future->succeeded() ? song->load_future->getValue({}) : nullptr;
|
||||
if(entry) {
|
||||
notify[command_index]["song_loaded"] = true;
|
||||
if(entry->type != ::music::TYPE_STREAM && entry->type != ::music::TYPE_VIDEO)
|
||||
@@ -999,8 +1031,9 @@ command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
|
||||
notify["bot_id"] = bot->getClientDatabaseId();
|
||||
this->sendCommand(notify);
|
||||
}
|
||||
|
||||
return command_result{error::ok};
|
||||
#endif
|
||||
return command_result{error::not_implemented}; //FIXME
|
||||
}
|
||||
|
||||
command_result ConnectedClient::handleCommandMusicBotQueueAdd(Command& cmd) {
|
||||
|
||||
Reference in New Issue
Block a user