Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load user's saved tracks #10

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The basic Vim and Emacs movement keys are supported instead of using arrow keys.
| `⌘F` or `⌘L` | global | Focus the search bar |
| `⌘Q` | global | Quit Spotiqueue |
| `⌘O` | global | List all of your saved playlists |
| `⌘P` | global | List all of your saved tracks |
| `⌘N` | global | Play next track from queue |
| `⌘;` or `⌘→` | search or queue | Browse details of selected item (see description below) |
| `⌘h` or `⌘←` | search | Enqueue selection at the bottom of the queue |
Expand Down
41 changes: 41 additions & 0 deletions Spotiqueue/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum SearchCommand {
case Album(Album)
case Artist(Artist)
case AllPlaylists
case AllSavedTracks
case Playlist(String, SpotifyURIConvertible)
}

Expand Down Expand Up @@ -126,6 +127,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.searchLabel.stringValue = "Artist: “\(artist.name)”"
case .AllPlaylists:
self.searchLabel.stringValue = "User Playlists"
case .AllSavedTracks:
self.searchLabel.stringValue = "User Saved Tracks"
case .Playlist(let title, _):
self.searchLabel.stringValue = "Playlist: “\(title)”"
}
Expand Down Expand Up @@ -372,6 +375,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
event.characters == "o"
{
self.retrieveAllPlaylists()
} else if flags == .command,
event.characters == "p"
{
self.retrieveAllSavedTracks()
} else if flags.isEmpty,
event.keyCode == kVK_Escape,
self.window.sheets.isEmpty // we don't want Esc eaten up if a modal is displayed
Expand Down Expand Up @@ -516,6 +523,38 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

func retrieveAllSavedTracks () {
guard !self.isSearching else {
return
}
self.isSearching = true

self.searchResults = []
self.filterResultsField.clearFilter()
self.searchResultsArrayController.sortDescriptors = []
self.searchHistory.append(.AllSavedTracks)

self.spotify.api.currentUserSavedTracks()
.extendPagesConcurrently(self.spotify.api)
.collectAndSortByOffset()
.receive(on: RunLoop.main)
.sink(receiveCompletion: { completion in
self.isSearching = false
if case .failure(let error) = completion {
logger.error("couldn't retrieve saved tracks: \(error.localizedDescription)")
}
},
receiveValue: { tracks in
for t in tracks {
self.searchResults.append(RBSpotifyItem(savedTrack: t))
}
self.searchTableView.selectRow(row: 0)
})
.store(in: &self.cancellables)

self.window.makeFirstResponder(self.searchTableView)
}

func retrieveAllPlaylists() {
guard !self.isSearching else {
return
Expand Down Expand Up @@ -569,6 +608,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.searchPlaylistTracks(for: row.spotify_uri, withTitle: row.title)
case .Playlist:
self.albumTracks(for: row.spotify_album)
case .AllSavedTracks:
self.albumTracks(for: row.spotify_album)
}
} else {
// The default case.
Expand Down
5 changes: 5 additions & 0 deletions Spotiqueue/Classes/RBSpotifyItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class RBSpotifyItem: NSObject {
@objc public enum ItemType: Int, RawRepresentable {
case Playlist
case Track
case SavedTrack
}

@objc dynamic var title: String
Expand Down Expand Up @@ -62,6 +63,10 @@ public final class RBSpotifyItem: NSObject {
self.itemType = .Playlist
}

convenience init(savedTrack: SavedTrack) {
self.init(track: savedTrack.item)
}

init(spotify_uri: String) {
// This is to create a placeholder/stub track object, to be hydrated later
self.spotify_uri = spotify_uri
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy