@JoeKun this is amazing! I'm so grateful for all of these improvements. Having the ability to return MusicKit Album objects from an MPMediaItemPropertyAlbumPersistentID makes it so much simpler for me to adopt all this awesome new stuff. I have noticed a couple of issues, for which I've filed feedbacks:
FB10581774 - Non-alphanumeric/whitespace characters don't work in equalTo matching
When testing the new LibraryAlbumFilter properties, I think I've found an issue where matching on \.artistName or \.title fails to return results when using the equalTo match type and matching on a string containing non-alphanumeric or whitespace characters. The below code fails to return any results when using equalTo, but using the contains version of the filter function correctly returns all the R.E.M. albums in my library. I have also reproduced this same issue when matching on \.title when the album name contains parentheses.
var nameRequest = MusicLibraryRequest<Album>.init()
nameRequest.filter(matching: \.artistName, equalTo: "R.E.M.")
do {
let nameResponse = try await nameRequest.response()
print(nameResponse.items)
} catch {
print("name request error: \(error)")
}
FB10581868 - Some MPMediaItemPropertyAlbumPersistentID matches fail
Using the below code successfully returns MusicKit albums in most cases, but sometimes it fails to. Here's my code for the match starting with an MPMediaItem called rep.
let idString = String(rep.albumPersistentID)
var request = MusicLibraryRequest<Album>()
request.filter(matching: \.id, equalTo: MusicItemID(idString))
do {
let response = try await request.response()
print(response.items)
} catch {
print("id request error: \(error)")
}
In cases where matching on this ID doesn’t work, I then do a backup search by .artistName and .title, which returns the album and shows a different ID.
The ones that fail show an ID with a huge negative number. It seems like the original MPMediaItemPropertyAlbumPersistentID is unsigned, but the ID MusicKit is using is? Something like that?
Here's what prints when I print the ID:
Looking for Defeater - Abandoned (Deluxe Edition), id: 9601744824086363441
Here's what prints when I show the results of the .artistName and .title match (using contains, because as described above, using equalTo will fail because of the parens in the album title :D)
MusicItemCollection<Album>(
items: [
Album(id: "-8844999249623188175", title: "Abandoned (Deluxe Edition)", artistName: "Defeater")
]
)
Should I be converting the MPMediaItemPropertyAlbumPersistentID to a string like this, or is there another to instantiate it as a MusicItemID?
FB10582021 Expose catalogID if present for Library albums
Being able to use an album’s MPMediaItemPropertyAlbumPersistentID to fetch the library version is great, but unless I’m missing something, you then lose access to the album's Apple Music catalog ID. It would be great to be able to still access the catalog ID as well as the local ID.
Running dump() on the fetched object, it looks like the catalog ID is embedded in some of the properties, such as the Play Parameters.
▿ playParameters: Optional(MusicKit.PlayParameters(id: -8844999249623188175, kind: "album", isLibrary: Optional(true), catalogID: Optional(MusicKit.MusicCatalogID(value: 1485062012, kind: MusicKit.MusicCatalogID.Kind.adamID)), deviceLocalID: Optional(MusicKit.MusicDeviceLocalID(value: -8844999249623188175, databaseID: 9C47D30D-37C1-4F5C-B5AF-010C9A1052F1)), rawValues: [:]))
As always, please let me know if I can provide any other information here or in the Feedbacks.