diff options
Diffstat (limited to 'MusicConverter/View/Napster/NapsterPlaylistView.swift')
-rw-r--r-- | MusicConverter/View/Napster/NapsterPlaylistView.swift | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/MusicConverter/View/Napster/NapsterPlaylistView.swift b/MusicConverter/View/Napster/NapsterPlaylistView.swift index ef907fe..0180dbb 100644 --- a/MusicConverter/View/Napster/NapsterPlaylistView.swift +++ b/MusicConverter/View/Napster/NapsterPlaylistView.swift @@ -17,7 +17,7 @@ struct NapsterPlaylistView: View { self.napsterPlaylist = Napster(id: id, api: api) self.napsterPlaylist.update(completion: {e in - if e == nil { + if e != nil { print("error updating: \(e!)") return } @@ -37,7 +37,7 @@ struct NapsterPlaylistView: View { Divider() Button(action: { showingSongs.toggle() }) { - Text("Songs") + Text("Songs (\(self.napsterPlaylist.appleChoices.count))") } } Text("trackCount: \(napsterPlaylist.tracks?.count ?? 0)") @@ -57,6 +57,7 @@ struct NapsterPlaylistView: View { return } self.updated = true + }) }) { Text("Update") @@ -78,26 +79,30 @@ struct NapsterPlaylistView_CreatButton: View { } var body: some View { - switch self.state { - case .none: - Button(action: { - DispatchQueue.global(qos: .userInitiated).async { - self.createPlaylist() - } - }, - label: { - Text("Create playlist") - }) - case .creating: + if self.napsterPlaylist.synced { + switch self.state { + case .none: + Button(action: { + DispatchQueue.global(qos: .userInitiated).async { + self.createPlaylist() + } + }, + label: { + Text("Create playlist") + }) + case .creating: + ProgressView() + case .created: + Text("done") + } + } else { ProgressView() - case .created: - Text("done") } } func createPlaylist() { self.state = .creating - self.napsterPlaylist.createApplePlaylist(completion: {result in + /*self.napsterPlaylist.createApplePlaylist(completion: {result in switch result { case .failure(let e): print("error creating: \(e)") @@ -113,6 +118,27 @@ struct NapsterPlaylistView_CreatButton: View { } }) } + })*/ + self.napsterPlaylist.api.createPlaylistAPI(name: self.napsterPlaylist.name, tracks: self.napsterPlaylist.appleChoices.filter { song in + if song.song.attributes.playParams != nil { + print("including") + return true + } + return false + }.map {song in + AppleMusicApi.LibraryPlaylistRequestTrack(id: song.song.attributes.playParams!.id, type: .songs) + } , description: "MusicConverter", completion: {result in + switch result { + case .failure(let e): + print("error creating playist: \(e)") + self.state = .none + case .success(_): + print("created playlist") + DispatchQueue.main.async { + //self.state = .created + self.state = .none + } + } }) } } |