Update utils
This commit is contained in:
@@ -415,7 +415,7 @@ internal class ExHentaiParser(
|
||||
joiner.append(lc.toLanguagePath())
|
||||
joiner.append("\"$")
|
||||
}
|
||||
return joiner.complete().takeUnless { it.isEmpty() }
|
||||
return joiner.complete().nullIfEmpty()
|
||||
}
|
||||
|
||||
private fun Collection<ContentType>.toFCats(): Int = fold(0) { acc, ct ->
|
||||
|
||||
@@ -9,14 +9,11 @@ import org.koitharu.kotatsu.parsers.MangaParser
|
||||
import org.koitharu.kotatsu.parsers.MangaSourceParser
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.*
|
||||
import org.koitharu.kotatsu.parsers.util.domain
|
||||
import org.koitharu.kotatsu.parsers.util.generateUid
|
||||
import org.koitharu.kotatsu.parsers.util.getDomain
|
||||
import org.koitharu.kotatsu.parsers.util.*
|
||||
import org.koitharu.kotatsu.parsers.util.json.asTypedList
|
||||
import org.koitharu.kotatsu.parsers.util.json.mapJSON
|
||||
import org.koitharu.kotatsu.parsers.util.json.mapJSONIndexed
|
||||
import org.koitharu.kotatsu.parsers.util.json.mapJSONNotNull
|
||||
import org.koitharu.kotatsu.parsers.util.toAbsoluteUrl
|
||||
import java.util.*
|
||||
|
||||
@Broken
|
||||
@@ -92,7 +89,7 @@ internal class AnibelParser(context: MangaLoaderContext) : MangaParser(context,
|
||||
title = title.getString("be"),
|
||||
coverUrl = jo.getString("poster").removePrefix("/cdn")
|
||||
.toAbsoluteUrl(getDomain("cdn")) + "?width=200&height=280",
|
||||
altTitle = title.optJSONArray("alt")?.optString(0)?.takeUnless(String::isEmpty),
|
||||
altTitle = title.optJSONArray("alt")?.optString(0)?.nullIfEmpty(),
|
||||
author = null,
|
||||
isNsfw = false,
|
||||
rating = jo.getDouble("rating").toFloat() / 10f,
|
||||
@@ -144,7 +141,7 @@ internal class AnibelParser(context: MangaLoaderContext) : MangaParser(context,
|
||||
).getJSONObject("chapters").getJSONArray("docs")
|
||||
return manga.copy(
|
||||
title = title.getString("be"),
|
||||
altTitle = title.optJSONArray("alt")?.optString(0)?.takeUnless(String::isEmpty),
|
||||
altTitle = title.optJSONArray("alt")?.optString(0)?.nullIfEmpty(),
|
||||
coverUrl = "$poster?width=200&height=280",
|
||||
largeCoverUrl = poster,
|
||||
description = details.getJSONObject("description").getString("be"),
|
||||
@@ -239,7 +236,7 @@ internal class AnibelParser(context: MangaLoaderContext) : MangaParser(context,
|
||||
title = title.getString("be"),
|
||||
coverUrl = jo.getString("poster").removePrefix("/cdn")
|
||||
.toAbsoluteUrl(getDomain("cdn")) + "?width=200&height=280",
|
||||
altTitle = title.getString("en").takeUnless(String::isEmpty),
|
||||
altTitle = title.getString("en").nullIfEmpty(),
|
||||
author = null,
|
||||
isNsfw = false,
|
||||
rating = RATING_UNKNOWN,
|
||||
|
||||
@@ -190,7 +190,7 @@ internal class AsuraScansParser(context: MangaLoaderContext) :
|
||||
val data = doc.selectOrThrow("script").mapNotNull { x ->
|
||||
x.data().substringBetween("self.__next_f.push(", ")", "")
|
||||
.trim()
|
||||
.takeUnless { it.isEmpty() }
|
||||
.nullIfEmpty()
|
||||
}.flatMap { it.jsonStrings() }
|
||||
.joinToString("")
|
||||
.split('\n')
|
||||
|
||||
@@ -50,6 +50,7 @@ internal class ComicExtra(context: MangaLoaderContext) : PagedMangaParser(contex
|
||||
append(page.toString())
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
when (order) {
|
||||
SortOrder.POPULARITY -> append("popular-comics")
|
||||
@@ -151,9 +152,9 @@ internal class ComicExtra(context: MangaLoaderContext) : PagedMangaParser(contex
|
||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
||||
val fullUrl = chapter.url.toAbsoluteUrl(domain) + "/full"
|
||||
val doc = webClient.httpGet(fullUrl).parseHtml()
|
||||
|
||||
|
||||
return doc.select("div.chapter-container img").mapNotNull { img ->
|
||||
val url = img.attr("src")?.takeUnless { it.isBlank() }?.toAbsoluteUrl(domain)
|
||||
val url = img.attrAsAbsoluteUrlOrNull("src")
|
||||
url?.let {
|
||||
MangaPage(
|
||||
id = generateUid(url),
|
||||
|
||||
@@ -10,10 +10,7 @@ import org.koitharu.kotatsu.parsers.model.MangaListFilterCapabilities
|
||||
import org.koitharu.kotatsu.parsers.model.MangaParserSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.site.mangareader.MangaReaderParser
|
||||
import org.koitharu.kotatsu.parsers.util.attrAsAbsoluteUrl
|
||||
import org.koitharu.kotatsu.parsers.util.domain
|
||||
import org.koitharu.kotatsu.parsers.util.parseHtml
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
import org.koitharu.kotatsu.parsers.util.*
|
||||
|
||||
@Broken
|
||||
@MangaSourceParser("FREAKCOMIC", "FreakComic", "en")
|
||||
@@ -41,7 +38,7 @@ internal class FreakComic(context: MangaLoaderContext) :
|
||||
key = el.attrAsAbsoluteUrl("href")
|
||||
.toHttpUrlOrNull()
|
||||
?.queryParameter("genre")
|
||||
?.takeUnless { it.isEmpty() }
|
||||
?.nullIfEmpty()
|
||||
?: continue,
|
||||
source = source,
|
||||
)
|
||||
|
||||
@@ -150,7 +150,7 @@ internal class TruyenGG(context: MangaLoaderContext) : PagedMangaParser(context,
|
||||
|
||||
return manga.copy(
|
||||
altTitle = doc.selectFirst("h2.other-name")?.text(),
|
||||
author = doc.select("p:contains(Tác Giả) + p").joinToString { it.text() }.takeUnless { it.isEmpty() },
|
||||
author = doc.select("p:contains(Tác Giả) + p").joinToString { it.text() }.nullIfEmpty(),
|
||||
tags = doc.select("a.clblue").mapToSet {
|
||||
MangaTag(
|
||||
key = it.attr("href").substringAfterLast('-').substringBeforeLast('.'),
|
||||
|
||||
@@ -127,9 +127,9 @@ public fun Element.selectLastOrThrow(cssQuery: String): Element = parseNotNull(s
|
||||
"Cannot find \"$cssQuery\""
|
||||
}
|
||||
|
||||
public fun Element.textOrNull(): String? = text().takeUnless { it.isEmpty() }
|
||||
public fun Element.textOrNull(): String? = text().nullIfEmpty()
|
||||
|
||||
public fun Element.ownTextOrNull(): String? = ownText().takeUnless { it.isEmpty() }
|
||||
public fun Element.ownTextOrNull(): String? = ownText().nullIfEmpty()
|
||||
|
||||
public fun Element.selectFirstParent(query: String): Element? {
|
||||
val selector = QueryParser.parse(query)
|
||||
|
||||
@@ -17,7 +17,7 @@ public suspend fun Call.await(): Response = suspendCancellableCoroutine { contin
|
||||
}
|
||||
|
||||
public val Response.mimeType: String?
|
||||
get() = header("content-type")?.takeUnless { it.isEmpty() }
|
||||
get() = header("content-type")?.nullIfEmpty()
|
||||
|
||||
public val Response.contentDisposition: String?
|
||||
get() = header("Content-Disposition")
|
||||
|
||||
@@ -107,6 +107,8 @@ public fun String.nl2br(): String = replace("\n", "<br>")
|
||||
|
||||
public fun String.splitByWhitespace(): List<String> = trim().split(REGEX_WHITESPACE)
|
||||
|
||||
public fun <T : CharSequence> T.nullIfEmpty(): T? = takeUnless { it.isEmpty() }
|
||||
|
||||
public fun ByteArray.byte2HexFormatted(): String {
|
||||
val str = StringBuilder(size * 2)
|
||||
for (i in indices) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import androidx.collection.ArraySet
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import org.koitharu.kotatsu.parsers.util.nullIfEmpty
|
||||
import java.util.*
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -67,9 +68,7 @@ public fun <T> JSONArray.mapJSONIndexed(block: (Int, JSONObject) -> T): List<T>
|
||||
|
||||
public fun JSONObject.getStringOrNull(name: String): String? = opt(name)?.takeUnless {
|
||||
it === JSONObject.NULL
|
||||
}?.toString()?.takeUnless {
|
||||
it.isEmpty()
|
||||
}
|
||||
}?.toString()?.nullIfEmpty()
|
||||
|
||||
public fun JSONObject.getBooleanOrDefault(name: String, defaultValue: Boolean): Boolean {
|
||||
return when (val rawValue = opt(name)) {
|
||||
|
||||
Reference in New Issue
Block a user