From d8935809cdc1155be3c94d0d1598b85e95ade092 Mon Sep 17 00:00:00 2001 From: eevee Date: Mon, 10 Jun 2024 16:37:00 +0300 Subject: [PATCH] real lrclib crash fix --- .../Lyrics/Helpers/LyricsHelper.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sources/EeveeSpotify/Lyrics/Helpers/LyricsHelper.swift b/Sources/EeveeSpotify/Lyrics/Helpers/LyricsHelper.swift index 015556b..82a14bd 100644 --- a/Sources/EeveeSpotify/Lyrics/Helpers/LyricsHelper.swift +++ b/Sources/EeveeSpotify/Lyrics/Helpers/LyricsHelper.swift @@ -35,12 +35,14 @@ class LyricsHelper { .dropLast() if plain.timeSynced { - - lyricLines = lines.map { line in - let match = line.firstMatch( - "\\[(?\\d{2}):(?\\d{2}\\.?\\d*)\\] ?(?.*)" - )! + lyricLines = lines.compactMap { line in + + guard let match = line.firstMatch( + "\\[(?\\d*):(?\\d*\\.?\\d*)\\] ?(?.*)" + ) else { + return nil + } var captures: [String: String] = [:] @@ -52,6 +54,10 @@ class LyricsHelper { captures[name] = String(line[substringRange]) } } + + if captures.count != 3 { + return nil + } let minute = Int(captures["minute"]!)! let seconds = Float(captures["seconds"]!)!