custom_modules: Fix mediaplayer.py handling untitled track

* Fix crash calling method on None
* Show artist if title is None
This commit is contained in:
Matthew Orlando
2026-05-31 10:01:25 -07:00
parent 05945748dc
commit 0af3ca1a4e
+6 -4
View File
@@ -105,24 +105,26 @@ class PlayerManager:
current_player = self.get_first_playing_player() current_player = self.get_first_playing_player()
if current_player is not None: if current_player is not None:
self.on_metadata_changed(current_player, current_player.props.metadata) self.on_metadata_changed(current_player, current_player.props.metadata)
else: else:
self.clear_output() self.clear_output()
def on_metadata_changed(self, player, metadata, _=None): def on_metadata_changed(self, player, metadata, _=None):
logger.debug(f"Metadata changed for player {player.props.player_name}") logger.debug(f"Metadata changed for player {player.props.player_name}")
player_name = player.props.player_name player_name = player.props.player_name
artist = player.get_artist() artist = player.get_artist()
artist = artist.replace("&", "&") artist = artist and artist.replace("&", "&")
title = player.get_title() title = player.get_title()
title = title.replace("&", "&") title = title and title.replace("&", "&")
track_info = "" track_info = ""
if player_name == "spotify" and "mpris:trackid" in metadata.keys() and ":ad:" in player.props.metadata["mpris:trackid"]: if player_name == "spotify" and "mpris:trackid" in metadata.keys() and ":ad:" in player.props.metadata["mpris:trackid"]:
track_info = "Advertisement" track_info = "Advertisement"
elif artist is not None and title is not None: elif artist is not None and title is not None:
track_info = f"{artist} - {title}" track_info = f"{artist} - {title}"
else: elif title is not None:
track_info = title track_info = title
elif artist is not None:
track_info = artist
if track_info: if track_info:
if player.props.status == "Playing": if player.props.status == "Playing":