Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Sources/NavidromeKit/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()

Expand Down
2 changes: 1 addition & 1 deletion Sources/NavidromeKit/Models/Song.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down