feat: added smart title param
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <fmt/chrono.h>
|
||||
#include <glibmm/ustring.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string>
|
||||
#include <regex>
|
||||
|
||||
#include <system_error>
|
||||
#include <util/sanitize_str.hpp>
|
||||
@@ -118,7 +120,7 @@ void waybar::modules::MPD::setLabel() {
|
||||
|
||||
auto format = format_;
|
||||
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;
|
||||
std::chrono::seconds elapsedTime, totalTime;
|
||||
|
||||
@@ -152,6 +154,13 @@ void waybar::modules::MPD::setLabel() {
|
||||
date = sanitize_string(getTag(MPD_TAG_DATE));
|
||||
filename = sanitize_string(getFilename());
|
||||
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;
|
||||
volume = mpd_status_get_volume(status_.get());
|
||||
if (volume < 0) {
|
||||
@@ -175,6 +184,7 @@ void waybar::modules::MPD::setLabel() {
|
||||
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_["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 {
|
||||
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("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon),
|
||||
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()) {
|
||||
label_.hide();
|
||||
} else {
|
||||
|
||||
0
subprojects/.wraplock
Normal file
0
subprojects/.wraplock
Normal file
Reference in New Issue
Block a user