mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Merge pull request #255 from 7hourspg/fix/lyrics-empty-array
Fix: Prevent '[]' from displaying when no lyrics are available
This commit is contained in:
commit
2d7664d105
1 changed files with 18 additions and 5 deletions
|
|
@ -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 []
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue