Skip to content

Commit

Permalink
Clean up playlists like we do artists
Browse files Browse the repository at this point in the history
There were some uh, nasty playlists on demo server that got cleaned up
remotely, but not locally
  • Loading branch information
NattyNarwhal committed Nov 14, 2023
1 parent 074e8aa commit 2e7318e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Submariner/SBSubsonicParsingOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class SBSubsonicParsingOperation: SBOperation, XMLParserDelegate {
var currentCoverID: String?

// state for deleting elements not in this list
var playlistsReturned: [SBPlaylist] = []
var artistsReturned: [SBArtist] = []

init!(managedObjectContext mainContext: NSManagedObjectContext!,
Expand Down Expand Up @@ -341,6 +342,7 @@ class SBSubsonicParsingOperation: SBOperation, XMLParserDelegate {
// we have an existing playlist, update it
updatePlaylist(playlist, attributes: attributeDict)
}
playlistsReturned.append(playlist!)
} else if requestType == .getPlaylist, let id = attributeDict["id"] {
currentPlaylist = fetchPlaylist(id: id)
} else {
Expand Down Expand Up @@ -597,6 +599,14 @@ class SBSubsonicParsingOperation: SBOperation, XMLParserDelegate {
} else if requestType == .getTrackDirectory {
postServerNotification(.SBSubsonicTracksUpdated)
} else if requestType == .getPlaylists {
let playlistRequest: NSFetchRequest<SBPlaylist> = SBPlaylist.fetchRequest()
playlistRequest.predicate = NSPredicate(format: "(server == %@) && (NOT (self IN %@))", server, playlistsReturned)
if let playlists = try? threadedContext.fetch(playlistRequest) {
for playlist in playlists {
logger.info("Removing artist not in list \(playlist.itemId ?? "<nil>", privacy: .public) name \(playlist.resourceName ?? "<nil>")")
threadedContext.delete(playlist)
}
}
postServerNotification(.SBSubsonicPlaylistsUpdated)
} else if requestType == .getPlaylist {
currentPlaylist = nil
Expand Down

0 comments on commit 2e7318e

Please sign in to comment.