Apple Music fix
This commit is contained in:
@@ -267,6 +267,17 @@ enum MediaType: String, Codable {
|
||||
case unknown
|
||||
}
|
||||
|
||||
/// Maps a library item to its backing provider instance.
|
||||
struct MAProviderMapping: Codable, Hashable {
|
||||
let providerDomain: String
|
||||
let itemId: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case providerDomain = "provider_domain"
|
||||
case itemId = "item_id"
|
||||
}
|
||||
}
|
||||
|
||||
struct MAArtist: Codable, Identifiable, Hashable {
|
||||
let uri: String
|
||||
let name: String
|
||||
@@ -274,6 +285,8 @@ struct MAArtist: Codable, Identifiable, Hashable {
|
||||
let sortName: String?
|
||||
let musicbrainzId: String?
|
||||
let favorite: Bool
|
||||
/// All provider instances this artist is mapped to (from MA's provider_mappings field).
|
||||
let providerMappings: [MAProviderMapping]
|
||||
|
||||
var id: String { uri }
|
||||
var imageUrl: String? { metadata?.thumbImage?.path }
|
||||
@@ -283,6 +296,7 @@ struct MAArtist: Codable, Identifiable, Hashable {
|
||||
case uri, name, metadata, favorite
|
||||
case sortName = "sort_name"
|
||||
case musicbrainzId = "musicbrainz_id"
|
||||
case providerMappings = "provider_mappings"
|
||||
case image // Direct image field
|
||||
}
|
||||
|
||||
@@ -291,6 +305,7 @@ struct MAArtist: Codable, Identifiable, Hashable {
|
||||
self.metadata = imageUrl.map { MediaItemMetadata(images: [MediaItemImage(type: "thumb", path: $0, provider: imageProvider, remotelyAccessible: nil)], cacheChecksum: nil) }
|
||||
self.sortName = sortName; self.musicbrainzId = musicbrainzId
|
||||
self.favorite = favorite
|
||||
self.providerMappings = []
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
@@ -300,17 +315,18 @@ struct MAArtist: Codable, Identifiable, Hashable {
|
||||
favorite = (try? c.decode(Bool.self, forKey: .favorite)) ?? false
|
||||
sortName = try? c.decodeIfPresent(String.self, forKey: .sortName)
|
||||
musicbrainzId = try? c.decodeIfPresent(String.self, forKey: .musicbrainzId)
|
||||
|
||||
providerMappings = (try? c.decodeIfPresent([MAProviderMapping].self, forKey: .providerMappings)) ?? []
|
||||
|
||||
// Try to decode metadata first
|
||||
var decodedMetadata = try? c.decodeIfPresent(MediaItemMetadata.self, forKey: .metadata)
|
||||
|
||||
|
||||
// If metadata is missing, try to get image from direct "image" field
|
||||
if decodedMetadata == nil {
|
||||
if let imageObj = try? c.decodeIfPresent(MediaItemImage.self, forKey: .image) {
|
||||
decodedMetadata = MediaItemMetadata(images: [imageObj], cacheChecksum: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
metadata = decodedMetadata
|
||||
}
|
||||
|
||||
@@ -320,6 +336,7 @@ struct MAArtist: Codable, Identifiable, Hashable {
|
||||
try c.encode(name, forKey: .name)
|
||||
try c.encodeIfPresent(sortName, forKey: .sortName)
|
||||
try c.encodeIfPresent(musicbrainzId, forKey: .musicbrainzId)
|
||||
try c.encode(providerMappings, forKey: .providerMappings)
|
||||
try c.encodeIfPresent(metadata, forKey: .metadata)
|
||||
try c.encode(favorite, forKey: .favorite)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user