Remove MetadataAdapter

This commit is contained in:
badaix 2025-02-15 22:27:16 +01:00 committed by Johannes Pohl
parent afa8c118f6
commit f8e4e60f2f
7 changed files with 38 additions and 123 deletions

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -29,27 +29,35 @@
using json = nlohmann::json;
/// Meta data of a single track
class Metadata
{
public:
/// Cover art
struct ArtData
{
/// base64 encoded art data
std::string data;
/// type of the data (e.g. jpg)
std::string extension;
/// compare for equality
bool operator==(const ArtData& other) const
{
return ((other.data == data) && (other.extension == extension));
}
/// compare for un-equality
bool operator!=(const ArtData& other) const
{
return !(other == *this);
}
};
/// c'tor
Metadata() = default;
Metadata(const json& j);
/// c'tor taking json serialized meta data
explicit Metadata(const json& j);
/// https://www.musicpd.org/doc/html/protocol.html#tags
/// the duration of the song
@ -142,7 +150,10 @@ public:
/// Spotify track id
std::optional<std::string> spotify_track_id;
/// serialize to json
json toJson() const;
/// deserialize from json
void fromJson(const json& j);
/// compare for equality
bool operator==(const Metadata& other) const;
};

View file

@ -29,6 +29,7 @@
#include "control_error.hpp"
#include "encoder/encoder_factory.hpp"
#include "image_cache.hpp"
#include "streamreader/properties.hpp"
// 3rd party headers
#include <boost/asio/ip/host_name.hpp>
@ -152,7 +153,7 @@ void PcmStream::pollProperties()
{
LOG(INFO, LOG_TAG) << "Response for Plugin.Stream.Player.GetProperties: " << response.to_json() << "\n";
if (response.error().code() == 0)
setProperties(response.result());
setProperties(Properties(response.result()));
});
pollProperties();
}
@ -168,7 +169,7 @@ void PcmStream::onControlNotification(const jsonrpcpp::Notification& notificatio
if (notification.method() == "Plugin.Stream.Player.Properties")
{
LOG(DEBUG, LOG_TAG) << "Received properties notification\n";
setProperties(notification.params().to_json());
setProperties(Properties(notification.params().to_json()));
}
else if (notification.method() == "Plugin.Stream.Ready")
{
@ -177,7 +178,7 @@ void PcmStream::onControlNotification(const jsonrpcpp::Notification& notificatio
{
LOG(INFO, LOG_TAG) << "Response for Plugin.Stream.Player.GetProperties: " << response.to_json() << "\n";
if (response.error().code() == 0)
setProperties(response.result());
setProperties(Properties(response.result()));
});
// TODO: Add capabilities or settings?

View file

@ -1,6 +1,6 @@
/***
This file is part of snapcast
Copyright (C) 2014-2024 Johannes Pohl
Copyright (C) 2014-2025 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -143,12 +143,14 @@ static std::istream& operator>>(std::istream& is, LoopStatus& loop_status)
return is;
}
/// Properties of the stream (volume, shuffle, mute, position, can_play, can_pause, ...)
class Properties
{
public:
/// c'tor
Properties() = default;
Properties(const json& j);
/// c'tor taking json serialized properties
explicit Properties(const json& j);
/// Meta data
std::optional<Metadata> metadata;
@ -185,7 +187,10 @@ public:
/// Whether the media player may be controlled over this interface
bool can_control = false;
/// serialize to json
json toJson() const;
/// deserialize from json
void fromJson(const json& j);
/// compare for equality
bool operator==(const Properties& other) const;
};