Fix: Prevent '[]' from displaying when no lyrics are available

This commit is contained in:
Rajiv 2026-01-22 04:01:20 +05:30
commit eaa26f8d36

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 []
} }