From 807459d64834a1604911ba736f977e6fa9f6c7fb Mon Sep 17 00:00:00 2001 From: paige Date: Tue, 18 Aug 2026 02:28:12 +0200 Subject: [PATCH 1/2] the --- Sources/NavidromeKit/APIClient.swift | 11 +++++++---- Sources/NavidromeKit/Models/Song.swift | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/NavidromeKit/APIClient.swift b/Sources/NavidromeKit/APIClient.swift index d6cbf6b..b69ee05 100644 --- a/Sources/NavidromeKit/APIClient.swift +++ b/Sources/NavidromeKit/APIClient.swift @@ -15,11 +15,14 @@ public final class APIClient: Sendable { internal let urlSession: URLSession internal let decoder: JSONDecoder = { -#warning("this date encoding loves to fail for some reason") - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" let decoder = JSONDecoder() - decoder.dateDecodingStrategy = .formatted(dateFormatter) + decoder.dateDecodingStrategy = .custom({ decoder in + let container = try decoder.singleValueContainer() + let dateString = try container.decode(String.self) + let formatter = ISO8601DateFormatter() + formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] + return formatter.date(from: dateString)! + }) return decoder }() diff --git a/Sources/NavidromeKit/Models/Song.swift b/Sources/NavidromeKit/Models/Song.swift index 358d06c..ed0f063 100644 --- a/Sources/NavidromeKit/Models/Song.swift +++ b/Sources/NavidromeKit/Models/Song.swift @@ -41,7 +41,7 @@ public struct Song: Codable, Identifiable, Hashable, Sendable { public let duration: Double public let bitRate: Int public let sampleRate: Int - public let bitDepth: Int + public let bitDepth: Int? public let channels: Int public let codec: String public let genre: String From f7391a67cf628555edf07481177fb6e2ce2af85b Mon Sep 17 00:00:00 2001 From: Lakhan Lothiyi Date: Tue, 18 Aug 2026 01:43:03 +0100 Subject: [PATCH 2/2] Update APIClient.swift --- Sources/NavidromeKit/APIClient.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sources/NavidromeKit/APIClient.swift b/Sources/NavidromeKit/APIClient.swift index b69ee05..3c97081 100644 --- a/Sources/NavidromeKit/APIClient.swift +++ b/Sources/NavidromeKit/APIClient.swift @@ -21,7 +21,16 @@ public final class APIClient: Sendable { let dateString = try container.decode(String.self) let formatter = ISO8601DateFormatter() formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds] - return formatter.date(from: dateString)! + if let date = formatter.date(from: dateString) { + return date + } else { + formatter.formatOptions = [.withInternetDateTime] + if let date = formatter.date(from: dateString) { + return date + } else { + throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date format (\(dateString))") + } + } }) return decoder }()