From 1b37c61b5a21043ab2bdcab3ed7fe83eb42a387c Mon Sep 17 00:00:00 2001 From: Chris Allan Date: Sat, 11 Jan 2020 12:59:43 -0800 Subject: [PATCH] JSON metadata for local manga (#1658) * JSON metadata for local manga * Simplification * Lazy load local data --- .../eu/kanade/tachiyomi/source/LocalSource.kt | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 1630e723d..b02c79ae1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.source import android.content.Context +import com.google.gson.Gson +import com.google.gson.JsonObject import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList @@ -21,6 +23,7 @@ import java.io.File import java.io.FileInputStream import java.io.InputStream import java.util.Locale +import java.util.Scanner import java.util.concurrent.TimeUnit import java.util.zip.ZipEntry import java.util.zip.ZipFile @@ -117,8 +120,6 @@ class LocalSource(private val context: Context) : CatalogueSource { } } } - - initialized = true } } return Observable.just(MangasPage(mangas, false)) @@ -126,7 +127,26 @@ class LocalSource(private val context: Context) : CatalogueSource { override fun fetchLatestUpdates(page: Int) = fetchSearchManga(page, "", LATEST_FILTERS) - override fun fetchMangaDetails(manga: SManga) = Observable.just(manga) + override fun fetchMangaDetails(manga: SManga): Observable { + getBaseDirectories(context) + .mapNotNull { File(it, manga.url).listFiles()?.toList() } + .flatten() + .filter { it.extension.equals("json") } + .firstOrNull() + ?.apply { + val json = Gson().fromJson(Scanner(this).useDelimiter("\\Z").next(), JsonObject::class.java) + manga.title = json["title"]?.asString ?: manga.title + manga.author = json["author"]?.asString ?: manga.author + manga.artist = json["artist"]?.asString ?: manga.artist + manga.description = json["description"]?.asString ?: manga.description + manga.genre = json["genre"]?.asJsonArray + ?.map { it.asString } + ?.joinToString(", ") + ?: manga.genre + manga.status = json["status"]?.asInt ?: manga.status + } + return Observable.just(manga) + } override fun fetchChapterList(manga: SManga): Observable> { val chapters = getBaseDirectories(context)