zaimanhua: add ranking filters (#6792)
This commit is contained in:
parent
4647af4f9c
commit
c9a27a8b51
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Zaimanhua'
|
extName = 'Zaimanhua'
|
||||||
extClass = '.Zaimanhua'
|
extClass = '.Zaimanhua'
|
||||||
extVersionCode = 4
|
extVersionCode = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package eu.kanade.tachiyomi.extension.zh.zaimanhua
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
|
||||||
|
open class QueryFilter(name: String, private val key: String, private val params: Array<Pair<String, String>>) :
|
||||||
|
Filter.Select<String>(name, params.map { it.first }.toTypedArray()) {
|
||||||
|
fun addQuery(builder: HttpUrl.Builder) {
|
||||||
|
val param = params[state].second
|
||||||
|
if (param.isNotEmpty()) {
|
||||||
|
builder.addQueryParameter(key, param)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class RankingGroup : Filter.Group<Filter<*>>(
|
||||||
|
"排行榜(搜索文本时无效)",
|
||||||
|
listOf<Filter<*>>(
|
||||||
|
TimeFilter(),
|
||||||
|
SortFilter(),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
private class TimeFilter : QueryFilter(
|
||||||
|
"榜单",
|
||||||
|
"by_time",
|
||||||
|
arrayOf(
|
||||||
|
Pair("日排行", "0"),
|
||||||
|
Pair("周排行", "1"),
|
||||||
|
Pair("月排行", "2"),
|
||||||
|
Pair("总排行", "3"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
private class SortFilter : QueryFilter(
|
||||||
|
"排序",
|
||||||
|
"rank_type",
|
||||||
|
arrayOf(
|
||||||
|
Pair("人气", "0"),
|
||||||
|
Pair("吐槽", "1"),
|
||||||
|
Pair("订阅", "2"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
|
@ -197,8 +197,8 @@ class Zaimanhua : HttpSource(), ConfigurableSource {
|
||||||
|
|
||||||
// Popular
|
// Popular
|
||||||
private fun rankApiUrl(): HttpUrl.Builder =
|
private fun rankApiUrl(): HttpUrl.Builder =
|
||||||
"$apiUrl/comic/rank/list".toHttpUrl().newBuilder().addQueryParameter("by_time", "3")
|
"$apiUrl/comic/rank/list".toHttpUrl().newBuilder()
|
||||||
.addQueryParameter("tag_id", "0").addQueryParameter("rank_type", "0")
|
.addQueryParameter("tag_id", "0")
|
||||||
|
|
||||||
override fun popularMangaRequest(page: Int): Request = GET(
|
override fun popularMangaRequest(page: Int): Request = GET(
|
||||||
rankApiUrl().apply {
|
rankApiUrl().apply {
|
||||||
|
@ -214,16 +214,30 @@ class Zaimanhua : HttpSource(), ConfigurableSource {
|
||||||
"$apiUrl/search/index".toHttpUrl().newBuilder().addQueryParameter("source", "0")
|
"$apiUrl/search/index".toHttpUrl().newBuilder().addQueryParameter("source", "0")
|
||||||
.addQueryParameter("size", "20")
|
.addQueryParameter("size", "20")
|
||||||
|
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = GET(
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
|
val ranking = filters.filterIsInstance<RankingGroup>().firstOrNull()
|
||||||
|
val url = if (query.isEmpty() && ranking != null) {
|
||||||
|
rankApiUrl().apply {
|
||||||
|
ranking.state.filterIsInstance<QueryFilter>().forEach {
|
||||||
|
it.addQuery(this)
|
||||||
|
}
|
||||||
|
addQueryParameter("page", page.toString())
|
||||||
|
}.build()
|
||||||
|
} else {
|
||||||
searchApiUrl().apply {
|
searchApiUrl().apply {
|
||||||
addQueryParameter("keyword", query)
|
addQueryParameter("keyword", query)
|
||||||
addQueryParameter("page", page.toString())
|
addQueryParameter("page", page.toString())
|
||||||
}.build(),
|
}.build()
|
||||||
apiHeaders,
|
}
|
||||||
)
|
return GET(url, apiHeaders)
|
||||||
|
}
|
||||||
|
|
||||||
override fun searchMangaParse(response: Response): MangasPage =
|
override fun searchMangaParse(response: Response): MangasPage =
|
||||||
|
if (response.request.url.toString().startsWith("$apiUrl/comic/rank/list")) {
|
||||||
|
latestUpdatesParse(response)
|
||||||
|
} else {
|
||||||
response.parseAs<ResponseDto<PageDto>>().data.toMangasPage()
|
response.parseAs<ResponseDto<PageDto>>().data.toMangasPage()
|
||||||
|
}
|
||||||
|
|
||||||
// Latest
|
// Latest
|
||||||
// "$apiUrl/comic/update/list/1/$page" is same content
|
// "$apiUrl/comic/update/list/1/$page" is same content
|
||||||
|
@ -231,10 +245,17 @@ class Zaimanhua : HttpSource(), ConfigurableSource {
|
||||||
GET("$apiUrl/comic/update/list/0/$page", apiHeaders)
|
GET("$apiUrl/comic/update/list/0/$page", apiHeaders)
|
||||||
|
|
||||||
override fun latestUpdatesParse(response: Response): MangasPage {
|
override fun latestUpdatesParse(response: Response): MangasPage {
|
||||||
val mangas = response.parseAs<ResponseDto<List<PageItemDto>>>().data
|
val mangas = response.parseAs<ResponseDto<List<PageItemDto>?>>().data
|
||||||
|
if (mangas.isNullOrEmpty()) {
|
||||||
|
throw Exception("没有更多结果了")
|
||||||
|
}
|
||||||
return MangasPage(mangas.map { it.toSManga() }, true)
|
return MangasPage(mangas.map { it.toSManga() }, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getFilterList() = FilterList(
|
||||||
|
RankingGroup(),
|
||||||
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val USE_CACHE = CacheControl.Builder().maxStale(170, TimeUnit.SECONDS).build()
|
val USE_CACHE = CacheControl.Builder().maxStale(170, TimeUnit.SECONDS).build()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue