41 lines
902 B
Swift
41 lines
902 B
Swift
import Foundation
|
|
|
|
public struct Artist: MusicBrainzSearchable {
|
|
public static let entityType: MusicBrainzEntity = .artist
|
|
|
|
public let id: String
|
|
public let name: String
|
|
public let sortName: String?
|
|
public let type: String?
|
|
public let country: String?
|
|
public let disambiguation: String?
|
|
public let lifeSpan: LifeSpan?
|
|
public let relations: [Relation]?
|
|
public let score: Int?
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case name
|
|
case sortName = "sort-name"
|
|
case type
|
|
case country
|
|
case disambiguation
|
|
case lifeSpan = "life-span"
|
|
case relations
|
|
case score
|
|
}
|
|
|
|
public var imageURL: URL? {
|
|
guard let relations else { return nil }
|
|
// Look for 'image' or 'wikimedia commons'
|
|
for rel in relations {
|
|
if rel.type == "image" || rel.type == "wikimedia commons" {
|
|
if let resource = rel.url?.resource {
|
|
return URL(string: resource)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|