38 lines
917 B
Swift
38 lines
917 B
Swift
import Foundation
|
|
|
|
public struct Recording: MusicBrainzSearchable, Identifiable, Hashable, Equatable {
|
|
public static let entityType: MusicBrainzEntity = .recording
|
|
|
|
public let id: String
|
|
public let title: String
|
|
public let length: Int?
|
|
public let video: Bool?
|
|
public let disambiguation: String?
|
|
public let firstReleaseDate: String?
|
|
public let relations: [Relation]?
|
|
public let score: Int?
|
|
|
|
enum CodingKeys: String, CodingKey, Hashable, Equatable {
|
|
case id
|
|
case title
|
|
case length
|
|
case video
|
|
case disambiguation
|
|
case firstReleaseDate = "first-release-date"
|
|
case relations
|
|
case score
|
|
}
|
|
|
|
public var youtubeURL: URL? {
|
|
guard let relations else { return nil }
|
|
for rel in relations {
|
|
if let resource = rel.url?.resource {
|
|
if rel.type == "youtube" || resource.contains("youtube.com") || resource.contains("youtu.be") {
|
|
return URL(string: resource)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|