Fix Grouple external links
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.koitharu.kotatsu.core.parser.site
|
package org.koitharu.kotatsu.core.parser.site
|
||||||
|
|
||||||
import androidx.collection.arraySetOf
|
import androidx.collection.arraySetOf
|
||||||
|
import androidx.core.net.toUri
|
||||||
import org.koitharu.kotatsu.core.exceptions.ParseException
|
import org.koitharu.kotatsu.core.exceptions.ParseException
|
||||||
import org.koitharu.kotatsu.core.model.*
|
import org.koitharu.kotatsu.core.model.*
|
||||||
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
|
||||||
@@ -30,33 +31,39 @@ abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
|
|||||||
val doc = when {
|
val doc = when {
|
||||||
!query.isNullOrEmpty() -> loaderContext.httpPost(
|
!query.isNullOrEmpty() -> loaderContext.httpPost(
|
||||||
"https://$domain/search",
|
"https://$domain/search",
|
||||||
mapOf("q" to query.urlEncoded(), "offset" to offset.toString())
|
mapOf(
|
||||||
|
"q" to query.urlEncoded(),
|
||||||
|
"offset" to offset.upBy(PAGE_SIZE_SEARCH).toString()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
tag == null -> loaderContext.httpGet(
|
tag == null -> loaderContext.httpGet(
|
||||||
"https://$domain/list?sortType=${
|
"https://$domain/list?sortType=${
|
||||||
getSortKey(
|
getSortKey(
|
||||||
sortOrder
|
sortOrder
|
||||||
)
|
)
|
||||||
}&offset=$offset"
|
}&offset=${offset.upBy(PAGE_SIZE)}"
|
||||||
)
|
)
|
||||||
else -> loaderContext.httpGet(
|
else -> loaderContext.httpGet(
|
||||||
"https://$domain/list/genre/${tag.key}?sortType=${
|
"https://$domain/list/genre/${tag.key}?sortType=${
|
||||||
getSortKey(
|
getSortKey(
|
||||||
sortOrder
|
sortOrder
|
||||||
)
|
)
|
||||||
}&offset=$offset"
|
}&offset=${offset.upBy(PAGE_SIZE)}"
|
||||||
)
|
)
|
||||||
}.parseHtml()
|
}.parseHtml()
|
||||||
val root = doc.body().getElementById("mangaBox")
|
val root = doc.body().getElementById("mangaBox")
|
||||||
?.selectFirst("div.tiles.row") ?: throw ParseException("Cannot find root")
|
?.selectFirst("div.tiles.row") ?: throw ParseException("Cannot find root")
|
||||||
|
val baseHost = root.baseUri().toUri().host
|
||||||
return root.select("div.tile").mapNotNull { node ->
|
return root.select("div.tile").mapNotNull { node ->
|
||||||
val imgDiv = node.selectFirst("div.img") ?: return@mapNotNull null
|
val imgDiv = node.selectFirst("div.img") ?: return@mapNotNull null
|
||||||
val descDiv = node.selectFirst("div.desc") ?: return@mapNotNull null
|
val descDiv = node.selectFirst("div.desc") ?: return@mapNotNull null
|
||||||
if (descDiv.selectFirst("i.fa-user") != null) {
|
if (descDiv.selectFirst("i.fa-user") != null) {
|
||||||
return@mapNotNull null //skip author
|
return@mapNotNull null //skip author
|
||||||
}
|
}
|
||||||
val href = imgDiv.selectFirst("a").attr("href")?.withDomain(domain)
|
val href = imgDiv.selectFirst("a").attr("href")?.inContextOf(node)
|
||||||
?: return@mapNotNull null
|
if (href == null || href.toUri().host != baseHost) {
|
||||||
|
return@mapNotNull null // skip external links
|
||||||
|
}
|
||||||
val title = descDiv.selectFirst("h3")?.selectFirst("a")?.text()
|
val title = descDiv.selectFirst("h3")?.selectFirst("a")?.text()
|
||||||
?: return@mapNotNull null
|
?: return@mapNotNull null
|
||||||
val tileInfo = descDiv.selectFirst("div.tile-info")
|
val tileInfo = descDiv.selectFirst("div.tile-info")
|
||||||
@@ -179,4 +186,10 @@ abstract class GroupleRepository(loaderContext: MangaLoaderContext) :
|
|||||||
SortOrder.RATING -> "votes"
|
SortOrder.RATING -> "votes"
|
||||||
null -> "updated"
|
null -> "updated"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
|
||||||
|
private const val PAGE_SIZE = 70
|
||||||
|
private const val PAGE_SIZE_SEARCH = 50
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,14 +4,20 @@ import androidx.collection.ArraySet
|
|||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
fun <T> JSONArray.map(block: (JSONObject) -> T): List<T> {
|
inline fun <R, C : MutableCollection<in R>> JSONArray.mapTo(
|
||||||
|
destination: C,
|
||||||
|
block: (JSONObject) -> R
|
||||||
|
): C {
|
||||||
val len = length()
|
val len = length()
|
||||||
val result = ArrayList<T>(len)
|
|
||||||
for (i in 0 until len) {
|
for (i in 0 until len) {
|
||||||
val jo = getJSONObject(i)
|
val jo = getJSONObject(i)
|
||||||
result.add(block(jo))
|
destination.add(block(jo))
|
||||||
}
|
}
|
||||||
return result
|
return destination
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> JSONArray.map(block: (JSONObject) -> T): List<T> {
|
||||||
|
return mapTo(ArrayList(length()), block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> JSONArray.mapIndexed(block: (Int, JSONObject) -> T): List<T> {
|
fun <T> JSONArray.mapIndexed(block: (Int, JSONObject) -> T): List<T> {
|
||||||
|
|||||||
@@ -31,4 +31,13 @@ fun Float.toIntUp(): Int {
|
|||||||
} else {
|
} else {
|
||||||
intValue + 1
|
intValue + 1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Int.upBy(step: Int): Int {
|
||||||
|
val mod = this % step
|
||||||
|
return if (mod == this) {
|
||||||
|
this
|
||||||
|
} else {
|
||||||
|
this - mod + step
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user