Skip to content

Commit 6d923a4

Browse files
rudrankriyamclaude
andcommitted
Extract catalogID into separate computed property for Song
For consistency with Album and improved code modularity, extract the catalogID retrieval logic from playParameters into its own computed property on Song. This makes the code more reusable and maintains consistency across all music item types. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e46e02c commit 6d923a4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Sources/MusadoraKit/Library/MLibrary+Song.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,19 @@ public extension Song {
506506
/// - Throws: An error if the song is not in library or if the request fails.
507507
var inFavorites: Bool {
508508
get async throws {
509-
// Get catalog ID from play parameters
509+
let catalogId = try self.catalogID
510+
return try await InFavoritesParser.fetchInFavorites(for: catalogId, itemType: .songs)
511+
}
512+
}
513+
514+
/// The catalog identifier for the song.
515+
///
516+
/// This property decodes the play parameters of the song to retrieve its catalog identifier.
517+
///
518+
/// - Returns: The catalog ID of the song.
519+
/// - Throws: `MusadoraKitError.notFound` if play parameters or catalog ID are not available.
520+
var catalogID: MusicItemID {
521+
get throws {
510522
guard let playParameters = playParameters else {
511523
throw MusadoraKitError.notFound(for: "playParameters")
512524
}
@@ -518,7 +530,7 @@ public extension Song {
518530
throw MusadoraKitError.notFound(for: "catalogId")
519531
}
520532

521-
return try await InFavoritesParser.fetchInFavorites(for: catalogId, itemType: .songs)
533+
return catalogId
522534
}
523535
}
524536
}

0 commit comments

Comments
 (0)