Merge pull request #255 from 7hourspg/fix/lyrics-empty-array

Fix: Prevent '[]' from displaying when no lyrics are available
This commit is contained in:
Hariharan Mudaliar 2026-01-22 16:22:49 +05:30 • committed by GitHub
commit 2d7664d105
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -708,14 +708,27 @@ class MusicManager: ObservableObject {
} }
} else { } else {
// Fallback: try to decode as UTF8 and handle as LRC or plain text // Fallback: try to decode as UTF8 and handle as LRC or plain text
if let lrcString = String(data: data, encoding: .utf8), !lrcString.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { if let lrcString = String(data: data, encoding: .utf8) {
// If it contains a syncedLyrics key in an object, try that let trimmed = lrcString.trimmingCharacters(in: .whitespacesAndNewlines)
if let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let synced = json["syncedLyrics"] as? String { if trimmed.isEmpty {
return parseLRC(synced) return []
} }
// If it contains a syncedLyrics key in an object, try that
if let json = try? JSONSerialization.jsonObject(with: data, options: []) {
if let dict = json as? [String: Any],
let synced = dict["syncedLyrics"] as? String
{
return parseLRC(synced)
}
if let array = json as? [Any], array.isEmpty {
return []
}
}
// Otherwise treat as plain lyrics blob // Otherwise treat as plain lyrics blob
return [LyricLine(timestamp: 0, text: lrcString.trimmingCharacters(in: .whitespacesAndNewlines))] return [LyricLine(timestamp: 0, text: trimmed)]
} }
return [] return []
} }