SpyFakku: Add `Random` Filter (#5411)
This commit is contained in:
parent
458fde8e7f
commit
c56fd24df9
|
@ -1,7 +1,7 @@
|
|||
ext {
|
||||
extName = 'SpyFakku'
|
||||
extClass = '.SpyFakku'
|
||||
extVersionCode = 8
|
||||
extVersionCode = 9
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -32,4 +32,5 @@ private val getSortsList: List<Pair<String, String>> = listOf(
|
|||
Pair("Date Added", "created_at"),
|
||||
Pair("Date Released", "released_at"),
|
||||
Pair("Pages", "pages"),
|
||||
Pair("Random", "random"),
|
||||
)
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.text.SimpleDateFormat
|
|||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.random.Random
|
||||
|
||||
class SpyFakku : HttpSource() {
|
||||
|
||||
|
@ -48,6 +49,8 @@ class SpyFakku : HttpSource() {
|
|||
.rateLimit(2, 1, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
private val charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
|
||||
override fun headersBuilder() = super.headersBuilder()
|
||||
.set("Referer", "$baseUrl/")
|
||||
.set("Origin", baseUrl)
|
||||
|
@ -76,6 +79,7 @@ class SpyFakku : HttpSource() {
|
|||
when (filter) {
|
||||
is SortFilter -> {
|
||||
addQueryParameter("sort", filter.getValue())
|
||||
if (filter.getValue() == "random") addQueryParameter("seed", generateSeed())
|
||||
addQueryParameter("order", if (filter.state!!.ascending) "asc" else "desc")
|
||||
}
|
||||
|
||||
|
@ -298,6 +302,17 @@ class SpyFakku : HttpSource() {
|
|||
return json.decodeFromString(body.string())
|
||||
}
|
||||
|
||||
private fun generateSeed(): String {
|
||||
val length = Random.nextInt(4, 9)
|
||||
val string = StringBuilder(length)
|
||||
|
||||
for (i in 0 until length) {
|
||||
string.append(charset.random())
|
||||
}
|
||||
|
||||
return string.toString()
|
||||
}
|
||||
|
||||
override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException()
|
||||
override fun latestUpdatesRequest(page: Int): Request = throw UnsupportedOperationException()
|
||||
override fun latestUpdatesParse(response: Response) = throw UnsupportedOperationException()
|
||||
|
|
Loading…
Reference in New Issue