-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at Implementation of MusicKit as a Source (#55)
- There is not a 100% mapping of properties... tbd as to what will be done.
- Loading branch information
Showing
2 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// Track+Song.swift | ||
// | ||
// | ||
// Created by Greg Bolsinga on 10/31/23. | ||
// | ||
|
||
import Foundation | ||
import MusicKit | ||
|
||
extension Track { | ||
init(_ song: Song) { | ||
// let refinedSong = try await song.with([.albums], preferredSource: .library) | ||
|
||
self.album = song.albumTitle | ||
self.albumArtist = song.artistName | ||
// self.albumRating = album.rating | ||
// self.albumRatingComputed = song.isRatingComputed | ||
self.artist = song.artistName | ||
// self.bitRate = song.bitrate | ||
// self.bPM = song.beatsPerMinute | ||
// self.comments = comments | ||
// self.compilation = album.isCompilation | ||
self.composer = song.composerName | ||
// self.contentRating = contentRating | ||
self.dateAdded = song.libraryAddedDate | ||
// self.dateModified = date | ||
// self.disabled = song.isUserDisabled | ||
// self.discCount = album.discCount | ||
self.discNumber = song.discNumber | ||
if let contentRating = song.contentRating, contentRating == .explicit { | ||
self.explicit = true | ||
} | ||
self.genre = song.genreNames.first | ||
// self.grouping = grouping | ||
// self.hasVideo = true | ||
// self.kind = kind | ||
// self.location = location.absoluteString | ||
// self.movie = true | ||
// self.musicVideo = true | ||
// self.podcast = true | ||
// self.tVShow = true | ||
self.name = song.title | ||
// self.partOfGaplessAlbum = album.isGapless | ||
// | ||
self.persistentID = UInt(song.id.rawValue) ?? 0 | ||
self.playCount = song.playCount | ||
self.playDateUTC = song.lastPlayedDate | ||
// self.protected = song.isDRMProtected | ||
// self.purchased = song.isPurchased | ||
// self.rating = song.rating | ||
// self.ratingComputed = song.isRatingComputed | ||
self.releaseDate = song.releaseDate | ||
// self.sampleRate = song.sampleRate | ||
// self.size = song.fileSize | ||
// self.skipCount = song.skipCount | ||
// self.skipDate = date | ||
// self.sortAlbum = name | ||
// self.sortAlbumArtist = name | ||
// self.sortArtist = name | ||
// self.sortComposer = sortComposer | ||
// self.sortName = sortName | ||
if let duration = song.duration { | ||
self.totalTime = Int(duration) | ||
} | ||
// | ||
// self.trackCount = album.trackCount | ||
self.trackNumber = song.trackNumber | ||
// self.trackType = "File" | ||
// self.trackType = "URL" | ||
// self.trackType = "Remote" | ||
// self.unplayed = playStatus | ||
// self.year = song.year | ||
|
||
// if let videoInfo = song.videoInfo { | ||
// if let episode = videoInfo.episode { | ||
// self.episode = episode | ||
// } | ||
// if videoInfo.episodeOrder != 0 { | ||
// self.episodeOrder = videoInfo.episodeOrder | ||
// } | ||
// if videoInfo.isHD { | ||
// self.hD = videoInfo.isHD | ||
// } | ||
// if videoInfo.season != 0 { | ||
// self.season = videoInfo.season | ||
// } | ||
// if let series = videoInfo.series { | ||
// self.series = series | ||
// } | ||
// if let sortSeries = videoInfo.sortSeries { | ||
// self.sortSeries = sortSeries | ||
// } | ||
// if videoInfo.videoHeight != 0 { | ||
// self.videoHeight = videoInfo.videoHeight | ||
// } | ||
// if videoInfo.videoWidth != 0 { | ||
// self.videoWidth = videoInfo.videoWidth | ||
// } | ||
// } | ||
} | ||
} | ||
|
||
extension Track { | ||
static func requestAccess() async { | ||
let musicAuthorizationStatus = await MusicAuthorization.request() | ||
print("\(musicAuthorizationStatus)") | ||
} | ||
|
||
static public func gatherWithMusicKit() async throws -> [Track] { | ||
await requestAccess() | ||
|
||
let request = MusicLibraryRequest<Song>() | ||
let response = try await request.response() | ||
return response.items.map { Track($0) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters