From 9bfbcfac20572186b316c2abe1add89b18001463 Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Sun, 12 Jan 2025 21:56:09 +0100 Subject: [PATCH 1/7] fix(namicomi): request tags in searchMangaRequest --- .../eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt index 5290e2a9e..845dcba71 100644 --- a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt +++ b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt @@ -127,6 +127,9 @@ abstract class NamiComi(final override val lang: String, private val extLang: St val url = NamiComiConstants.apiSearchUrl.toHttpUrl().newBuilder() .addQueryParameter("ids[]", query.removePrefix(NamiComiConstants.prefixIdSearch)) .addQueryParameter("includes[]", NamiComiConstants.coverArt) + .addQueryParameter("includes[]", NamiComiConstants.primaryTag) + .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) + .addQueryParameter("includes[]", NamiComiConstants.tag) .build() return GET(url, headers, CacheControl.FORCE_NETWORK) @@ -136,6 +139,9 @@ abstract class NamiComi(final override val lang: String, private val extLang: St .addQueryParameter("limit", NamiComiConstants.mangaLimit.toString()) .addQueryParameter("offset", helper.getMangaListOffset(page)) .addQueryParameter("includes[]", NamiComiConstants.coverArt) + .addQueryParameter("includes[]", NamiComiConstants.primaryTag) + .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) + .addQueryParameter("includes[]", NamiComiConstants.tag) val actualQuery = query.replace(NamiComiConstants.whitespaceRegex, " ") if (actualQuery.isNotBlank()) { From 15023589919bd68ebe040f9475c44da1d296aefd Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Sun, 12 Jan 2025 21:56:38 +0100 Subject: [PATCH 2/7] fix(namicomi): request chapter lists & chapter access maps in chunks of 200 entities --- .../extension/all/namicomi/NamiComi.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt index 845dcba71..9ee0503c5 100644 --- a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt +++ b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt @@ -205,7 +205,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St val url = NamiComiConstants.apiChapterUrl.toHttpUrl().newBuilder() .addQueryParameter("titleId", mangaId) .addQueryParameter("includes[]", NamiComiConstants.organization) - .addQueryParameter("limit", "500") + .addQueryParameter("limit", "200") .addQueryParameter("offset", offset.toString()) .addQueryParameter("translatedLanguages[]", extLang) .addQueryParameter("order[volume]", "desc") @@ -244,7 +244,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St var offset = chapterListResponse.meta.offset var hasNextPage = chapterListResponse.meta.hasNextPage - // Max results that can be returned is 500 so need to make more API + // Max results that can be returned is 200 so need to make more API // calls if the chapter list response has a next page. while (hasNextPage) { offset += chapterListResponse.meta.limit @@ -262,10 +262,16 @@ abstract class NamiComi(final override val lang: String, private val extLang: St return emptyList() } - val gatingCheckRequest = accessibleChapterListRequest(chapterListResults.map { it.id }) - val gatingCheckResponse = client.newCall(gatingCheckRequest).execute() - val accessibleChapterMap = gatingCheckResponse.parseAs() - .data?.attributes?.map ?: emptyMap() + // Split chapter access checks into chunks of 200 chapters + val chapterListResultsChunks = chapterListResults.map { it.id }.chunked(200) + val accessibleChapterMap: MutableMap = mutableMapOf() + + for (chapterIds in chapterListResultsChunks) { + val gatingCheckRequest = accessibleChapterListRequest(chapterIds) + val gatingCheckResponse = client.newCall(gatingCheckRequest).execute() + accessibleChapterMap += gatingCheckResponse.parseAs() + .data?.attributes?.map ?: emptyMap() + } return chapterListResults.mapNotNull { val isAccessible = accessibleChapterMap[it.id]!! From fbce1b197e847ad6677df2bffca73f50cbe7f9cd Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Sun, 12 Jan 2025 21:56:55 +0100 Subject: [PATCH 3/7] fix(namicomi): read id directly from URL query parameter instead of using string manipulation --- .../eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt index 9ee0503c5..df98ccd11 100644 --- a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt +++ b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt @@ -235,9 +235,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St return emptyList() } - val mangaId = response.request.url.toString() - .substringBefore("/chapter") - .substringAfter("${NamiComiConstants.apiMangaUrl}/") + val mangaId = response.request.url.queryParameter("titleId")!! val chapterListResponse = response.parseAs() val chapterListResults = chapterListResponse.data.toMutableList() From 3e057cc4e83286621dd6a53206f3881c8cefcd8a Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Sun, 12 Jan 2025 21:57:56 +0100 Subject: [PATCH 4/7] chore(namicomi): bump version code --- src/all/namicomi/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/all/namicomi/build.gradle b/src/all/namicomi/build.gradle index 11a531ba5..308aa7a6e 100644 --- a/src/all/namicomi/build.gradle +++ b/src/all/namicomi/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'NamiComi' extClass = '.NamiComiFactory' - extVersionCode = 1 + extVersionCode = 2 isNsfw = false } From 28d76a87d79ede60f35408429ac02eb9ce31eefc Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Mon, 13 Jan 2025 18:40:53 +0100 Subject: [PATCH 5/7] Fix regression caused by simplification of createManga(...) --- .../extension/all/namicomi/NamiComi.kt | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt index df98ccd11..9c2c2195c 100644 --- a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt +++ b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt @@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import okhttp3.CacheControl +import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody @@ -71,10 +72,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St .addQueryParameter("availableTranslatedLanguages[]", extLang) .addQueryParameter("limit", NamiComiConstants.mangaLimit.toString()) .addQueryParameter("offset", helper.getMangaListOffset(page)) - .addQueryParameter("includes[]", NamiComiConstants.coverArt) - .addQueryParameter("includes[]", NamiComiConstants.primaryTag) - .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) - .addQueryParameter("includes[]", NamiComiConstants.tag) + .addCommonIncludeParameters() .build() return GET(url, headers, CacheControl.FORCE_NETWORK) @@ -126,10 +124,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St // If the query is an ID, return the manga directly val url = NamiComiConstants.apiSearchUrl.toHttpUrl().newBuilder() .addQueryParameter("ids[]", query.removePrefix(NamiComiConstants.prefixIdSearch)) - .addQueryParameter("includes[]", NamiComiConstants.coverArt) - .addQueryParameter("includes[]", NamiComiConstants.primaryTag) - .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) - .addQueryParameter("includes[]", NamiComiConstants.tag) + .addCommonIncludeParameters() .build() return GET(url, headers, CacheControl.FORCE_NETWORK) @@ -138,10 +133,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St val tempUrl = NamiComiConstants.apiSearchUrl.toHttpUrl().newBuilder() .addQueryParameter("limit", NamiComiConstants.mangaLimit.toString()) .addQueryParameter("offset", helper.getMangaListOffset(page)) - .addQueryParameter("includes[]", NamiComiConstants.coverArt) - .addQueryParameter("includes[]", NamiComiConstants.primaryTag) - .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) - .addQueryParameter("includes[]", NamiComiConstants.tag) + .addCommonIncludeParameters() val actualQuery = query.replace(NamiComiConstants.whitespaceRegex, " ") if (actualQuery.isNotBlank()) { @@ -169,11 +161,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St */ override fun mangaDetailsRequest(manga: SManga): Request { val url = (NamiComiConstants.apiMangaUrl + manga.url).toHttpUrl().newBuilder() - .addQueryParameter("includes[]", NamiComiConstants.coverArt) - .addQueryParameter("includes[]", NamiComiConstants.organization) - .addQueryParameter("includes[]", NamiComiConstants.tag) - .addQueryParameter("includes[]", NamiComiConstants.primaryTag) - .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) + .build() return GET(url, headers, CacheControl.FORCE_NETWORK) @@ -349,6 +337,13 @@ abstract class NamiComi(final override val lang: String, private val extLang: St override fun getFilterList(): FilterList = helper.filters.getFilterList(helper.intl) + private fun HttpUrl.Builder.addCommonIncludeParameters() = + this.addQueryParameter("includes[]", NamiComiConstants.coverArt) + .addQueryParameter("includes[]", NamiComiConstants.organization) + .addQueryParameter("includes[]", NamiComiConstants.tag) + .addQueryParameter("includes[]", NamiComiConstants.primaryTag) + .addQueryParameter("includes[]", NamiComiConstants.secondaryTag) + private inline fun Response.parseAs(): T = use { helper.json.decodeFromString(body.string()) } From 494300f5e147ebc563f87bf8266944d8ba3e7885 Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Mon, 13 Jan 2025 18:43:59 +0100 Subject: [PATCH 6/7] Add missing slash --- .../src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt index 9c2c2195c..08899aadc 100644 --- a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt +++ b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt @@ -160,8 +160,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St * Get the API endpoint URL for the entry details. */ override fun mangaDetailsRequest(manga: SManga): Request { - val url = (NamiComiConstants.apiMangaUrl + manga.url).toHttpUrl().newBuilder() - + val url = ("${NamiComiConstants.apiMangaUrl}/${manga.url}").toHttpUrl().newBuilder() .build() return GET(url, headers, CacheControl.FORCE_NETWORK) From 7ea6cc67da2073e8e5c08cb0bef6ec29cb318f47 Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Mon, 13 Jan 2025 18:46:36 +0100 Subject: [PATCH 7/7] Use new extension function to add parameters --- .../src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt index 08899aadc..48d167749 100644 --- a/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt +++ b/src/all/namicomi/src/eu/kanade/tachiyomi/extension/all/namicomi/NamiComi.kt @@ -161,6 +161,7 @@ abstract class NamiComi(final override val lang: String, private val extLang: St */ override fun mangaDetailsRequest(manga: SManga): Request { val url = ("${NamiComiConstants.apiMangaUrl}/${manga.url}").toHttpUrl().newBuilder() + .addCommonIncludeParameters() .build() return GET(url, headers, CacheControl.FORCE_NETWORK)