From 34cf6a50b9b3ac4a13783e45ad7fbaefd6d9f046 Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Mon, 3 Oct 2022 19:48:48 +0800 Subject: [PATCH] Kemono: fix image loading (#13692) --- .../kanade/tachiyomi/multisrc/kemono/Kemono.kt | 16 +++++++++------- .../tachiyomi/multisrc/kemono/KemonoDto.kt | 14 ++++++++------ .../tachiyomi/multisrc/kemono/KemonoGenerator.kt | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt index 5b03d40b7..9b5555abe 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt @@ -20,7 +20,6 @@ import okhttp3.Response import org.jsoup.nodes.Element import org.jsoup.select.Evaluator import rx.Observable -import rx.Single import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy @@ -35,6 +34,9 @@ open class Kemono( override val client = network.client.newBuilder().rateLimit(2).build() + override fun headersBuilder() = super.headersBuilder() + .add("Referer", "$baseUrl/") + private val json: Json by injectLazy() private val preferences by lazy { @@ -69,7 +71,7 @@ open class Kemono( override fun latestUpdatesParse(response: Response) = popularMangaParse(response) - override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable = Single.create { subscriber -> + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable = Observable.fromCallable { val baseUrl = this.baseUrl val response = client.newCall(GET("$baseUrl/api/creators", headers)).execute() val result = response.parseAs>() @@ -77,8 +79,8 @@ open class Kemono( .sortedByDescending { it.updatedDate } .map { it.toSManga(baseUrl) } .filterUnsupported() - subscriber.onSuccess(MangasPage(result, false)) - }.toObservable() + MangasPage(result, false) + } override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = throw UnsupportedOperationException("Not used.") override fun searchMangaParse(response: Response) = throw UnsupportedOperationException("Not used.") @@ -87,7 +89,7 @@ open class Kemono( override fun mangaDetailsParse(response: Response) = throw UnsupportedOperationException("Not used.") - override fun fetchChapterList(manga: SManga): Observable> = Single.create> { + override fun fetchChapterList(manga: SManga): Observable> = Observable.fromCallable { KemonoPostDto.dateFormat.timeZone = when (manga.author) { "Pixiv Fanbox", "Fantia" -> TimeZone.getTimeZone("GMT+09:00") else -> TimeZone.getTimeZone("GMT") @@ -104,8 +106,8 @@ open class Kemono( offset += POST_PAGE_SIZE hasNextPage = page.size == POST_PAGE_SIZE } - it.onSuccess(result) - }.toObservable() + result + } override fun chapterListParse(response: Response) = throw UnsupportedOperationException("Not used.") diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoDto.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoDto.kt index 15fd92074..d7ed5622e 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoDto.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoDto.kt @@ -56,14 +56,14 @@ class KemonoPostDto( ) { val images: List get() = buildList(attachments.size + 1) { - file.path?.let { add(it) } - attachments.mapTo(this) { it.path } + if (file.path != null) add(KemonoAttachmentDto(file.name!!, file.path)) + addAll(attachments) }.filter { - when (it.substringAfterLast('.').lowercase()) { + when (it.name.substringAfterLast('.').lowercase()) { "png", "jpg", "gif", "jpeg", "webp" -> true else -> false } - }.distinct() + }.distinctBy { it.path }.map { it.toString() } fun toSChapter() = SChapter.create().apply { url = "/$service/user/$user/post/$id" @@ -78,10 +78,12 @@ class KemonoPostDto( } @Serializable -class KemonoFileDto(val path: String? = null) +class KemonoFileDto(val name: String? = null, val path: String? = null) @Serializable -class KemonoAttachmentDto(val path: String) +class KemonoAttachmentDto(val name: String, val path: String) { + override fun toString() = "$path?f=$name" +} private fun getApiDateFormat() = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt index 9d9fc7d35..24509c546 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt @@ -6,7 +6,7 @@ import generator.ThemeSourceGenerator class KemonoGenerator : ThemeSourceGenerator { override val themeClass = "Kemono" override val themePkg = "kemono" - override val baseVersionCode = 2 + override val baseVersionCode = 3 override val sources = listOf( SingleLang("Kemono", "https://kemono.party", "all", isNsfw = true), SingleLang("Coomer", "https://coomer.party", "all", isNsfw = true)