Skip to content

Commit cf30840

Browse files
committed
Handle corrupted lyrics without crashing
1 parent 96d6f15 commit cf30840

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/mediaplayer

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,22 @@ def get_new_lyrics(artist, title):
322322
return
323323
for i, line in enumerate(lyr.lt):
324324
m = re.match(r"\[(.*)\](.*)", line)
325+
if not m:
326+
continue
327+
# convert time from min:sec into sec
325328
timing = m.group(1)
326329
timing2 = timing.split(":")
327-
assert len(timing2) == 2
330+
if len(timing2) != 2:
331+
logger.debug(f"ERROR: timing2={timing2} is not of length 2")
332+
continue
333+
if not timing2[0].isnumeric():
334+
logger.debug(f"ERROR: timing2[0]={timing2[0]} is not numeric")
335+
continue
336+
if not timing2[1].isnumeric():
337+
logger.debug(f"ERROR: timing2[1]={timing2[1]} is not numeric")
338+
continue
328339
secs = int(timing2[0]) * 60.0 + float(timing2[1])
340+
# get lyrics text
329341
text = m.group(2).strip()
330342
if text == "":
331343
text = "[INTERMISSION]"

0 commit comments

Comments
 (0)