From 9f21ec0d06f091e3b089981135324564db881a7f Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:45:33 +0500 Subject: [PATCH] fix Hitomi method conflict with ext-lib 1.5 methods (#806) * maybe fix private fun conflict with ext-lib 1.5 interface methods * add pages in description * slight refactor * bump * make search default order same as site some entries don't show up on popular sort --- src/all/hitomi/build.gradle | 2 +- .../tachiyomi/extension/all/hitomi/Hitomi.kt | 85 +++++++++---------- 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/src/all/hitomi/build.gradle b/src/all/hitomi/build.gradle index c32dfc2a7..c23da94e2 100644 --- a/src/all/hitomi/build.gradle +++ b/src/all/hitomi/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Hitomi' extClass = '.HitomiFactory' - extVersionCode = 25 + extVersionCode = 26 isNsfw = true } diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt index 27c4a26d9..26f2d0def 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt @@ -56,50 +56,44 @@ class Hitomi( .set("origin", baseUrl) override fun fetchPopularManga(page: Int): Observable = Observable.fromCallable { - runBlocking { getPopularManga(page) } - } + runBlocking { + val entries = getGalleryIDsFromNozomi("popular", "today", nozomiLang, page.nextPageRange()) + .toMangaList() - private suspend fun getPopularManga(page: Int): MangasPage { - val entries = getGalleryIDsFromNozomi("popular", "today", nozomiLang, page.nextPageRange()) - .toMangaList() - - return MangasPage(entries, entries.size >= 24) + MangasPage(entries, entries.size >= 24) + } } override fun fetchLatestUpdates(page: Int): Observable = Observable.fromCallable { - runBlocking { getLatestUpdates(page) } - } + runBlocking { + val entries = getGalleryIDsFromNozomi(null, "index", nozomiLang, page.nextPageRange()) + .toMangaList() - private suspend fun getLatestUpdates(page: Int): MangasPage { - val entries = getGalleryIDsFromNozomi(null, "index", nozomiLang, page.nextPageRange()) - .toMangaList() - - return MangasPage(entries, entries.size >= 24) + MangasPage(entries, entries.size >= 24) + } } private lateinit var searchResponse: List override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable = Observable.fromCallable { - runBlocking { getSearchManga(page, query, filters) } - } + runBlocking { + if (page == 1) { + searchResponse = hitomiSearch( + query.trim(), + filters.filterIsInstance().firstOrNull()?.state == 1, + nozomiLang, + ).toList() + } - private suspend fun getSearchManga(page: Int, query: String, filters: FilterList): MangasPage { - if (page == 1) { - searchResponse = hitomiSearch( - query.trim(), - filters.filterIsInstance().firstOrNull()?.state == 0, - nozomiLang, - ).toList() + val end = min(page * 25, searchResponse.size) + val entries = searchResponse.subList((page - 1) * 25, end) + .toMangaList() + + MangasPage(entries, end != searchResponse.size) } - - val end = min(page * 25, searchResponse.size) - val entries = searchResponse.subList((page - 1) * 25, end) - .toMangaList() - - return MangasPage(entries, end != searchResponse.size) } - private class SortFilter : Filter.Select("Sort By", arrayOf("Popularity", "Updated")) + private class SortFilter : Filter.Select("Sort By", arrayOf("Updated", "Popularity")) override fun getFilterList(): FilterList { return FilterList(SortFilter()) @@ -450,6 +444,7 @@ class Hitomi( parodys?.joinToString { it.formatted }?.let { append("Parodies: ", it, "\n") } + append("Pages: ", files.size) } status = SManga.COMPLETED update_strategy = UpdateStrategy.ONLY_FETCH_ONCE @@ -464,10 +459,8 @@ class Hitomi( return GET("$ltnUrl/galleries/$id.js", headers) } - override fun mangaDetailsParse(response: Response): SManga { - return response.parseScriptAs().let { - runBlocking { it.toSManga() } - } + override fun mangaDetailsParse(response: Response) = runBlocking { + response.parseScriptAs().toSManga() } override fun getMangaUrl(manga: SManga) = baseUrl + manga.url @@ -508,22 +501,20 @@ class Hitomi( return GET("$ltnUrl/galleries/$id.js", headers) } - override fun pageListParse(response: Response): List { + override fun pageListParse(response: Response) = runBlocking { val gallery = response.parseScriptAs() - return gallery.files.mapIndexed { idx, img -> - runBlocking { - val hash = img.hash - val commonId = commonImageId() - val imageId = imageIdFromHash(hash) - val subDomain = 'a' + subdomainOffset(imageId) + gallery.files.mapIndexed { idx, img -> + val hash = img.hash + val commonId = commonImageId() + val imageId = imageIdFromHash(hash) + val subDomain = 'a' + subdomainOffset(imageId) - Page( - idx, - "$baseUrl/reader/$id.html", - "https://${subDomain}a.$domain/webp/$commonId$imageId/$hash.webp", - ) - } + Page( + idx, + "$baseUrl/reader/$id.html", + "https://${subDomain}a.$domain/webp/$commonId$imageId/$hash.webp", + ) } }