 
 
 extension Notification.Name {
-   
+    
     static let SambaDownloadProgress = Notification.Name(rawValue: "SambaDownloadProgressNotification")
     
     static let SambaDownloadStateChanged = Notification.Name(rawValue: "SambaDownloadStateChangedNotification")
-
+    
     static let SambaPersistenceManagerDidRestoreState = Notification.Name(rawValue: "SambaPersistenceManagerDidRestoreStateNotification")
 }
 

        //        NotificationCenter.default.post(name: .AssetDownloadStateChanged, object: nil, userInfo: userInfo)
        //    }
        //
        //    func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask,
        //                    didFinishDownloadingTo location: URL) {
        //        let userDefaults = UserDefaults.standard
        //
        //        /*
        //         This delegate callback should only be used to save the location URL
        //         somewhere in your application. Any additional work should be done in
        //         `URLSessionTaskDelegate.urlSession(_:task:didCompleteWithError:)`.
        //         */
        //        if let asset = activeDownloadsMap[assetDownloadTask] {
        //
        //            do {
        //                let bookmark = try location.bookmarkData()
        //
        //                userDefaults.set(bookmark, forKey: asset.stream.name)
        //            } catch {
        //                print("Failed to create bookmark for location: \(location)")
        //                deleteAsset(asset)
        //            }
        //        }
    }
    
    func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didLoad timeRange: CMTimeRange,
                    totalTimeRangesLoaded loadedTimeRanges: [NSValue], timeRangeExpectedToLoad: CMTimeRange) {
        
                guard let media = activeDownloadsMap[assetDownloadTask] else { return }
        
                var percentComplete = 0.0
                for value in loadedTimeRanges {
                    let loadedTimeRange: CMTimeRange = value.timeRangeValue
                    percentComplete += CMTimeGetSeconds(loadedTimeRange.duration) / CMTimeGetSeconds(timeRangeExpectedToLoad.duration)
                }
        
                var userInfo = [DownloadState.Key: Any]()
        
                userInfo[DownloadState.Key.progress] = DownloadState.from(state: DownloadState.State.IN_PROGRESS, totalDownloadSize: media.downloadData?.totalDownloadSizeInMB ?? 0, downloadPercentage: Float(percentComplete), media: media, sambaSubtitle: nil)
        
        
                NotificationCenter.default.post(name: .SambaDownloadProgress, object: nil, userInfo: userInfo)
    }
    
    func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask,
                    didResolve resolvedMediaSelection: AVMediaSelection) {
  
        mediaSelectionMap[assetDownloadTask] = resolvedMediaSelection
        
    }

        var userInfo = [DownloadState.Key: Any]()
        
        userInfo[DownloadState.Key.state] = downloadState
        
        NotificationCenter.default.post(name: .SambaDownloadStateChanged, object: nil, userInfo: userInfo)
        
    }
    
    func isDownloading(_ mediaId: String) -> Bool {
        guard activeDownloadsMap.contains(where: { $1.id == mediaId }),
            sambaMediasDownloading.contains(where: { $0.id == mediaId}) else {
                return false
        }
        
        return true
