From 5a4f9d8914020190c1d1e42f2750bc1970d666a8 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 16 Nov 2024 16:42:31 +0200 Subject: [PATCH] [MangaFire] Fix search --- .../koitharu/kotatsu/parsers/site/all/HitomiLaParser.kt | 2 +- .../koitharu/kotatsu/parsers/site/all/MangaFireParser.kt | 8 +++++++- .../kotlin/org/koitharu/kotatsu/parsers/util/String.kt | 2 +- .../org/koitharu/kotatsu/parsers/InMemoryCookieJar.kt | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/HitomiLaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/HitomiLaParser.kt index 94ba7cdc..9568916b 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/HitomiLaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/HitomiLaParser.kt @@ -172,7 +172,7 @@ internal class HitomiLaParser(context: MangaLoaderContext) : MangaParser(context .trim() .replace(Regex("""^\?"""), "") .lowercase() - .split(Regex("\\s+")) + .splitByWhitespace() .map { it.replace('_', ' ') } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt index 8d423bd6..1fb32323 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt @@ -38,6 +38,7 @@ internal abstract class MangaFireParser( SortOrder.RATING, SortOrder.NEWEST, SortOrder.ALPHABETICAL, + SortOrder.RELEVANCE, ) override fun onCreateConfig(keys: MutableCollection>) { @@ -91,7 +92,10 @@ internal abstract class MangaFireParser( when { !filter.query.isNullOrEmpty() -> { - addQueryParameter("keyword", filter.query.space2plus()) + val encodedQuery = filter.query.splitByWhitespace().joinToString(separator = "+") { part -> + part.urlEncoded() + } + addEncodedQueryParameter("keyword", encodedQuery) addQueryParameter( name = "sort", value = when (order) { @@ -100,6 +104,7 @@ internal abstract class MangaFireParser( SortOrder.RATING -> "scores" SortOrder.NEWEST -> "release_date" SortOrder.ALPHABETICAL -> "title_az" + SortOrder.RELEVANCE -> "most_relevance" else -> "" }, ) @@ -135,6 +140,7 @@ internal abstract class MangaFireParser( SortOrder.RATING -> "scores" SortOrder.NEWEST -> "release_date" SortOrder.ALPHABETICAL -> "title_az" + SortOrder.RELEVANCE -> "most_relevance" else -> "" }, ) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/String.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/String.kt index b246689f..96736632 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/String.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/String.kt @@ -105,7 +105,7 @@ public fun String.urlDecode(): String = URLDecoder.decode(this, Charsets.UTF_8.n public fun String.nl2br(): String = replace("\n", "
") -public fun String.space2plus(): String = trim().replace(REGEX_WHITESPACE, "+") +public fun String.splitByWhitespace(): List = trim().split(REGEX_WHITESPACE) public fun ByteArray.byte2HexFormatted(): String { val str = StringBuilder(size * 2) diff --git a/src/test/kotlin/org/koitharu/kotatsu/parsers/InMemoryCookieJar.kt b/src/test/kotlin/org/koitharu/kotatsu/parsers/InMemoryCookieJar.kt index c88efb9f..1fad9c6c 100644 --- a/src/test/kotlin/org/koitharu/kotatsu/parsers/InMemoryCookieJar.kt +++ b/src/test/kotlin/org/koitharu/kotatsu/parsers/InMemoryCookieJar.kt @@ -4,6 +4,7 @@ import okhttp3.Cookie import okhttp3.CookieJar import okhttp3.HttpUrl import org.koitharu.kotatsu.parsers.util.insertCookie +import org.koitharu.kotatsu.parsers.util.splitByWhitespace import org.koitharu.kotatsu.test_util.component6 import org.koitharu.kotatsu.test_util.component7 import java.io.InputStream @@ -32,7 +33,7 @@ class InMemoryCookieJar : CookieJar { if (line.isBlank() || line.startsWith("# ")) { continue } - val (host, _, path, secure, expire, name, value) = line.split(Regex("\\s+")) + val (host, _, path, secure, expire, name, value) = line.splitByWhitespace() val domain = host.removePrefix("#HttpOnly_").trimStart('.') val httpOnly = host.startsWith("#HttpOnly_") val cookie = Cookie.Builder() @@ -51,4 +52,4 @@ class InMemoryCookieJar : CookieJar { val host: String, val name: String, ) -} \ No newline at end of file +}