From: Ruben Beltran del Rio Date: Sun, 21 Jan 2024 16:54:50 +0000 (+0100) Subject: Update genius integration X-Git-Tag: 2.0.1 X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/commitdiff_plain/4adf8d5182b7ad3720e3160e0f4530547625dbce Update genius integration --- diff --git a/Sources/lyricli/lyricli.swift b/Sources/lyricli/lyricli.swift index 13f8f18..d5e5b91 100644 --- a/Sources/lyricli/lyricli.swift +++ b/Sources/lyricli/lyricli.swift @@ -2,7 +2,7 @@ class Lyricli { // Version of the application - static var version = "2.0.0" + static var version = "2.0.1" // Flag that controls whether we should show the track artist and name before // the lyrics diff --git a/Sources/lyricli/lyrics_engine.swift b/Sources/lyricli/lyrics_engine.swift index 620e521..e0752d7 100644 --- a/Sources/lyricli/lyrics_engine.swift +++ b/Sources/lyricli/lyrics_engine.swift @@ -73,9 +73,11 @@ class LyricsEngine { if let data = data { if let jsonResponse = try? JSONSerialization.jsonObject(with: data) { if let jsonResponse = jsonResponse as? [String: Any] { - if let response = jsonResponse["response"] as? [String:Any] { - if let hits = response["hits"] as? [Any] { - if let firstHit = hits[0] as? [String: Any] { + if let response = jsonResponse["response"] as? [String: Any] { + if let hits = response["hits"] as? [[String: Any]] { + let filteredHits = hits.filter { $0["type"] as? String == "song" } + if filteredHits.count > 0 { + let firstHit = hits[0] if let firstHitData = firstHit["result"] as? [String: Any] { if let lyricsUrlString = firstHitData["url"] as? String { if let lyricsUrl = URL(string: lyricsUrlString) {