Skip to content

Commit

Permalink
Add .all for all extended properties for both iOS 15 and iOS 16
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Jul 23, 2022
1 parent 938cbdd commit 8c5fd66
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Sources/MusadoraKit/Catalog/CatalogAlbum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@ public extension MusadoraKit {
return response.items
}
}

extension Array where Element == PartialMusicAsyncProperty<Album> {
public static var all: Self {
#if compiler(>=5.7)
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
return [.artistURL, .genres, .artists, .audioVariants, .appearsOn, .otherVersions, .recordLabels, .relatedAlbums, .relatedVideos, .tracks]
}
#else
return [.artistURL, .genres, .artists, .appearsOn, .otherVersions, .recordLabels, .relatedAlbums, .relatedVideos, .tracks]
#endif
}
}
38 changes: 34 additions & 4 deletions Sources/MusadoraKit/Catalog/CatalogArtist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public extension MusadoraKit {
/// - properties: Additional relationships to fetch with the artist.
/// - Returns: `Artist` matching the given identifier.
static func catalogArtist(id: MusicItemID,
with properties: [PartialMusicAsyncProperty<Artist>] = []) async throws -> Artist
{
with properties: [PartialMusicAsyncProperty<Artist>] = []) async throws -> Artist {
var request = MusicCatalogResourceRequest<Artist>(matching: \.id, equalTo: id)
request.properties = properties
let response = try await request.response()
Expand All @@ -29,17 +28,48 @@ public extension MusadoraKit {
return artist
}

/// Fetch an artist from the Apple Music catalog by using its identifier with all properties.
/// - Parameters:
/// - id: The unique identifier for the artist.
/// - Returns: `Artist` matching the given identifier.
static func catalogArtist(id: MusicItemID) async throws -> Artist {
var request = MusicCatalogResourceRequest<Artist>(matching: \.id, equalTo: id)
request.properties = .all
let response = try await request.response()

guard let artist = response.items.first else {
throw MusadoraKitError.notFound(for: id.rawValue)
}
return artist
}

/// Fetch multiple artists from the Apple Music catalog by using their identifiers.
/// - Parameters:
/// - ids: The unique identifiers for the artists.
/// - properties: Additional relationships to fetch with the artists.
/// - Returns: `Artists` matching the given identifiers.
static func catalogArtists(ids: [MusicItemID],
with properties: [PartialMusicAsyncProperty<Artist>] = []) async throws -> Artists
{
with properties: [PartialMusicAsyncProperty<Artist>] = []) async throws -> Artists {
var request = MusicCatalogResourceRequest<Artist>(matching: \.id, memberOf: ids)
request.properties = properties
let response = try await request.response()
return response.items
}

/// Fetch multiple artists from the Apple Music catalog by using their identifiers with all properties.
/// - Parameters:
/// - ids: The unique identifiers for the artists.
/// - Returns: `Artists` matching the given identifiers.
static func catalogArtists(ids: [MusicItemID]) async throws -> Artists {
var request = MusicCatalogResourceRequest<Artist>(matching: \.id, memberOf: ids)
request.properties = .all
let response = try await request.response()
return response.items
}
}

extension Array where Element == PartialMusicAsyncProperty<Artist> {
public static var all: Self {
[.genres, .station, .musicVideos, .albums, .playlists, .appearsOnAlbums, .fullAlbums, .featuredAlbums, .liveAlbums, .compilationAlbums, .featuredPlaylists, .latestRelease, .topSongs, .topMusicVideos, .similarArtists, .singles]
}
}
8 changes: 8 additions & 0 deletions Sources/MusadoraKit/Catalog/CatalogCurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ public extension MusadoraKit {
return response.items
}
}

@available(iOS 15.4, macOS 12.3, tvOS 15.4, *)
@available(watchOS, unavailable)
extension Array where Element == PartialMusicAsyncProperty<Curator> {
public static var all: Self {
[.playlists]
}
}
6 changes: 6 additions & 0 deletions Sources/MusadoraKit/Catalog/CatalogMusicVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ public extension MusadoraKit {
return response.items
}
}

extension Array where Element == PartialMusicAsyncProperty<MusicVideo> {
public static var all: Self {
[.albums, .genres, .artists, .artistURL, .moreInGenre, .songs, .moreByArtist]
}
}
12 changes: 12 additions & 0 deletions Sources/MusadoraKit/Catalog/CatalogPlaylist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ public extension MusadoraKit {
return response.items
}
}

extension Array where Element == PartialMusicAsyncProperty<Playlist> {
public static var all: Self {
#if compiler(>=5.7)
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
return [.tracks, .curator, .featuredArtists, .moreByCurator, .radioShow]
}
#else
return [.tracks, .featuredArtists, .moreByCurator]
#endif
}
}
8 changes: 8 additions & 0 deletions Sources/MusadoraKit/Catalog/CatalogRadioShow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ public extension MusadoraKit {
return response.items
}
}

@available(iOS 15.4, macOS 12.3, tvOS 15.4, *)
@available(watchOS, unavailable)
extension Array where Element == PartialMusicAsyncProperty<RadioShow> {
public static var all: Self {
[.playlists]
}
}
44 changes: 40 additions & 4 deletions Sources/MusadoraKit/Catalog/CatalogRecordLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public extension MusadoraKit {
/// - properties: Additional relationships to fetch with the record label.
/// - Returns: `RecordLabel` matching the given identifier.
static func catalogRecordLabel(id: MusicItemID,
with properties: [PartialMusicAsyncProperty<RecordLabel>] = []) async throws -> RecordLabel
{
with properties: [PartialMusicAsyncProperty<RecordLabel>] = []) async throws -> RecordLabel {
var request = MusicCatalogResourceRequest<RecordLabel>(matching: \.id, equalTo: id)
request.properties = properties
let response = try await request.response()
Expand All @@ -29,17 +28,54 @@ public extension MusadoraKit {
return recordLabel
}

#if compiler(>=5.7)
/// Fetch a record label from the Apple Music catalog by using its identifier with all properties.
/// - Parameters:
/// - id: The unique identifier for the record label.
/// - Returns: `RecordLabel` matching the given identifier.
static func catalogRecordLabel(id: MusicItemID) async throws -> RecordLabel {
var request = MusicCatalogResourceRequest<RecordLabel>(matching: \.id, equalTo: id)
request.properties = .all
let response = try await request.response()

guard let recordLabel = response.items.first else {
throw MusadoraKitError.notFound(for: id.rawValue)
}
return recordLabel
}
#endif

/// Fetch multiple record labels from the Apple Music catalog by using their identifiers.
/// - Parameters:
/// - ids: The unique identifiers for the record labels.
/// - properties: Additional relationships to fetch with the record labels.
/// - Returns: `RecordLabels` matching the given identifiers.
static func catalogRecordLabels(ids: [MusicItemID],
with properties: [PartialMusicAsyncProperty<RecordLabel>] = []) async throws -> RecordLabels
{
with properties: [PartialMusicAsyncProperty<RecordLabel>] = []) async throws -> RecordLabels {
var request = MusicCatalogResourceRequest<RecordLabel>(matching: \.id, memberOf: ids)
request.properties = properties
let response = try await request.response()
return response.items
}

#if compiler(>=5.7)
/// Fetch multiple record labels from the Apple Music catalog by using their identifiers with all properties.
/// - Parameters:
/// - ids: The unique identifiers for the record labels.
/// - Returns: `RecordLabels` matching the given identifiers.
static func catalogRecordLabels(ids: [MusicItemID]) async throws -> RecordLabels {
var request = MusicCatalogResourceRequest<RecordLabel>(matching: \.id, memberOf: ids)
request.properties = .all
let response = try await request.response()
return response.items
}
#endif
}

#if compiler(>=5.7)
extension Array where Element == PartialMusicAsyncProperty<RecordLabel> {
public static var all: Self {
[.latestReleases, .topReleases]
}
}
#endif
9 changes: 7 additions & 2 deletions Sources/MusadoraKit/Catalog/CatalogSong.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ public extension MusadoraKit {
}
}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
extension Array where Element == PartialMusicAsyncProperty<Song> {
public static var all: Self {
[.audioVariants, .albums, .artists, .composers, .genres, .musicVideos, .artistURL, .station]
#if compiler(>=5.7)
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
return [.audioVariants, .albums, .artists, .composers, .genres, .musicVideos, .artistURL, .station]
}
#else
return [.albums, .artists, .composers, .genres, .musicVideos, .artistURL, .station]
#endif
}
}

0 comments on commit 8c5fd66

Please sign in to comment.