mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-07-30 00:18:43 +02:00
Download part removed after no updates for 10 seconds, still need to fix the UI
This commit is contained in:
@@ -127,6 +127,11 @@ class DownloadItemManager(
|
|||||||
val internalProgressCallback =
|
val internalProgressCallback =
|
||||||
object : InternalProgressCallback {
|
object : InternalProgressCallback {
|
||||||
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
||||||
|
// Store time progress was last changed to prevent stale downloads from getting
|
||||||
|
// stuck in an infinite loop
|
||||||
|
if (downloadItemPart.bytesDownloaded != totalBytesWritten) {
|
||||||
|
downloadItemPart.lastUpdateTime = System.currentTimeMillis()
|
||||||
|
}
|
||||||
downloadItemPart.bytesDownloaded = totalBytesWritten
|
downloadItemPart.bytesDownloaded = totalBytesWritten
|
||||||
downloadItemPart.progress = progress
|
downloadItemPart.progress = progress
|
||||||
}
|
}
|
||||||
@@ -215,6 +220,21 @@ class DownloadItemManager(
|
|||||||
downloadItem?.let { checkDownloadItemFinished(it) }
|
downloadItem?.let { checkDownloadItemFinished(it) }
|
||||||
}
|
}
|
||||||
currentDownloadItemParts.remove(downloadItemPart)
|
currentDownloadItemParts.remove(downloadItemPart)
|
||||||
|
} else {
|
||||||
|
// Check for stalled downloads
|
||||||
|
val currentTimeMillis = System.currentTimeMillis()
|
||||||
|
val lastUpdateTime = downloadItemPart.lastUpdateTime ?: currentTimeMillis
|
||||||
|
val timeSinceLastUpdate = currentTimeMillis - lastUpdateTime
|
||||||
|
val stallTimeoutMillis = 10 * 1000 // 10 seconds
|
||||||
|
if (timeSinceLastUpdate > stallTimeoutMillis) {
|
||||||
|
Log.w(
|
||||||
|
tag,
|
||||||
|
"Download stalled for ${downloadItemPart.filename}, removing from download queue."
|
||||||
|
)
|
||||||
|
downloadItemPart.failed = true
|
||||||
|
clientEventEmitter.onDownloadItemPartUpdate(downloadItemPart)
|
||||||
|
currentDownloadItemParts.remove(downloadItemPart)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,32 +12,45 @@ import com.fasterxml.jackson.annotation.JsonIgnore
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
data class DownloadItemPart(
|
data class DownloadItemPart(
|
||||||
val id: String,
|
val id: String,
|
||||||
val downloadItemId: String,
|
val downloadItemId: String,
|
||||||
val filename: String,
|
val filename: String,
|
||||||
val fileSize: Long,
|
val fileSize: Long,
|
||||||
val finalDestinationPath:String,
|
val finalDestinationPath: String,
|
||||||
val serverPath: String,
|
val serverPath: String,
|
||||||
val localFolderName: String,
|
val localFolderName: String,
|
||||||
val localFolderUrl: String,
|
val localFolderUrl: String,
|
||||||
val localFolderId: String,
|
val localFolderId: String,
|
||||||
val ebookFile: EBookFile?,
|
val ebookFile: EBookFile?,
|
||||||
val audioTrack: AudioTrack?,
|
val audioTrack: AudioTrack?,
|
||||||
val episode: PodcastEpisode?,
|
val episode: PodcastEpisode?,
|
||||||
var completed:Boolean,
|
var completed: Boolean,
|
||||||
var moved:Boolean,
|
var moved: Boolean,
|
||||||
var isMoving:Boolean,
|
var isMoving: Boolean,
|
||||||
var failed:Boolean,
|
var failed: Boolean,
|
||||||
@JsonIgnore val uri: Uri,
|
@JsonIgnore val uri: Uri,
|
||||||
@JsonIgnore val destinationUri: Uri,
|
@JsonIgnore val destinationUri: Uri,
|
||||||
@JsonIgnore val finalDestinationUri: Uri,
|
@JsonIgnore val finalDestinationUri: Uri,
|
||||||
val finalDestinationSubfolder: String,
|
val finalDestinationSubfolder: String,
|
||||||
var downloadId: Long?,
|
var downloadId: Long?,
|
||||||
var progress: Long,
|
var lastUpdateTime: Long?,
|
||||||
var bytesDownloaded: Long
|
var progress: Long,
|
||||||
|
var bytesDownloaded: Long
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun make(downloadItemId:String, filename:String, fileSize: Long, destinationFile: File, finalDestinationFile: File, subfolder:String, serverPath:String, localFolder: LocalFolder, ebookFile: EBookFile?, audioTrack: AudioTrack?, episode: PodcastEpisode?) :DownloadItemPart {
|
fun make(
|
||||||
|
downloadItemId: String,
|
||||||
|
filename: String,
|
||||||
|
fileSize: Long,
|
||||||
|
destinationFile: File,
|
||||||
|
finalDestinationFile: File,
|
||||||
|
subfolder: String,
|
||||||
|
serverPath: String,
|
||||||
|
localFolder: LocalFolder,
|
||||||
|
ebookFile: EBookFile?,
|
||||||
|
audioTrack: AudioTrack?,
|
||||||
|
episode: PodcastEpisode?
|
||||||
|
): DownloadItemPart {
|
||||||
val destinationUri = Uri.fromFile(destinationFile)
|
val destinationUri = Uri.fromFile(destinationFile)
|
||||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||||
|
|
||||||
@@ -47,40 +60,46 @@ data class DownloadItemPart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val downloadUri = Uri.parse(downloadUrl)
|
val downloadUri = Uri.parse(downloadUrl)
|
||||||
Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri")
|
Log.d(
|
||||||
|
"DownloadItemPart",
|
||||||
|
"Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri"
|
||||||
|
)
|
||||||
return DownloadItemPart(
|
return DownloadItemPart(
|
||||||
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
||||||
downloadItemId,
|
downloadItemId,
|
||||||
filename = filename,
|
filename = filename,
|
||||||
fileSize = fileSize,
|
fileSize = fileSize,
|
||||||
finalDestinationPath = finalDestinationFile.absolutePath,
|
finalDestinationPath = finalDestinationFile.absolutePath,
|
||||||
serverPath = serverPath,
|
serverPath = serverPath,
|
||||||
localFolderName = localFolder.name,
|
localFolderName = localFolder.name,
|
||||||
localFolderUrl = localFolder.contentUrl,
|
localFolderUrl = localFolder.contentUrl,
|
||||||
localFolderId = localFolder.id,
|
localFolderId = localFolder.id,
|
||||||
ebookFile = ebookFile,
|
ebookFile = ebookFile,
|
||||||
audioTrack = audioTrack,
|
audioTrack = audioTrack,
|
||||||
episode = episode,
|
episode = episode,
|
||||||
completed = false,
|
completed = false,
|
||||||
moved = false,
|
moved = false,
|
||||||
isMoving = false,
|
isMoving = false,
|
||||||
failed = false,
|
failed = false,
|
||||||
uri = downloadUri,
|
uri = downloadUri,
|
||||||
destinationUri = destinationUri,
|
destinationUri = destinationUri,
|
||||||
finalDestinationUri = finalDestinationUri,
|
finalDestinationUri = finalDestinationUri,
|
||||||
finalDestinationSubfolder = subfolder,
|
finalDestinationSubfolder = subfolder,
|
||||||
downloadId = null,
|
downloadId = null,
|
||||||
progress = 0,
|
lastUpdateTime = null,
|
||||||
bytesDownloaded = 0
|
progress = 0,
|
||||||
|
bytesDownloaded = 0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
val isInternalStorage
|
||||||
|
get() = localFolderId.startsWith("internal-")
|
||||||
|
|
||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val serverUrl get() = uri.toString()
|
val serverUrl
|
||||||
|
get() = uri.toString()
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
fun getDownloadRequest(): DownloadManager.Request {
|
fun getDownloadRequest(): DownloadManager.Request {
|
||||||
|
|||||||
Reference in New Issue
Block a user