Minor adjustments
This commit is contained in:
parent
849c4d1df4
commit
f48e7419e9
@ -43,7 +43,7 @@ dependencies {
|
||||
//implementation(project(mapOf("path" to ":shared")))
|
||||
|
||||
implementation("no.iktdev:exfl:0.0.13-SNAPSHOT")
|
||||
implementation("no.iktdev.library:subtitle:1.7.7-SNAPSHOT")
|
||||
implementation("no.iktdev.library:subtitle:1.7.8-SNAPSHOT")
|
||||
|
||||
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
|
||||
|
||||
@ -49,14 +49,28 @@ class DownloadAndStoreCoverTask(@Autowired override var coordinator: Coordinator
|
||||
return SimpleMessageData(Status.ERROR, "Check for output directory for cover storage failed for $serviceId")
|
||||
|
||||
val client = DownloadClient(coverData.url, File(coverData.outDir), coverData.outFileBaseName)
|
||||
val result = runBlocking {
|
||||
client.download()
|
||||
|
||||
val outFile = runBlocking {
|
||||
client.getOutFile()
|
||||
}
|
||||
|
||||
var message: String? = null
|
||||
val result = if (outFile?.exists() == true) {
|
||||
message = "${outFile.name} already exists"
|
||||
outFile
|
||||
} else if (outFile != null) {
|
||||
runBlocking {
|
||||
client.download(outFile)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
return if (result == null) {
|
||||
SimpleMessageData(Status.ERROR, "Could not download cover, check logs")
|
||||
} else {
|
||||
val status = if (result.exists() && result.canRead()) Status.COMPLETED else Status.ERROR
|
||||
CoverDownloadWorkPerformed(status = status, coverFile = result.absolutePath)
|
||||
CoverDownloadWorkPerformed(status = status, message = message, coverFile = result.absolutePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -31,15 +31,21 @@ open class DownloadClient(val url: String, val outDir: File, val baseName: Strin
|
||||
return ((read * 100) / total)
|
||||
}
|
||||
|
||||
suspend fun download(): File? = withContext(Dispatchers.IO) {
|
||||
suspend fun getOutFile(): File? = withContext(Dispatchers.IO) {
|
||||
val extension = getExtension()
|
||||
?: throw UnsupportedFormatException("Provided url does not contain a supported file extension")
|
||||
val outFile = outDir.using("$baseName.$extension")
|
||||
if (!outDir.exists())
|
||||
if (!outDir.exists()) {
|
||||
log.error { "Unable to create parent folder for ${outFile.name}. Download skipped!" }
|
||||
return@withContext null
|
||||
}
|
||||
return@withContext outFile
|
||||
}
|
||||
|
||||
suspend fun download(outFile: File): File? = withContext(Dispatchers.IO) {
|
||||
if (outFile.exists()) {
|
||||
log.info { "${outFile.name} already exists. Download skipped!" }
|
||||
return@withContext outFile
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
val inputStream = http.inputStream
|
||||
|
||||
Loading…
Reference in New Issue
Block a user