AudioCollectionModel.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*****************************************************************************
  2. * AudioCollectionModel.swift
  3. *
  4. * Copyright © 2019 VLC authors and VideoLAN
  5. *
  6. * Authors: Edgar Fouillet <vlc # edgar.fouillet.eu>
  7. *
  8. * Refer to the COPYING file of the official project for license.
  9. *****************************************************************************/
  10. import Foundation
  11. protocol AudioCollectionModel: MLBaseModel { }
  12. extension AudioCollectionModel {
  13. func delete(_ items: [VLCMLObject]) {
  14. do {
  15. for case let item as MediaCollectionModel in items {
  16. if let tracks = item.files() {
  17. for track in tracks {
  18. if let mainFile = track.mainFile() {
  19. try FileManager.default.removeItem(atPath: mainFile.mrl.path)
  20. }
  21. }
  22. let folderPaths = Set(tracks.map {
  23. $0.mainFile()?.mrl.deletingLastPathComponent()
  24. })
  25. for path in folderPaths {
  26. if let path = path {
  27. try FileManager.default.deleteMediaFolder(name: item.title(), at: path)
  28. }
  29. }
  30. }
  31. }
  32. medialibrary.reload()
  33. }
  34. catch let error as NSError {
  35. assertionFailure("AudioCollectionModel: Delete failed: \(error.localizedDescription)")
  36. }
  37. }
  38. }