mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 07:07:22 +02:00
Combine cover download logic
This commit is contained in:
@@ -298,55 +298,6 @@ class AbsDownloader : Plugin() {
|
|||||||
)
|
)
|
||||||
downloadItem.downloadItemParts.add(downloadItemPart)
|
downloadItem.downloadItemParts.add(downloadItemPart)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadItem.downloadItemParts.isNotEmpty()) {
|
|
||||||
// Add cover download item
|
|
||||||
if (libraryItem.media.coverPath != null && libraryItem.media.coverPath?.isNotEmpty() == true
|
|
||||||
) {
|
|
||||||
val coverLibraryFile =
|
|
||||||
libraryItem.libraryFiles?.find { it.metadata.path == libraryItem.media.coverPath }
|
|
||||||
val coverFileSize = coverLibraryFile?.metadata?.size ?: 0
|
|
||||||
|
|
||||||
val serverPath = "/api/items/${libraryItem.id}/cover"
|
|
||||||
val destinationFilename = "cover-${libraryItem.id}.jpg"
|
|
||||||
val destinationFile = File("$tempFolderPath/$destinationFilename")
|
|
||||||
val finalDestinationFile = File("$itemFolderPath/$destinationFilename")
|
|
||||||
|
|
||||||
if (destinationFile.exists()) {
|
|
||||||
Log.d(
|
|
||||||
tag,
|
|
||||||
"TEMP Audio file already exists, removing it from ${destinationFile.absolutePath}"
|
|
||||||
)
|
|
||||||
destinationFile.delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finalDestinationFile.exists()) {
|
|
||||||
Log.d(
|
|
||||||
tag,
|
|
||||||
"Cover already exists, removing it from ${finalDestinationFile.absolutePath}"
|
|
||||||
)
|
|
||||||
finalDestinationFile.delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
val downloadItemPart =
|
|
||||||
DownloadItemPart.make(
|
|
||||||
downloadItem.id,
|
|
||||||
destinationFilename,
|
|
||||||
coverFileSize,
|
|
||||||
destinationFile,
|
|
||||||
finalDestinationFile,
|
|
||||||
itemSubfolder,
|
|
||||||
serverPath,
|
|
||||||
localFolder,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
downloadItem.downloadItemParts.add(downloadItemPart)
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadItemManager.addDownloadItem(downloadItem)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Podcast episode download
|
// Podcast episode download
|
||||||
val audioTrack = episode?.audioTrack
|
val audioTrack = episode?.audioTrack
|
||||||
@@ -387,40 +338,53 @@ class AbsDownloader : Plugin() {
|
|||||||
episode
|
episode
|
||||||
)
|
)
|
||||||
downloadItem.downloadItemParts.add(downloadItemPart)
|
downloadItem.downloadItemParts.add(downloadItemPart)
|
||||||
|
}
|
||||||
|
|
||||||
if (libraryItem.media.coverPath != null && libraryItem.media.coverPath?.isNotEmpty() == true
|
// Download cover image if it is not already downloaded
|
||||||
) {
|
if (libraryItem.media.coverPath != null && libraryItem.media.coverPath?.isNotEmpty() == true) {
|
||||||
val coverLibraryFile =
|
val coverLibraryFile =
|
||||||
libraryItem.libraryFiles?.find { it.metadata.path == libraryItem.media.coverPath }
|
libraryItem.libraryFiles?.find { it.metadata.path == libraryItem.media.coverPath }
|
||||||
val coverFileSize = coverLibraryFile?.metadata?.size ?: 0
|
val coverFileSize = coverLibraryFile?.metadata?.size ?: 0
|
||||||
|
|
||||||
serverPath = "/api/items/${libraryItem.id}/cover"
|
var serverPath = "/api/items/${libraryItem.id}/cover"
|
||||||
destinationFilename = "cover.jpg"
|
var destinationFilename = "cover-${libraryItem.id}.jpg"
|
||||||
|
var destinationFile = File("$tempFolderPath/$destinationFilename")
|
||||||
destinationFile = File("$tempFolderPath/$destinationFilename")
|
var finalDestinationFile = File("$itemFolderPath/$destinationFilename")
|
||||||
finalDestinationFile = File("$itemFolderPath/$destinationFilename")
|
|
||||||
|
|
||||||
|
// If a book, replace the cover image if it already exists
|
||||||
|
if (libraryItem.mediaType == "book") {
|
||||||
|
if (destinationFile.exists()) {
|
||||||
|
Log.d(tag, "TEMP cover already exists, removing it from ${destinationFile.absolutePath}")
|
||||||
|
destinationFile.delete()
|
||||||
|
}
|
||||||
if (finalDestinationFile.exists()) {
|
if (finalDestinationFile.exists()) {
|
||||||
Log.d(tag, "Podcast cover already exists - not downloading cover again")
|
Log.d(tag, "Cover already exists, removing it from ${finalDestinationFile.absolutePath}")
|
||||||
} else {
|
finalDestinationFile.delete()
|
||||||
downloadItemPart =
|
|
||||||
DownloadItemPart.make(
|
|
||||||
downloadItem.id,
|
|
||||||
destinationFilename,
|
|
||||||
coverFileSize,
|
|
||||||
destinationFile,
|
|
||||||
finalDestinationFile,
|
|
||||||
title,
|
|
||||||
serverPath,
|
|
||||||
localFolder,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
downloadItem.downloadItemParts.add(downloadItemPart)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (finalDestinationFile.exists()) {
|
||||||
|
Log.d(tag, "Podcast cover already exists - not downloading cover again")
|
||||||
|
} else {
|
||||||
|
val downloadItemPart =
|
||||||
|
DownloadItemPart.make(
|
||||||
|
downloadItem.id,
|
||||||
|
destinationFilename,
|
||||||
|
coverFileSize,
|
||||||
|
destinationFile,
|
||||||
|
finalDestinationFile,
|
||||||
|
itemSubfolder,
|
||||||
|
serverPath,
|
||||||
|
localFolder,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
downloadItem.downloadItemParts.add(downloadItemPart)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add to download manager if there are files to download
|
||||||
|
if (downloadItem.downloadItemParts.isNotEmpty()) {
|
||||||
downloadItemManager.addDownloadItem(downloadItem)
|
downloadItemManager.addDownloadItem(downloadItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user