Handle download complete lifecycle

This commit is contained in:
ronaldheft
2022-08-07 10:27:08 -04:00
parent 5495bcb945
commit b549528e23
5 changed files with 62 additions and 9 deletions
+7 -2
View File
@@ -9,7 +9,7 @@ import Foundation
import Unrealm
struct DownloadItem: Realmable, Codable {
var id: String = UUID().uuidString
var id: String?
var libraryItemId: String?
var episodeId: String?
var userMediaProgress: MediaProgress?
@@ -36,6 +36,7 @@ struct DownloadItem: Realmable, Codable {
extension DownloadItem {
init(libraryItem: LibraryItem, server: ServerConnectionConfig) {
self.id = libraryItem.id
self.libraryItemId = libraryItem.id
//self.episodeId // TODO
self.userMediaProgress = libraryItem.userMediaProgress
@@ -52,7 +53,7 @@ extension DownloadItem {
}
func didDownloadSuccessfully() -> Bool {
self.downloadItemParts.allSatisfy({ $0.failed = false })
self.downloadItemParts.allSatisfy({ $0.failed == false })
}
}
@@ -101,6 +102,10 @@ extension DownloadItemPart {
self.destinationUri = destination.path
}
func mimeType() -> String? {
audioTrack?.mimeType ?? episode?.audioTrack?.mimeType
}
func downloadURL() -> URL? {
if let uri = self.uri {
return URL(string: uri)