diff --git a/Sources/NavidromeKit/APIClient.swift b/Sources/NavidromeKit/APIClient.swift index d6cbf6b..3c97081 100644 --- a/Sources/NavidromeKit/APIClient.swift +++ b/Sources/NavidromeKit/APIClient.swift @@ -15,11 +15,23 @@ 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] + 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 }() 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