Everything works well and good structure.
This commit is contained in:
@@ -7,22 +7,37 @@ let client = MusicBrainzClient(
|
||||
do {
|
||||
print("--- Artist Search: 'Michael Jackson' ---")
|
||||
let artistSearch = try await client.search(
|
||||
.artist(name: "Michael Jackson", gender: .male, country: .us, type: .person), limit: 5)
|
||||
print("Total results: \(artistSearch.count)")
|
||||
for artist in artistSearch.entities {
|
||||
print("- \(artist.name) (\(artist.id))")
|
||||
if let disambiguation = artist.disambiguation {
|
||||
print(" (\(disambiguation))")
|
||||
.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: 5)
|
||||
print("Total results: \(releaseSearch.count)")
|
||||
for release in releaseSearch.entities {
|
||||
print("- \(release.title) (\(release.id))")
|
||||
if let date = release.date {
|
||||
print(" Date: \(date)")
|
||||
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)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user