Add playback handoff support

This commit is contained in:
lucast committed 2026-10-16 03:18:49 +02:00
1 parent c72596ef44
commit 77c00cc47e
5 files changed
+440 -1

No files matched your search

+62
View File
@@ -100,4 +100,66 @@ nonisolated public struct SearchResults: Decodable, Sendable {
}
nonisolated public struct TrackMembership: Decodable, Sendable { public let contains: Bool }
nonisolated public struct PlaybackHandoff: Decodable, Sendable {
public let currentTrackId: String
public let position: Double
public let queueTrackIds: [String]
public let remainingTrackIds: [String]
public let historyTrackIds: [String]
public let repeatEnabled: Bool
public let repeatOnce: Bool
public let wasPlaying: Bool
enum CodingKeys: String, CodingKey {
case currentTrackId, position, queueTrackIds, remainingTrackIds, historyTrackIds
case repeatEnabled = "repeat"
case repeatOnce, wasPlaying
}
}
nonisolated public struct PlaybackHandoffBody: Encodable, Sendable {
public let currentTrackId: String
public let position: Double
public let queueTrackIds: [String]
public let remainingTrackIds: [String]
public let historyTrackIds: [String]
public let repeatEnabled: Bool
public let repeatOnce: Bool
public let wasPlaying: Bool
enum CodingKeys: String, CodingKey {
case currentTrackId, position, queueTrackIds, remainingTrackIds, historyTrackIds
case repeatEnabled = "repeat"
case repeatOnce, wasPlaying
}
public init(
currentTrackId: String,
position: Double,
queueTrackIds: [String],
remainingTrackIds: [String],
historyTrackIds: [String],
repeatEnabled: Bool,
repeatOnce: Bool,
wasPlaying: Bool
) {
self.currentTrackId = currentTrackId
self.position = position
self.queueTrackIds = queueTrackIds
self.remainingTrackIds = remainingTrackIds
self.historyTrackIds = historyTrackIds
self.repeatEnabled = repeatEnabled
self.repeatOnce = repeatOnce
self.wasPlaying = wasPlaying
}
}
nonisolated public struct PlaybackHandoffSaveResponse: Decodable, Sendable {
public let saved: Bool
public let expiresAt: String
}
nonisolated public struct PlaybackHandoffDeleteResponse: Decodable, Sendable {
public let deleted: Bool
}
nonisolated public enum SearchType: String, Sendable { case track, album, artist, `default` }
+12
View File
@@ -109,6 +109,18 @@ public struct MusicAPI: Sendable {
let _: APIClient.EmptyResponse = try await client.request(
"DELETE", path: "user/tracks", query: ids.map { URLQueryItem(name: "ids", value: $0) })
}
public func playbackHandoff() async throws -> PlaybackHandoff? {
try await client.request("GET", path: "user/playback-handoff")
}
@discardableResult
public func savePlaybackHandoff(_ body: PlaybackHandoffBody) async throws
-> PlaybackHandoffSaveResponse
{
try await client.request("PUT", path: "user/playback-handoff", body: body)
}
public func deletePlaybackHandoff() async throws -> PlaybackHandoffDeleteResponse {
try await client.request("DELETE", path: "user/playback-handoff")
}
public func tracks(ids: [String]) async throws -> [Track] {
try await client.request(
"GET", path: "tracks", query: ids.map { URLQueryItem(name: "ids", value: $0) })