From 0491341d6e883af4074d14acc87f8e0c40220014 Mon Sep 17 00:00:00 2001 From: Tristan Ferrua Date: Mon, 1 Feb 2021 23:11:32 +0000 Subject: [PATCH] Fixed an issue where if the song artist or title was not set, the player would error. When there is no title, the file name without the extension will be used. --- bin/miniplayer | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/miniplayer b/bin/miniplayer index 7f0c014..0e07eeb 100755 --- a/bin/miniplayer +++ b/bin/miniplayer @@ -238,8 +238,19 @@ class Player: except KeyError: self.album = "" - self.artist = song["artist"] - self.title = song["title"] + try: + self.artist = song["artist"] + except KeyError: + self.artist = "" + + try: + self.title = song["title"] + except KeyError: + # If no title, use base file name + aux = song["file"] + aux = os.path.basename(aux) + aux = os.path.splitext(aux)[0] + self.title = aux self.last_song = song @@ -313,10 +324,16 @@ class Player: A function to draw the info below the album art """ state, album, artist, title = self.fitText() + + if len(self.artist) == 0: + seperator = "" + else: + seperator = " - " + if state == 0: # Everything fits self.win.addstr(self.text_start, 0, f"{title}") - self.win.addstr(self.text_start + 1, 0, f"{artist} - {album}") + self.win.addstr(self.text_start + 1, 0, f"{artist}{seperator}{album}") elif state == 1: # Too wide