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.

This commit is contained in:
Tristan Ferrua
2021-02-01 23:11:32 +00:00
parent 1944ccd764
commit 0491341d6e

View File

@ -238,8 +238,19 @@ class Player:
except KeyError:
self.album = ""
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