feat: added smart title param

This commit is contained in:
2025-10-08 13:52:24 +03:00
parent 41de8964f1
commit d59e7c98d5
2 changed files with 13 additions and 2 deletions

View File

@@ -3,6 +3,8 @@
#include <fmt/chrono.h> #include <fmt/chrono.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <string>
#include <regex>
#include <system_error> #include <system_error>
#include <util/sanitize_str.hpp> #include <util/sanitize_str.hpp>
@@ -118,7 +120,7 @@ void waybar::modules::MPD::setLabel() {
auto format = format_; auto format = format_;
Glib::ustring artist, album_artist, album, title; Glib::ustring artist, album_artist, album, title;
std::string date, filename, uri; std::string date, filename, uri, titleSmart;
int song_pos = 0, queue_length = 0, volume = 0; int song_pos = 0, queue_length = 0, volume = 0;
std::chrono::seconds elapsedTime, totalTime; std::chrono::seconds elapsedTime, totalTime;
@@ -152,6 +154,13 @@ void waybar::modules::MPD::setLabel() {
date = sanitize_string(getTag(MPD_TAG_DATE)); date = sanitize_string(getTag(MPD_TAG_DATE));
filename = sanitize_string(getFilename()); filename = sanitize_string(getFilename());
uri = mpd_song_get_uri(song_.get()); uri = mpd_song_get_uri(song_.get());
if (title == "n/a" || artist == "n/a") {
titleSmart = std::regex_replace(filename, std::regex(R"((\s*$$.*?$$)|(\.(mp3|m4a|opus|ogx))$)"), "");
} else {
titleSmart = static_cast<std::string>(artist) + " - " + static_cast<std::string>(title);
}
song_pos = mpd_status_get_song_pos(status_.get()) + 1; song_pos = mpd_status_get_song_pos(status_.get()) + 1;
volume = mpd_status_get_volume(status_.get()); volume = mpd_status_get_volume(status_.get());
if (volume < 0) { if (volume < 0) {
@@ -175,6 +184,7 @@ void waybar::modules::MPD::setLabel() {
album_artist = album_artist.substr(0, config_["album-artist-len"].asInt()); album_artist = album_artist.substr(0, config_["album-artist-len"].asInt());
if (config_["album-len"].isInt()) album = album.substr(0, config_["album-len"].asInt()); if (config_["album-len"].isInt()) album = album.substr(0, config_["album-len"].asInt());
if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt()); if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt());
if (config_["title-len"].isInt()) titleSmart = titleSmart.substr(0, config_["title-len"].asInt());
try { try {
auto text = fmt::format( auto text = fmt::format(
@@ -185,7 +195,8 @@ void waybar::modules::MPD::setLabel() {
fmt::arg("songPosition", song_pos), fmt::arg("queueLength", queue_length), fmt::arg("songPosition", song_pos), fmt::arg("queueLength", queue_length),
fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon), fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon),
fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon), fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon),
fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri)); fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri),
fmt::arg("titleSmart", titleSmart));
if (text.empty()) { if (text.empty()) {
label_.hide(); label_.hide();
} else { } else {

0
subprojects/.wraplock Normal file
View File