Update Downloader.kt
added a function that creates a local source readable details.json file on chapter download.
This commit is contained in:
parent
1f9f9662bc
commit
b5bb76eb7e
@ -1,6 +1,7 @@
|
|||||||
package eu.kanade.tachiyomi.data.download
|
package eu.kanade.tachiyomi.data.download
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import com.jakewharton.rxrelay.BehaviorRelay
|
import com.jakewharton.rxrelay.BehaviorRelay
|
||||||
import com.jakewharton.rxrelay.PublishRelay
|
import com.jakewharton.rxrelay.PublishRelay
|
||||||
@ -28,6 +29,9 @@ import eu.kanade.tachiyomi.util.storage.saveTo
|
|||||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||||
import eu.kanade.tachiyomi.util.system.logcat
|
import eu.kanade.tachiyomi.util.system.logcat
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
@ -37,6 +41,7 @@ import rx.subscriptions.CompositeSubscription
|
|||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.OutputStream
|
||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
@ -500,6 +505,55 @@ class Downloader(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data type for details.json
|
||||||
|
*/
|
||||||
|
@Serializable
|
||||||
|
data class Details(
|
||||||
|
val title: String?,
|
||||||
|
val author: String?,
|
||||||
|
val artist: String?,
|
||||||
|
val genre: List<String>? = emptyList(),
|
||||||
|
val description: String?,
|
||||||
|
val status: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates the details.json file containing manga information for local source
|
||||||
|
*
|
||||||
|
* @param mangaDir the manga directory of the download.
|
||||||
|
* @param manga the manga of the chapters to download.
|
||||||
|
*/
|
||||||
|
private fun createDetails(mangaDir: UniFile, manga: Manga) {
|
||||||
|
try {
|
||||||
|
val detailsData = Details(
|
||||||
|
manga.title,
|
||||||
|
manga.author,
|
||||||
|
manga.artist,
|
||||||
|
manga.genre,
|
||||||
|
manga.description,
|
||||||
|
manga.status.toString(),
|
||||||
|
)
|
||||||
|
|
||||||
|
val fileName = "details.json"
|
||||||
|
var path = mangaDir.filePath
|
||||||
|
path = "$path/$fileName"
|
||||||
|
val file = File(path)
|
||||||
|
val uri = Uri.fromFile(file)
|
||||||
|
|
||||||
|
val json: Json by injectLazy()
|
||||||
|
|
||||||
|
val outputStream: OutputStream? = uri?.let {
|
||||||
|
context.contentResolver?.openOutputStream(
|
||||||
|
it,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
outputStream?.write(json.encodeToString(detailsData).toByteArray())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR, e) { "Error creating details.json for ${manga.title}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the download was successful.
|
* Checks if the download was successful.
|
||||||
*
|
*
|
||||||
@ -528,6 +582,10 @@ class Downloader(
|
|||||||
|
|
||||||
DiskUtil.createNoMediaFile(tmpDir, context)
|
DiskUtil.createNoMediaFile(tmpDir, context)
|
||||||
|
|
||||||
|
// creates details.json file for local source
|
||||||
|
if (preferences.createDetails().get()) {
|
||||||
|
createDetails(mangaDir, download.manga)
|
||||||
|
}
|
||||||
Download.State.DOWNLOADED
|
Download.State.DOWNLOADED
|
||||||
} else {
|
} else {
|
||||||
Download.State.ERROR
|
Download.State.ERROR
|
||||||
|
Loading…
x
Reference in New Issue
Block a user