47 lines
1.4 KiB
Swift
47 lines
1.4 KiB
Swift
import Foundation
|
|
import MusicBrainz
|
|
|
|
let client = MusicBrainzClient(
|
|
clientAgent: .init(appName: "MusicD", version: "0.0.1", email: "test@gmail.com"))
|
|
|
|
do {
|
|
print("--- Artist Search: 'Michael Jackson' ---")
|
|
let artistSearch = try await client.search(
|
|
.artist(name: "Michael Jackson", gender: .male, country: .us, type: .person), limit: 1)
|
|
|
|
if let artist = artistSearch.entities.first {
|
|
print("- Found Artist: \(artist.name) (\(artist.id))")
|
|
|
|
// Fetch artist with URL relationships to find an image
|
|
print(" Fetching artist details (with url-rels)...")
|
|
let detailedArtist = try await client.fetch(.artist, id: artist.id, includes: ["url-rels"])
|
|
if let imageURL = detailedArtist.imageURL {
|
|
print(" Artist Image URL: \(imageURL)")
|
|
} else {
|
|
print(" No image found for artist.")
|
|
}
|
|
}
|
|
|
|
print("\n--- Release Search: 'Thriller' ---")
|
|
let releaseSearch = try await client.search(.release(title: "Thriller"), limit: 1)
|
|
|
|
if let release = releaseSearch.entities.first {
|
|
print("- Found Release: \(release.title) (\(release.id))")
|
|
|
|
// Fetch cover art from Cover Art Archive
|
|
print(" Fetching cover art...")
|
|
do {
|
|
let coverArt = try await client.fetchCoverArt(releaseId: release.id)
|
|
if let front = coverArt.frontImage {
|
|
print(" Front Cover Image: \(front.image)")
|
|
print(" Thumbnails: \(front.thumbnails)")
|
|
}
|
|
} catch {
|
|
print(" Could not fetch cover art: \(error)")
|
|
}
|
|
}
|
|
|
|
} catch {
|
|
print("Error: \(error)")
|
|
}
|