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

Get top and similar tracks #219

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Similar tracks (radio) feature
Fixes GH-108
  • Loading branch information
NattyNarwhal committed Nov 13, 2024
commit 5a39cb235b5ce979ce1856704772da2075b3c034
1 change: 1 addition & 0 deletions Submariner/SBDatabaseController.h
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@
- (IBAction)showLibraryView:(id)sender;

- (void)getTopTracksFor:(NSString*)artistName;
- (void)getSimilarTracksTo:(SBArtist*)artist;

- (IBAction)openAudioFiles:(id)sender;
- (IBAction)toggleTrackList:(id)sender;
9 changes: 9 additions & 0 deletions Submariner/SBDatabaseController.m
Original file line number Diff line number Diff line change
@@ -957,6 +957,12 @@ - (void)getTopTracksFor:(NSString*)artistName {
}


- (void)getSimilarTracksTo:(SBArtist*)artist {
SBNavigationItem *navItem = [[SBServerSearchNavigationItem alloc] initWithServer: self.server similarTo:artist];
[self navigateForwardToNavItem: navItem];
}


- (IBAction)cleanTracklist:(id)sender {
[self stop: sender];
[tracklistController cleanTracklist: sender];
@@ -1909,6 +1915,9 @@ - (void)pageController:(NSPageController *)pageController didTransitionToObject:
} else if (searchNavItem.topTracksForArtist) {
[self.server getTopTracksForArtistName: searchNavItem.topTracksForArtist];
[searchField setStringValue: @""];
} else if (searchNavItem.similarToArtist) {
[self.server getSimilarTracksTo: searchNavItem.similarToArtist];
[searchField setStringValue: @""];
}
} else {
[searchField setStringValue: @""];
12 changes: 12 additions & 0 deletions Submariner/SBNavigationItem.swift
Original file line number Diff line number Diff line change
@@ -46,6 +46,13 @@ import Cocoa
return nil
}

@objc var similarToArtist: SBArtist? {
if case let .similarTo(artist) = self.query {
return artist
}
return nil
}

@objc init(server: SBServer, query: String) {
self.query = .search(query: query)
super.init(server: server)
@@ -55,6 +62,11 @@ import Cocoa
self.query = .topTracksFor(artistName: artistName)
super.init(server: server)
}

@objc init(server: SBServer, similarTo artist: SBArtist) {
self.query = .similarTo(artist: artist)
super.init(server: server)
}
}

@objc class SBPlaylistNavigationItem: SBNavigationItem {
2 changes: 1 addition & 1 deletion Submariner/SBSearchResult.swift
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import Cocoa
@objc class SBSearchResult: NSObject {
enum QueryType {
case search(query: String)
//case similarTo(trackID: String)
case similarTo(artist: SBArtist)
case topTracksFor(artistName: String)
}

5 changes: 5 additions & 0 deletions Submariner/SBServer.swift
Original file line number Diff line number Diff line change
@@ -525,6 +525,11 @@ public class SBServer: SBResource {
OperationQueue.sharedServerQueue.addOperation(request)
}

@objc func getSimilarTracks(to artist: SBArtist) {
let request = SBSubsonicRequestOperation(server: self, request: .getSimilarTracks(artist: artist))
OperationQueue.sharedServerQueue.addOperation(request)
}

// #MARK: - Subsonic Client (Rating)

@objc(setRating:forID:) func setRating(_ rating: Int, id: String) {
8 changes: 8 additions & 0 deletions Submariner/SBServerLibraryController.m
Original file line number Diff line number Diff line change
@@ -282,6 +282,14 @@ - (IBAction)getTopTracksForSelectedArtist:(id)sender {
}


- (IBAction)getSimilarTracksForSelectedArtist:(id)sender {
SBArtist *artist = [[self selectedArtists] firstObject];
if (artist) {
[self.databaseController getSimilarTracksTo: artist];
}
}


- (void)showTrackInLibrary:(SBTrack*)track {
[artistsController setSelectedObjects: @[track.album.artist]];
[artistsTableView scrollRowToVisible: [artistsTableView selectedRow]];
2 changes: 2 additions & 0 deletions Submariner/SBServerSearchController.swift
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import Cocoa
switch self.searchResult?.query {
case .search(let query):
self.title = "Search Results for \(query)"
case .similarTo(let artist):
self.title = "Similar Tracks to \(artist.itemName ?? "(unknown artist)")"
case .topTracksFor(let artistName):
self.title = "Top Tracks for \(artistName)"
default:
2 changes: 1 addition & 1 deletion Submariner/SBSubsonicParsingOperation.swift
Original file line number Diff line number Diff line change
@@ -625,7 +625,7 @@ class SBSubsonicParsingOperation: SBOperation, XMLParserDelegate {
postServerNotification(.SBSubsonicPlaylistsCreated)
case .getNowPlaying:
postServerNotification(.SBSubsonicNowPlayingUpdated)
case .search(_), .getTopTracks(artistName: _):
case .search(_), .getTopTracks(artistName: _), .getSimilarTracks(artist: _):
NotificationCenter.default.post(name: .SBSubsonicSearchResultUpdated, object: currentSearch)
case .getPodcasts:
postServerNotification(.SBSubsonicPodcastsUpdated)
6 changes: 6 additions & 0 deletions Submariner/SBSubsonicRequestOperation.swift
Original file line number Diff line number Diff line change
@@ -276,6 +276,12 @@ class SBSubsonicRequestOperation: SBOperation {
customization = { operation in
operation.currentSearch = SBSearchResult(query: .topTracksFor(artistName: artistName))
}
case .getSimilarTracks(let artist):
parameters["id"] = artist.itemId
url = URL.URLWith(string: server.url, command: "rest/getSimilarSongs2.view", parameters: parameters)
customization = { operation in
operation.currentSearch = SBSearchResult(query: .similarTo(artist: artist))
}
}
}
}
1 change: 1 addition & 0 deletions Submariner/SBSubsonicRequestType.swift
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ enum SBSubsonicRequestType: Equatable {
case star(tracks: [SBTrack], albums: [SBAlbum], artists: [SBArtist], directories: [SBDirectory])
case unstar(tracks: [SBTrack], albums: [SBAlbum], artists: [SBArtist], directories: [SBDirectory])
case getTopTracks(artistName: String)
case getSimilarTracks(artist: SBArtist)
}

@objc enum SBAlbumListType: Int {
6 changes: 6 additions & 0 deletions Submariner/ServerLibrary.xib
Original file line number Diff line number Diff line change
@@ -424,6 +424,12 @@
<action selector="getTopTracksForSelectedArtist:" target="-1" id="hnt-lV-CEC"/>
</connections>
</menuItem>
<menuItem title="Similar Tracks" id="TTQ-qJ-d48">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="getSimilarTracksForSelectedArtist:" target="-1" id="hSY-iE-iCA"/>
</connections>
</menuItem>
</items>
<point key="canvasLocation" x="89" y="-153"/>
</menu>