]> git.r.bdr.sh - rbdr/lyricli/commitdiff
Update genius integration 2.0.1
authorRuben Beltran del Rio <redacted>
Sun, 21 Jan 2024 16:54:50 +0000 (17:54 +0100)
committerRuben Beltran del Rio <redacted>
Sun, 21 Jan 2024 16:54:50 +0000 (17:54 +0100)
Sources/lyricli/lyricli.swift
Sources/lyricli/lyrics_engine.swift

index 13f8f185023993549e20f123bb446f007e441341..d5e5b91d5f08687eef022e2083931431477506cb 100644 (file)
@@ -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
index 620e5215c0a3834a271332106e51093e6e345100..e0752d77ebb20de9c0f7e2896ff5c57a55565b5e 100644 (file)
@@ -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) {