implement albumArtist

todo testing
This commit is contained in:
hecate cantus
2025-04-27 20:30:14 -07:00
parent 0332d2ebf8
commit 9b7a8a8c21
2 changed files with 20 additions and 0 deletions
+3
View File
@@ -38,6 +38,7 @@ class Mpris : public ALabel {
std::optional<std::string> artist;
std::optional<std::string> album;
std::optional<std::string> album_artist;
std::optional<std::string> title;
std::optional<std::string> length; // as HH:MM:SS
std::optional<std::string> position; // same format
@@ -76,6 +77,8 @@ class Mpris : public ALabel {
std::string player_;
std::vector<std::string> ignored_players_;
bool prefer_album_artist_;
PlayerctlPlayerManager* manager;
PlayerctlPlayer* player;
std::string lastStatus;
+17
View File
@@ -31,6 +31,7 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
dynamic_separator_(" - "),
truncate_hours_(true),
tooltip_len_limits_(false),
prefer_album_artist_(false),
// this character is used in Gnome so it's fine to use it here
ellipsis_("\u2026"),
player_("playerctld"),
@@ -68,6 +69,9 @@ Mpris::Mpris(const std::string& id, const Json::Value& config)
if (config_["enable-tooltip-len-limits"].isBool()) {
tooltip_len_limits_ = config["enable-tooltip-len-limits"].asBool();
}
if (config_["prefer-album-artist"].isBool()) {
prefer_album_artist_ = config["prefer-album-artist"].asBool();
}
}
if (config["artist-len"].isUInt()) {
@@ -244,6 +248,12 @@ void truncate(std::string& s, const std::string& ellipsis, size_t max_len) {
auto Mpris::getArtistStr(const PlayerInfo& info, bool truncated) -> std::string {
auto artist = info.artist.value_or(std::string());
if (prefer_album_artist_) {
auto album_artist = info.album_artist.value_or(std::string());
if (!album_artist.empty()) {
artist = album_artist;
}
}
if (truncated && artist_len_ >= 0) truncate(artist, ellipsis_, artist_len_);
return artist;
}
@@ -516,6 +526,7 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
.status_string = player_status,
.artist = std::nullopt,
.album = std::nullopt,
.album_artist = std::nullopt,
.title = std::nullopt,
.length = std::nullopt,
};
@@ -527,6 +538,12 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
}
if (error) goto errorexit;
if (auto* album_artist_ = playerctl_player_print_metadata_prop(player, "xesam:albumArtist", &error)) {
spdlog::debug("mpris[{}]: albumArtist = {}", info.name, album_artist_);
info.album_artist = album_artist_;
g_free(album_artist_);
}
if (auto* album_ = playerctl_player_get_album(player, &error)) {
spdlog::debug("mpris[{}]: album = {}", info.name, album_);
info.album = album_;