Rename MetaTags to MetaData

This commit is contained in:
badaix 2021-12-09 22:09:32 +01:00
parent 607f1db77f
commit 8e1f92acb1
13 changed files with 54 additions and 62 deletions

View file

@ -45,7 +45,6 @@
#include "common/str_compat.hpp"
#include "common/utils.hpp"
#include "common/version.hpp"
// #include "metadata.hpp"
#include <boost/asio/ip/host_name.hpp>
#include <boost/asio/signal_set.hpp>
@ -130,7 +129,6 @@ int main(int argc, char** argv)
int exitcode = EXIT_SUCCESS;
try
{
string meta_script;
ClientSettings settings;
string pcm_device(player::DEFAULT_DEVICE);
@ -175,8 +173,6 @@ int main(int argc, char** argv)
else
mixer_mode = op.add<Value<string>>("", "mixer", "software|script|none|?[:<options>]", "software");
auto metaStderr = op.add<Switch>("e", "mstderr", "send metadata to stderr");
// daemon settings
#ifdef HAS_DAEMON
int processPriority(-3);
@ -265,8 +261,6 @@ int main(int argc, char** argv)
exit(EXIT_SUCCESS);
}
// XXX: Only one metadata option must be set
settings.logging.filter = logfilterOption->value();
if (logfilterOption->is_set())
{
@ -430,9 +424,7 @@ int main(int argc, char** argv)
LOG(INFO, LOG_TAG) << "Version " << version::code << (!version::rev().empty() ? (", revision " + version::rev(8)) : ("")) << "\n";
// Setup metadata handling
// auto meta(metaStderr ? std::make_unique<MetaStderrAdapter>() : std::make_unique<MetadataAdapter>());
auto controller = make_shared<Controller>(io_context, settings); //, std::move(meta));
auto controller = make_shared<Controller>(io_context, settings);
controller->start();
int num_threads = 0;

View file

@ -28,7 +28,7 @@ set(SERVER_SOURCES
streamreader/meta_stream.cpp
streamreader/watchdog.cpp
streamreader/properties.cpp
streamreader/metatags.cpp
streamreader/metadata.cpp
streamreader/process_stream.cpp)
set(SERVER_LIBRARIES

View file

@ -44,7 +44,7 @@ endif
CXXFLAGS += $(ADD_CFLAGS) -std=c++17 -Wall -Wextra -Wpedantic -Wno-unused-function -DBOOST_ERROR_CODE_HEADER_ONLY -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DHAS_OPUS -DHAS_SOXR -DVERSION=\"$(VERSION)\" -I. -I.. -I../common
LDFLAGS += $(ADD_LDFLAGS) -lvorbis -lvorbisenc -logg -lFLAC -lopus -lsoxr
OBJ = snapserver.o server.o config.o control_server.o control_session_tcp.o control_session_http.o control_session_ws.o stream_server.o stream_session.o stream_session_tcp.o stream_session_ws.o streamreader/stream_uri.o streamreader/base64.o streamreader/stream_manager.o streamreader/pcm_stream.o streamreader/posix_stream.o streamreader/pipe_stream.o streamreader/file_stream.o streamreader/tcp_stream.o streamreader/process_stream.o streamreader/airplay_stream.o streamreader/meta_stream.o streamreader/librespot_stream.o streamreader/watchdog.o streamreader/control_error.o streamreader/stream_control.o streamreader/metatags.o streamreader/properties.o encoder/encoder_factory.o encoder/flac_encoder.o encoder/opus_encoder.o encoder/pcm_encoder.o encoder/null_encoder.o encoder/ogg_encoder.o ../common/sample_format.o ../common/resampler.o
OBJ = snapserver.o server.o config.o control_server.o control_session_tcp.o control_session_http.o control_session_ws.o stream_server.o stream_session.o stream_session_tcp.o stream_session_ws.o streamreader/stream_uri.o streamreader/base64.o streamreader/stream_manager.o streamreader/pcm_stream.o streamreader/posix_stream.o streamreader/pipe_stream.o streamreader/file_stream.o streamreader/tcp_stream.o streamreader/process_stream.o streamreader/airplay_stream.o streamreader/meta_stream.o streamreader/librespot_stream.o streamreader/watchdog.o streamreader/control_error.o streamreader/stream_control.o streamreader/metadata.o streamreader/properties.o encoder/encoder_factory.o encoder/flac_encoder.o encoder/opus_encoder.o encoder/pcm_encoder.o encoder/null_encoder.o encoder/ogg_encoder.o ../common/sample_format.o ../common/resampler.o
ifneq (,$(TARGET))
CXXFLAGS += -D$(TARGET)

View file

@ -160,7 +160,7 @@ void AirplayStream::push()
if (is_cover)
{
setMetaData(meta_.art_data, Metatags::ArtData{data, "jpg"});
setMetaData(meta_.art_data, Metadata::ArtData{data, "jpg"});
// LOG(INFO, LOG_TAG) << "Metadata type: " << entry_->type << " code: " << entry_->code << " data length: " << data.length() << "\n";
}
else
@ -179,7 +179,7 @@ void AirplayStream::push()
if (metadata_dirty_ && entry_->type == "ssnc" && (entry_->code == "mden" || entry_->code == "pcen"))
{
Properties properties;
properties.metatags = meta_;
properties.metadata = meta_;
setProperties(properties);
metadata_dirty_ = false;
}

View file

@ -68,7 +68,7 @@ protected:
std::unique_ptr<TageEntry> entry_;
std::string buf_;
/// set whenever metadata_ has changed
Metatags meta_;
Metadata meta_;
bool metadata_dirty_;
#endif

View file

@ -158,21 +158,21 @@ void LibrespotStream::onStderrMsg(const std::string& line)
// Patched version
LOG(INFO, LOG_TAG) << "metadata: <" << m[1] << ">\n";
json j = json::parse(m[1].str());
Metatags meta;
Metadata meta;
meta.artist = std::vector<std::string>{j["ARTIST"].get<std::string>()};
meta.title = j["TITLE"].get<std::string>();
Properties properties;
properties.metatags = meta;
properties.metadata = std::move(meta);
setProperties(properties);
}
else if (regex_search(line, m, re_track_loaded))
{
LOG(INFO, LOG_TAG) << "metadata: <" << m[1] << ">\n";
Metatags meta;
Metadata meta;
meta.title = string(m[1]);
meta.duration = cpt::stod(m[2]) / 1000.;
Properties properties;
properties.metatags = meta;
properties.metadata = std::move(meta);
setProperties(properties);
}
}

View file

@ -16,9 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "metatags.hpp"
#include "metadata.hpp"
static constexpr auto LOG_TAG = "Metatags";
static constexpr auto LOG_TAG = "Metadata";
namespace
@ -60,13 +60,13 @@ void addTag(json& j, const std::string& tag, const std::optional<T>& source)
} // namespace
Metatags::Metatags(const json& j)
Metadata::Metadata(const json& j)
{
fromJson(j);
}
json Metatags::toJson() const
json Metadata::toJson() const
{
json j(json::object());
addTag(j, "trackId", track_id);
@ -118,7 +118,7 @@ json Metatags::toJson() const
}
void Metatags::fromJson(const json& j)
void Metadata::fromJson(const json& j)
{
static std::set<std::string> supported_tags = {"trackId",
"duration",
@ -217,8 +217,8 @@ void Metatags::fromJson(const json& j)
}
bool Metatags::operator==(const Metatags& other) const
bool Metadata::operator==(const Metadata& other) const
{
// expensive, but not called ofetn and less typing
// expensive, but not called often and less typing
return (toJson() == other.toJson());
}

View file

@ -16,19 +16,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef METATAGS_HPP
#define METATAGS_HPP
#ifndef METADATA_HPP
#define METADATA_HPP
#include "common/aixlog.hpp"
#include "common/json.hpp"
#include <optional>
#include <set>
#include <string>
#include "common/aixlog.hpp"
#include "common/json.hpp"
using json = nlohmann::json;
class Metatags
class Metadata
{
public:
struct ArtData
@ -47,8 +47,8 @@ public:
}
};
Metatags() = default;
Metatags(const json& j);
Metadata() = default;
Metadata(const json& j);
/// https://www.musicpd.org/doc/html/protocol.html#tags
/// the duration of the song
@ -143,7 +143,7 @@ public:
json toJson() const;
void fromJson(const json& j);
bool operator==(const Metatags& other) const;
bool operator==(const Metadata& other) const;
};

View file

@ -16,11 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
#include <boost/asio/ip/host_name.hpp>
#include "pcm_stream.hpp"
#include "base64.h"
#include "common/aixlog.hpp"
@ -30,7 +26,12 @@
#include "common/utils/string_utils.hpp"
#include "control_error.hpp"
#include "encoder/encoder_factory.hpp"
#include "pcm_stream.hpp"
#include <boost/asio/ip/host_name.hpp>
#include <fcntl.h>
#include <memory>
#include <sys/stat.h>
using namespace std;
@ -444,20 +445,20 @@ void PcmStream::setProperties(const Properties& properties)
Properties props = properties;
// Missing metadata means the data didn't change, so
// enrich the new properites with old metadata
if (!props.metatags.has_value() && properties_.metatags.has_value())
props.metatags = properties_.metatags;
if (!props.metadata.has_value() && properties_.metadata.has_value())
props.metadata = properties_.metadata;
// If the cover image is availbale as raw data, cache it on the HTTP Server to make it also available via HTTP
if (props.metatags.has_value() && props.metatags->art_data.has_value() && !props.metatags->art_url.has_value())
if (props.metadata.has_value() && props.metadata->art_data.has_value() && !props.metadata->art_url.has_value())
{
auto data = base64_decode(props.metatags->art_data.value().data);
auto md5 = server_settings_.http.image_cache.setImage(getName(), std::move(data), props.metatags->art_data.value().extension);
auto data = base64_decode(props.metadata->art_data.value().data);
auto md5 = server_settings_.http.image_cache.setImage(getName(), std::move(data), props.metadata->art_data.value().extension);
std::stringstream url;
url << "http://" << server_settings_.http.host << ":" << server_settings_.http.port << "/__image_cache?name=" << md5;
props.metatags->art_url = url.str();
props.metadata->art_url = url.str();
}
else if (!props.metatags->art_data.has_value())
else if (!props.metadata->art_data.has_value())
{
server_settings_.http.image_cache.clear(getName());
}

View file

@ -101,8 +101,8 @@ json Properties::toJson() const
addTag(j, "canPause", can_pause);
addTag(j, "canSeek", can_seek);
addTag(j, "canControl", can_control);
if (metatags.has_value())
addTag(j, "metadata", metatags->toJson());
if (metadata.has_value())
addTag(j, "metadata", metadata->toJson());
return j;
}
@ -147,12 +147,12 @@ void Properties::fromJson(const json& j)
if (j.contains("metadata"))
{
Metatags m;
Metadata m;
m.fromJson(j["metadata"]);
metatags = m;
metadata = m;
}
else
metatags = std::nullopt;
metadata = std::nullopt;
}
bool Properties::operator==(const Properties& other) const

View file

@ -19,14 +19,13 @@
#ifndef PROPERTIES_HPP
#define PROPERTIES_HPP
#include <set>
#include <string>
#include <optional>
#include "common/aixlog.hpp"
#include "common/json.hpp"
#include "metatags.hpp"
#include "metadata.hpp"
#include <optional>
#include <set>
#include <string>
using json = nlohmann::json;
@ -152,7 +151,7 @@ public:
Properties(const json& j);
/// Meta data
std::optional<Metatags> metatags;
std::optional<Metadata> metadata;
/// https://www.musicpd.org/doc/html/protocol.html#tags
/// The current playback status
std::optional<PlaybackStatus> playback_status;

View file

@ -13,7 +13,7 @@ set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/control_error.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/properties.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/metatags.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/metadata.cpp
${CMAKE_SOURCE_DIR}/server/streamreader/stream_uri.cpp)
add_executable(snapcast_test ${TEST_SOURCES})

View file

@ -109,7 +109,7 @@ TEST_CASE("Uri")
}
TEST_CASE("Metatags")
TEST_CASE("Metadata")
{
auto in_json = json::parse(R"(
{
@ -146,7 +146,7 @@ TEST_CASE("Metatags")
)");
// std::cout << in_json.dump(4) << "\n";
Metatags meta(in_json);
Metadata meta(in_json);
REQUIRE(meta.album.has_value());
REQUIRE(meta.album.value() == "Memories...Do Not Open");
REQUIRE(meta.genre.has_value());