Merge pull request #5225 from JuustKiwi/fix-mpris-newlines
fix(mpris): sanitize metadata to prevent multiline UI expansion
This commit is contained in:
+28
-22
@@ -543,34 +543,40 @@ auto Mpris::getPlayerInfo() -> std::optional<PlayerInfo> {
|
|||||||
.length = std::nullopt,
|
.length = std::nullopt,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (auto* artist_ = playerctl_player_get_artist(last_active_player_, &error)) {
|
auto sanitize = [ ]( char* raw_str ) {
|
||||||
spdlog::debug("mpris[{}]: artist = {}", info.name, artist_);
|
std::string s( raw_str );
|
||||||
info.artist = artist_;
|
std::replace( s.begin(), s.end(), '\n', ' ' );
|
||||||
g_free(artist_);
|
std::replace( s.begin(), s.end(), '\r', ' ' );
|
||||||
}
|
return s;
|
||||||
if (error) goto errorexit;
|
};
|
||||||
|
|
||||||
if (auto* album_artist_ =
|
if(auto* artist_ = playerctl_player_get_artist( last_active_player_, &error )) {
|
||||||
playerctl_player_print_metadata_prop(last_active_player_, "xesam:albumArtist", &error)) {
|
spdlog::debug( "mpris[{}]: artist = {}", info.name, artist_ );
|
||||||
spdlog::debug("mpris[{}]: albumArtist = {}", info.name, album_artist_);
|
info.artist = sanitize( artist_ );
|
||||||
info.album_artist = album_artist_;
|
g_free( artist_ );
|
||||||
g_free(album_artist_);
|
|
||||||
}
|
}
|
||||||
if (error) goto errorexit;
|
if(error) goto errorexit;
|
||||||
|
|
||||||
if (auto* album_ = playerctl_player_get_album(last_active_player_, &error)) {
|
if(auto* album_artist_ = playerctl_player_print_metadata_prop( last_active_player_, "xesam:albumArtist", &error )) {
|
||||||
spdlog::debug("mpris[{}]: album = {}", info.name, album_);
|
spdlog::debug( "mpris[{}]: albumArtist = {}", info.name, album_artist_ );
|
||||||
info.album = album_;
|
info.album_artist = sanitize( album_artist_ );
|
||||||
g_free(album_);
|
g_free( album_artist_ );
|
||||||
}
|
}
|
||||||
if (error) goto errorexit;
|
if(error) goto errorexit;
|
||||||
|
|
||||||
if (auto* title_ = playerctl_player_get_title(last_active_player_, &error)) {
|
if(auto* album_ = playerctl_player_get_album( last_active_player_, &error )) {
|
||||||
spdlog::debug("mpris[{}]: title = {}", info.name, title_);
|
spdlog::debug( "mpris[{}]: album = {}", info.name, album_ );
|
||||||
info.title = title_;
|
info.album = sanitize( album_ );
|
||||||
g_free(title_);
|
g_free( album_ );
|
||||||
}
|
}
|
||||||
if (error) goto errorexit;
|
if(error) goto errorexit;
|
||||||
|
|
||||||
|
if(auto* title_ = playerctl_player_get_title( last_active_player_, &error )) {
|
||||||
|
spdlog::debug( "mpris[{}]: title = {}", info.name, title_ );
|
||||||
|
info.title = sanitize( title_ );
|
||||||
|
g_free( title_ );
|
||||||
|
}
|
||||||
|
if(error) goto errorexit;
|
||||||
|
|
||||||
if (auto* length_ =
|
if (auto* length_ =
|
||||||
playerctl_player_print_metadata_prop(last_active_player_, "mpris:length", &error)) {
|
playerctl_player_print_metadata_prop(last_active_player_, "mpris:length", &error)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user