             let url = episode.audioURL else { return }
 
         let task = session.downloadTask(with: url)
-        downloadedUrls[url] = task
+        downloadedUrls[task] = url
         let downloadInfo = NSManagedObject(entity: entity, insertInto: appDelegate.dataController.managedObjectContext)
         downloadInfo.setValuesForKeys([
             DownloadInfo.Keys.progress: 0,

        // Fetch download info by identifier
        if let downloadInfo = DownloadInfo.fetchDownloadInfo(with: task.taskIdentifier) {
            downloadInfo.setValue(DownloadInfoStatus.failed, forKey: DownloadInfo.Keys.status)
        }
        saveData()
        // Send notification about error
        // Do we need to send user info?
        NotificationCenter.default.post(name: .didFailDownload, object: nil)
    }

}

        guard let url = episode.audioURL, let downloadInfo = episode.downloadInfo,
            let resumeData = downloadInfo.resumeData else { return }
        let task = session.downloadTask(withResumeData: resumeData)
        downloadedUrls[task] = url
        downloadInfo.setValue(task.taskIdentifier, forKey: DownloadInfo.Keys.identifier)
        saveData()
        task.resume()
