Cleanup some delegation

This commit is contained in:
Jobobby04 2021-05-09 18:42:29 -04:00
parent 428a9e82f3
commit 93fe927de2
6 changed files with 14 additions and 12 deletions

View File

@ -56,9 +56,9 @@ class Hitomi(delegate: HttpSource, val context: Context) :
artists = galleryElement.select("h2 a").map { it.text() }
tags += artists.map { RaisedTag("artist", it, RaisedSearchMetadata.TAG_TYPE_VIRTUAL) }
input.select(".gallery-info tr").forEach {
val content = it.child(1)
when (it.child(0).text().toLowerCase()) {
input.select(".gallery-info tr").forEach { galleryInfoElement ->
val content = galleryInfoElement.child(1)
when (galleryInfoElement.child(0).text().toLowerCase()) {
"group" -> {
group = content.text()
tags += RaisedTag("group", group!!, RaisedSearchMetadata.TAG_TYPE_VIRTUAL)
@ -91,9 +91,11 @@ class Hitomi(delegate: HttpSource, val context: Context) :
}
"tags" -> {
tags += content.select("a").map {
val ns = if (it.attr("href").startsWith("/tag/male")) "male"
else if (it.attr("href").startsWith("/tag/female")) "female"
else "misc"
val ns = when {
it.attr("href").startsWith("/tag/male") -> "male"
it.attr("href").startsWith("/tag/female") -> "female"
else -> "misc"
}
RaisedTag(
ns,
it.text().dropLast(if (ns == "misc") 0 else 2),

View File

@ -55,7 +55,7 @@ class NHentai(delegate: HttpSource, val context: Context) :
}
override suspend fun parseIntoMetadata(metadata: NHentaiSearchMetadata, input: Response) {
val json = GALLERY_JSON_REGEX.find(input.body!!.string())!!.groupValues[1].replace(
val json = GALLERY_JSON_REGEX.find(input.body?.string().orEmpty())!!.groupValues[1].replace(
UNICODE_ESCAPE_REGEX
) { it.groupValues[1].toInt(radix = 16).toChar().toString() }
val jsonResponse = jsonParser.decodeFromString<JsonResponse>(json)

View File

@ -125,7 +125,7 @@ class PervEden(delegate: HttpSource, val context: Context) :
}
}
override suspend fun mapUrlToMangaUrl(uri: Uri): String? {
override suspend fun mapUrlToMangaUrl(uri: Uri): String {
val newUri = "http://www.perveden.com/".toUri().buildUpon()
uri.pathSegments.take(3).forEach {
newUri.appendPath(it)

View File

@ -89,7 +89,7 @@ class EightMuses(delegate: HttpSource, val context: Context) :
"8muses.com"
)
override suspend fun mapUrlToMangaUrl(uri: Uri): String? {
override suspend fun mapUrlToMangaUrl(uri: Uri): String {
var path = uri.pathSegments.drop(2)
if (uri.pathSegments[1].toLowerCase() == "picture") {
path = path.dropLast(1)

View File

@ -80,7 +80,7 @@ class HBrowse(delegate: HttpSource, val context: Context) :
)
override suspend fun mapUrlToMangaUrl(uri: Uri): String? {
return "/${uri.pathSegments.first()}/c00001/"
return uri.pathSegments.firstOrNull()?.let { "/$it/c00001/" }
}
override fun getDescriptionAdapter(controller: MangaController): HBrowseDescriptionAdapter {

View File

@ -62,7 +62,7 @@ class Pururin(delegate: HttpSource, val context: Context) :
val parsedSelfLink = selfLink.attr("href").toUri().pathSegments
with(metadata) {
prId = parsedSelfLink[parsedSelfLink.lastIndex - 1].toIntOrNull()
prId = parsedSelfLink[parsedSelfLink.lastIndex - 1].toInt()
prShortLink = parsedSelfLink.last()
val contentWrapper = input.selectFirst(".content-wrapper")
@ -112,7 +112,7 @@ class Pururin(delegate: HttpSource, val context: Context) :
)
override suspend fun mapUrlToMangaUrl(uri: Uri): String {
return "${PururinSearchMetadata.BASE_URL}/gallery/${uri.pathSegments[1]}/${uri.lastPathSegment}"
return "${PururinSearchMetadata.BASE_URL}/gallery/${uri.pathSegments.getOrNull(1)}/${uri.lastPathSegment}"
}
override fun getDescriptionAdapter(controller: MangaController): PururinDescriptionAdapter {