Updated some small stuff
This commit is contained in:
parent
a36f0dbf02
commit
f830a8023d
@ -2342,7 +2342,7 @@ command_result ConnectedClient::handleCommandDummy_IpChange(ts::Command &cmd) {
|
||||
if(geoloc::provider) {
|
||||
auto loc = this->isAddressV4() ? geoloc::provider->resolveInfoV4(this->getPeerIp(), false) : geoloc::provider->resolveInfoV6(this->getPeerIp(), false);
|
||||
if(loc) {
|
||||
logError(this->getServerId(), "[{}] Received new ip location. IP {} traced to {} ({}).", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), loc->name, loc->identifier);
|
||||
logMessage(this->getServerId(), "[{}] Received new ip location. IP {} traced to {} ({}).", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), loc->name, loc->identifier);
|
||||
this->properties()[property::CLIENT_COUNTRY] = loc->identifier;
|
||||
server->notifyClientPropertyUpdates(_this.lock(), deque<property::ClientProperties>{property::CLIENT_COUNTRY});
|
||||
new_country = loc->identifier;
|
||||
|
@ -801,6 +801,44 @@ command_result ConnectedClient::handleCommandPlaylistClientDelPerm(ts::Command &
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
constexpr auto max_song_meta_info = 1024 * 512;
|
||||
|
||||
inline size_t estimated_song_info_size(const std::shared_ptr<ts::music::PlaylistEntryInfo>& song, bool extract_metadata) {
|
||||
return 128 + std::min(song->metadata.json_string.length(), (size_t) max_song_meta_info) + extract_metadata * 256;
|
||||
}
|
||||
|
||||
inline void fill_song_info(ts::command_builder_bulk bulk, const std::shared_ptr<ts::music::PlaylistEntryInfo>& song, bool extract_metadata) {
|
||||
bulk.reserve(estimated_song_info_size(song, extract_metadata));
|
||||
|
||||
bulk.put("song_id", song->song_id);
|
||||
bulk.put("song_invoker", song->invoker);
|
||||
bulk.put("song_previous_song_id", song->previous_song_id);
|
||||
bulk.put("song_url", song->original_url);
|
||||
bulk.put("song_url_loader", song->url_loader);
|
||||
bulk.put("song_loaded", song->metadata.is_loaded());
|
||||
if(song->metadata.json_string.length() > 1024 * 1024 * 512) {
|
||||
logWarning(LOG_GENERAL, "Dropping song metadata because its way to big. ({}bytes)", song->metadata.json_string.size());
|
||||
} else {
|
||||
bulk.put("song_metadata", song->metadata.json_string);
|
||||
}
|
||||
|
||||
if(extract_metadata) {
|
||||
bulk.reserve(256, true);
|
||||
auto metadata = song->metadata.loaded_data;
|
||||
if(extract_metadata && song->metadata.is_loaded() && metadata) {
|
||||
bulk.put("song_metadata_title", metadata->title);
|
||||
bulk.put("song_metadata_description", metadata->description);
|
||||
bulk.put("song_metadata_url", metadata->url);
|
||||
bulk.put("song_metadata_length", metadata->length.count());
|
||||
if(auto thumbnail = static_pointer_cast<::music::ThumbnailUrl>(metadata->thumbnail); thumbnail && thumbnail->type() == ::music::THUMBNAIL_URL) {
|
||||
bulk.put("song_metadata_thumbnail_url", thumbnail->url());
|
||||
} else {
|
||||
bulk.put("song_metadata_thumbnail_url", "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
command_result ConnectedClient::handleCommandPlaylistSongList(ts::Command &cmd) {
|
||||
CMD_REF_SERVER(ref_server);
|
||||
CMD_RESET_IDLE;
|
||||
@ -816,39 +854,29 @@ command_result ConnectedClient::handleCommandPlaylistSongList(ts::Command &cmd)
|
||||
if(songs.empty())
|
||||
return command_result{error::database_empty_result};
|
||||
|
||||
Command notify(this->notify_response_command("notifyplaylistsonglist"));
|
||||
notify["playlist_id"] = playlist->playlist_id();
|
||||
|
||||
ts::command_builder result{this->notify_response_command("notifyplaylistsonglist")};
|
||||
result.put(0, "version", 2); /* to signalize that we're sending the response bulked */
|
||||
auto extract_metadata = cmd.hasParm("extract-metadata");
|
||||
|
||||
size_t index = 0;
|
||||
size_t index{0};
|
||||
for(const auto& song : songs) {
|
||||
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->original_url;
|
||||
notify[index]["song_url_loader"] = song->url_loader;
|
||||
notify[index]["song_loaded"] = song->metadata.is_loaded();
|
||||
notify[index]["song_metadata"] = song->metadata.json_string;
|
||||
if(index == 0) {
|
||||
result.put(0, "playlist_id", playlist->playlist_id());
|
||||
}
|
||||
fill_song_info(result.bulk(index), song, extract_metadata);
|
||||
|
||||
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();
|
||||
if(this->getExternalType() == ClientType::CLIENT_TEAMSPEAK && result.current_size() + estimated_song_info_size(song, extract_metadata) > 128 * 1024) {
|
||||
this->sendCommand(result);
|
||||
result.reset();
|
||||
index = 0;
|
||||
} else {
|
||||
notify[index]["song_metadata_thumbnail_url"] = "none";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
this->sendCommand(notify);
|
||||
}
|
||||
if(index > 0)
|
||||
this->sendCommand(result);
|
||||
if(this->getExternalType() == ClientType::CLIENT_TEAMSPEAK)
|
||||
this->sendCommand(ts::command_builder{"notifyplaylistsonglistfinished"});
|
||||
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user