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

Use tag instead of directory based metadata #177

Merged
merged 20 commits into from
Nov 20, 2023
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
42 changes: 21 additions & 21 deletions Submariner/SBClientController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,12 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
request(url: url, type: .getLicense)
}

@objc func getIndexes() {
let url = URL.URLWith(string: server.url, command: "rest/getIndexes.view", parameters: parameters)
request(url: url, type: .getIndexes)
func getArtists() {
let url = URL.URLWith(string: server.url, command: "rest/getArtists.view", parameters: parameters)
request(url: url, type: .getArtists)
}

@objc(getIndexesSince:) func getIndexes(since: Date) {
var params = parameters
params["ifModifiedSince"] = String(format: "%00.f", since.timeIntervalSince1970 * 1000)

let url = URL.URLWith(string: server.url, command: "rest/getIndexes.view", parameters: params)
request(url: url, type: .getIndexes)
}

@objc(getAlbumsForArtist:) func getAlbums(artist: SBArtist) {
func get(artist: SBArtist) {
var params = parameters
if artist.itemId == nil {
// can happen because of now playing/search
Expand All @@ -145,8 +137,8 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
}
params["id"] = artist.itemId

let url = URL.URLWith(string: server.url, command: "rest/getMusicDirectory.view", parameters: params)
request(url: url, type: .getAlbumDirectory) { operation in
let url = URL.URLWith(string: server.url, command: "rest/getArtist.view", parameters: params)
request(url: url, type: .getArtist) { operation in
operation.currentArtistID = artist.itemId
}
}
Expand All @@ -161,13 +153,21 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
}
}

@objc(getTracksForAlbumID:) func getTracks(albumID: String) {
func getTrack(trackID: String) {
var params = parameters
params["id"] = trackID

let url = URL.URLWith(string: server.url, command: "rest/getSong.view", parameters: params)
request(url: url, type: .getTrack)
}

func get(album: SBAlbum) {
var params = parameters
params["id"] = albumID
params["id"] = album.itemId

let url = URL.URLWith(string: server.url, command: "rest/getMusicDirectory.view", parameters: params)
request(url: url, type: .getTrackDirectory) { operation in
operation.currentAlbumID = albumID
let url = URL.URLWith(string: server.url, command: "rest/getAlbum.view", parameters: params)
request(url: url, type: .getAlbum) { operation in
operation.currentAlbumID = album.itemId
}
}

Expand Down Expand Up @@ -273,7 +273,7 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
abort()
}

let url = URL.URLWith(string: server.url, command: "rest/getAlbumList.view", parameters: params)
let url = URL.URLWith(string: server.url, command: "rest/getAlbumList2.view", parameters: params)
request(url: url, type: type)
}

Expand All @@ -295,7 +295,7 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
params["query"] = query
params["songCount"] = "100" // XXX: Configurable? Pagination?

let url = URL.URLWith(string: server.url, command: "rest/search2.view", parameters: params)
let url = URL.URLWith(string: server.url, command: "rest/search3.view", parameters: params)
request(url: url, type: .search) { operation in
operation.currentSearch = SBSearchResult(query: query)
}
Expand Down
6 changes: 3 additions & 3 deletions Submariner/SBDatabaseController.m
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ - (void)reloadServerInternal: (SBServer*)server {
return;
}
[server getServerLicense];
[server getServerIndexes];
[server getArtists];
[server getServerPlaylists];
// XXX: Check if it's the current VC too?
if (server != nil && serverHomeController.server == server) {
Expand Down Expand Up @@ -860,7 +860,7 @@ - (IBAction)showPodcasts:(id)sender {
return;
}
[self.server setSelectedTabIndex: 2];
SBNavigationItem *navItem = [[SBServerHomeNavigationItem alloc] initWithServer: self.server];
SBNavigationItem *navItem = [[SBServerPodcastsNavigationItem alloc] initWithServer: self.server];
[self navigateForwardToNavItem: navItem];
}

Expand Down Expand Up @@ -1380,7 +1380,7 @@ - (void)subsonicConnectionFailed:(NSNotification *)notification {
- (void)subsonicConnectionSucceeded:(NSNotification *)notification {
// loading of server content, major !!!
[self.server getServerLicense];
[self.server getServerIndexes];
[self.server getArtists];
[self.server getServerPlaylists];
}

Expand Down
8 changes: 4 additions & 4 deletions Submariner/SBEpisode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public class SBEpisode: SBTrack {
let path = self.path,
FileManager.default.fileExists(atPath: path) {
return URL.init(fileURLWithPath: path)
} else if let server = self.server, let url = server.url {
} else if let server = self.server, let streamID = self.streamID, let url = server.url {
var parameters = server.getBaseParameters()
parameters["id"] = self.itemId
parameters["id"] = streamID

return URL.URLWith(string: url, command: "rest/stream.view", parameters: parameters)
}
return nil
}

@objc override func downloadURL() -> URL? {
if let server = self.server, let url = server.url {
if let server = self.server, let streamID = self.streamID, let url = server.url {
var parameters = server.getBaseParameters()
parameters["id"] = self.itemId
parameters["id"] = streamID

return URL.URLWith(string: url, command: "rest/download.view", parameters: parameters)
}
Expand Down
16 changes: 6 additions & 10 deletions Submariner/SBServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,16 @@ public class SBServer: SBResource {

// #MARK: - Subsonic Client (Server Data)

@objc func getServerIndexes() {
if let lastIndexesDate = self.lastIndexesDate {
self.clientController.getIndexes(since: lastIndexesDate)
} else {
self.clientController.getIndexes()
}
@objc func getArtists() {
self.clientController.getArtists()
}

@objc func getAlbumsFor(artist: SBArtist) {
self.clientController.getAlbums(artist: artist)
@objc(getArtist:) func get(artist: SBArtist) {
self.clientController.get(artist: artist)
}

@objc func getTracksFor(albumID: String) {
self.clientController.getTracks(albumID: albumID)
@objc(getAlbum:) func get(album: SBAlbum) {
self.clientController.get(album: album)
}

@objc func getAlbumListFor(type: SBSubsonicParsingOperation.RequestType) {
Expand Down
9 changes: 5 additions & 4 deletions Submariner/SBServerHomeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ - (void)loadView {
[NSDictionary dictionaryWithObjectsAndKeys:
@"NewestItem", ITEM_IDENTIFIER,
@"Newest", ITEM_NAME, nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"HighestItem", ITEM_IDENTIFIER,
@"Highest", ITEM_NAME, nil],
// "highest" isn't supported by albumList2 in Subsonic or Navidrome for some reason...
// [NSDictionary dictionaryWithObjectsAndKeys:
// @"HighestItem", ITEM_IDENTIFIER,
// @"Highest", ITEM_NAME, nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"FrequentItem", ITEM_IDENTIFIER,
@"Frequent", ITEM_NAME, nil],
Expand Down Expand Up @@ -382,7 +383,7 @@ - (void)imageBrowserSelectionDidChange:(IKImageBrowserView *)aBrowser {

// reset current tracks
[tracksController setContent:nil];
[self.server getTracksForAlbumID: album.itemId];
[self.server getAlbum: album];

if([album.tracks count] == 0) {
// wait for new tracks
Expand Down
4 changes: 2 additions & 2 deletions Submariner/SBServerLibraryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ - (void)tableViewSelectionDidChange:(NSNotification *)notification {
if(selectedRow != -1) {
SBArtist *selectedArtist = [[artistsController arrangedObjects] objectAtIndex:selectedRow];
if(selectedArtist && [selectedArtist isKindOfClass:[SBArtist class]]) {
[self.server getAlbumsForArtist:selectedArtist];
[self.server getArtist:selectedArtist];
[albumsBrowserView setSelectionIndexes:nil byExtendingSelection:NO];
}
}
Expand Down Expand Up @@ -618,7 +618,7 @@ - (void)imageBrowserSelectionDidChange:(IKImageBrowserView *)aBrowser {
SBAlbum *album = [[albumsController arrangedObjects] objectAtIndex:selectedRow];
if(album) {

[self.server getTracksForAlbumID: album.itemId];
[self.server getAlbum: album];

if([album.tracks count] == 0) {
// wait for new tracks
Expand Down
2 changes: 1 addition & 1 deletion Submariner/SBServerPodcastController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (NSString*)title {
- (id)initWithManagedObjectContext:(NSManagedObjectContext *)context {
self = [super initWithManagedObjectContext:context];
if (self) {
NSSortDescriptor *descr1 = [NSSortDescriptor sortDescriptorWithKey:@"id" ascending:YES];
NSSortDescriptor *descr1 = [NSSortDescriptor sortDescriptorWithKey:@"itemId" ascending:YES];
podcastsSortDescriptors = [[NSArray alloc] initWithObjects:descr1, nil];

NSSortDescriptor *descr2 = [NSSortDescriptor sortDescriptorWithKey:@"publishDate" ascending:NO];
Expand Down
7 changes: 6 additions & 1 deletion Submariner/SBSubsonicDownloadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ fileprivate let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, catego
}

// SBImportOperation needs an audio file extension. Rename the file.
let fileType = UTType(mimeType: downloadTask.response?.mimeType ?? "audio/mp3") ?? UTType.mp3
var proposedMimeType = downloadTask.response?.mimeType
if proposedMimeType == "application/x-download" {
// XXX: get a better one
proposedMimeType = nil
}
let fileType = UTType(mimeType: proposedMimeType ?? "audio/mp3") ?? UTType.mp3
let temporaryFile = URL.temporaryFile().appendingPathExtension(for: fileType)
try! FileManager.default.moveItem(at: location, to: temporaryFile)

Expand Down
Loading
Loading