Everything works well and good structure.
This commit is contained in:
40
Sources/MusicBrainz/Models/Artist.swift
Normal file
40
Sources/MusicBrainz/Models/Artist.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user