             OfflineUtils.removeMediaLocation(from: media)
             sambaMediasDownloaded.removeAll(where: {$0.id == media.id})
             OfflineUtils.persistDownloadedMedias(sambaMediasDownloaded)
-                
-            let downloadState = DownloadState.from(state: isError ? DownloadState.State.FAILED : DownloadState.State.CANCELED , totalDownloadSize: media.downloadData?.totalDownloadSizeInMB ?? 0, downloadPercentage: 0, media: media)
-                
-            OfflineUtils.sendNotification(with: downloadState)
-            
+            
+            
+            if isNotify {
+                let downloadState = DownloadState.from(state: isError ? DownloadState.State.FAILED : DownloadState.State.DELETED , totalDownloadSize: media.downloadData?.totalDownloadSizeInMB ?? 0, downloadPercentage: 0, media: media)
+                
+                OfflineUtils.sendNotification(with: downloadState)
+            }
+         
         } catch {
             print("An error occured deleting the file: \(error)")
         }

        deleteMediaDownload(media)
    }
    
    fileprivate func deleteMediaDownload(_ media: SambaMediaConfig, _ isError: Bool = false) {
        
        do {
            guard let localFileLocation = OfflineUtils.localAssetForMedia(withMedia: media)?.url else {

    
    func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask,
                    didFinishDownloadingTo location: URL) {
        
        guard let media = activeDownloadsMap[assetDownloadTask] else {
            return
        }

        do {
            let bookmark = try location.bookmarkData()
            OfflineUtils.saveMediaLocation(with: media, location: bookmark)
            media.isOffline = true
                
            if !sambaMediasDownloaded.contains(where: {$0.id == media.id}) {
                sambaMediasDownloaded.append(media)
            } else {
                let newMedia = sambaMediasDownloaded.filter({$0.id == media.id})
                newMedia.forEach({$0.isOffline = true})
            }
                
                
            OfflineUtils.persistDownloadedMedias(sambaMediasDownloaded)
            
        } catch {
                print("Failed to create bookmark for location: \(location)")
                deleteMediaDownload(media, true)
        }
    }
    
