Always download to internal app storage

This commit is contained in:
Nicholas Wallace
2025-04-11 14:32:49 -07:00
parent e11b8cb66c
commit d25b9a8d73
2 changed files with 20 additions and 23 deletions
@@ -99,17 +99,19 @@ class DownloadItemManager(
/** Processes the download item parts. */ /** Processes the download item parts. */
private fun processDownloadItemParts(nextDownloadItemParts: List<DownloadItemPart>) { private fun processDownloadItemParts(nextDownloadItemParts: List<DownloadItemPart>) {
nextDownloadItemParts.forEach { nextDownloadItemParts.forEach {
if (it.isInternalStorage) { // if (it.isInternalStorage) {
startInternalDownload(it) startInternalDownload(it)
} else { // } else {
startExternalDownload(it) // startExternalDownload(it)
} // }
} }
} }
/** Starts an internal download. */ /** Starts an internal download. */
private fun startInternalDownload(downloadItemPart: DownloadItemPart) { private fun startInternalDownload(downloadItemPart: DownloadItemPart) {
val file = File(downloadItemPart.finalDestinationPath) // Create internal download location at temp directory location
Log.d(tag, "Creating internal download location at ${downloadItemPart.destinationUri.path}")
val file = File(downloadItemPart.destinationUri.path ?: "")
file.parentFile?.mkdirs() file.parentFile?.mkdirs()
val internalProgressCallback = val internalProgressCallback =
@@ -129,11 +131,7 @@ class DownloadItemManager(
tag, tag,
"Start internal download to destination path ${downloadItemPart.finalDestinationPath} from ${downloadItemPart.serverUrl}" "Start internal download to destination path ${downloadItemPart.finalDestinationPath} from ${downloadItemPart.serverUrl}"
) )
InternalDownloadManager( InternalDownloadManager(mainActivity, downloadItemPart.destinationUri, internalProgressCallback)
mainActivity,
downloadItemPart.finalDestinationUri,
internalProgressCallback
)
.download(downloadItemPart.serverUrl) .download(downloadItemPart.serverUrl)
downloadItemPart.downloadId = 1 downloadItemPart.downloadId = 1
currentDownloadItemParts.add(downloadItemPart) currentDownloadItemParts.add(downloadItemPart)
@@ -159,11 +157,11 @@ class DownloadItemManager(
while (currentDownloadItemParts.isNotEmpty()) { while (currentDownloadItemParts.isNotEmpty()) {
val itemParts = currentDownloadItemParts.filter { !it.isMoving } val itemParts = currentDownloadItemParts.filter { !it.isMoving }
for (downloadItemPart in itemParts) { for (downloadItemPart in itemParts) {
if (downloadItemPart.isInternalStorage) { // if (downloadItemPart.isInternalStorage) {
handleInternalDownloadPart(downloadItemPart) handleInternalDownloadPart(downloadItemPart)
} else { // } else {
handleExternalDownloadPart(downloadItemPart) // handleExternalDownloadPart(downloadItemPart)
} // }
} }
delay(500) delay(500)
@@ -2,7 +2,6 @@ package com.audiobookshelf.app.plugins
import android.app.DownloadManager import android.app.DownloadManager
import android.content.Context import android.content.Context
import android.os.Environment
import android.util.Log import android.util.Log
import com.audiobookshelf.app.MainActivity import com.audiobookshelf.app.MainActivity
import com.audiobookshelf.app.data.* import com.audiobookshelf.app.data.*
@@ -108,6 +107,8 @@ class AbsDownloader : Plugin() {
DeviceManager.dbManager.saveLocalFolder(localFolder) DeviceManager.dbManager.saveLocalFolder(localFolder)
} }
val isInternal = localFolderId.startsWith("internal-")
if (localFolder != null) { if (localFolder != null) {
if (episodeId.isNotEmpty() && libraryItem.mediaType != "podcast") { if (episodeId.isNotEmpty() && libraryItem.mediaType != "podcast") {
Log.e(tag, "Library item is not a podcast but episode was requested") Log.e(tag, "Library item is not a podcast but episode was requested")
@@ -119,11 +120,11 @@ class AbsDownloader : Plugin() {
if (episode == null) { if (episode == null) {
call.resolve(JSObject("{\"error\":\"Invalid podcast episode not found\"}")) call.resolve(JSObject("{\"error\":\"Invalid podcast episode not found\"}"))
} else { } else {
startLibraryItemDownload(libraryItem, localFolder, episode) startLibraryItemDownload(libraryItem, isInternal, localFolder, episode)
call.resolve() call.resolve()
} }
} else { } else {
startLibraryItemDownload(libraryItem, localFolder, null) startLibraryItemDownload(libraryItem, isInternal, localFolder, null)
call.resolve() call.resolve()
} }
} else { } else {
@@ -153,14 +154,12 @@ class AbsDownloader : Plugin() {
private fun startLibraryItemDownload( private fun startLibraryItemDownload(
libraryItem: LibraryItem, libraryItem: LibraryItem,
isInternal: Boolean,
localFolder: LocalFolder, localFolder: LocalFolder,
episode: PodcastEpisode? episode: PodcastEpisode?
) { ) {
val isInternal = localFolder.id.startsWith("internal-")
val tempFolderPath = val tempFolderPath = "${mainActivity.filesDir}/downloads/${libraryItem.id}"
if (isInternal) "${mainActivity.filesDir}/downloads/${libraryItem.id}"
else mainActivity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
Log.d(tag, "downloadCacheDirectory=$tempFolderPath") Log.d(tag, "downloadCacheDirectory=$tempFolderPath")