dmzj: add apiv1 search (#8749)
* dmzj: add apiv1 search * dmzj: remove old text search
This commit is contained in:
parent
adbfe86669
commit
d50732286a
@ -1,7 +1,7 @@
|
|||||||
ext {
|
ext {
|
||||||
extName = 'DMZJ'
|
extName = 'DMZJ'
|
||||||
extClass = '.Dmzj'
|
extClass = '.Dmzj'
|
||||||
extVersionCode = 45
|
extVersionCode = 46
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
@ -3,40 +3,62 @@ package eu.kanade.tachiyomi.extension.zh.dmzj
|
|||||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.decodeFromString
|
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
|
||||||
object ApiSearch {
|
object ApiSearch {
|
||||||
|
|
||||||
fun textSearchUrl(query: String) =
|
fun searchUrlV1(page: Int, query: String) =
|
||||||
"http://sacg.idmzj.com/comicsum/search.php".toHttpUrl().newBuilder()
|
"https://manhua.idmzj.com/api/v1/comic2/search".toHttpUrl().newBuilder()
|
||||||
.addQueryParameter("s", query)
|
.addQueryParameter("page", page.toString())
|
||||||
|
.addQueryParameter("size", "30")
|
||||||
|
.addQueryParameter("keyword", query)
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
fun parsePage(response: Response): MangasPage {
|
fun parsePageV1(response: Response): MangasPage {
|
||||||
if (!response.isSuccessful) {
|
if (!response.isSuccessful) {
|
||||||
response.close()
|
response.close()
|
||||||
return MangasPage(emptyList(), false)
|
return MangasPage(emptyList(), false)
|
||||||
}
|
}
|
||||||
// "var g_search_data = [...];"
|
val result = response.parseAs<ResponseDto<SearchResultDto?>>()
|
||||||
val js = response.body.string().run { substring(20, length - 1) }
|
if (result.errmsg.isNotBlank()) {
|
||||||
val data: List<MangaDto> = json.decodeFromString(js)
|
throw Exception(result.errmsg)
|
||||||
return MangasPage(data.map { it.toSManga() }, false)
|
} else {
|
||||||
|
val url = response.request.url
|
||||||
|
val page = url.queryParameter("page")?.toInt()
|
||||||
|
val size = url.queryParameter("size")?.toInt()
|
||||||
|
return if (result.data != null) {
|
||||||
|
MangasPage(result.data.comicList.map { it.toSManga() }, page!! * size!! < result.data.totalNum)
|
||||||
|
} else {
|
||||||
|
MangasPage(emptyList(), false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class MangaDto(
|
class MangaDtoV1(
|
||||||
private val id: Int,
|
private val id: Int,
|
||||||
private val comic_name: String,
|
private val name: String,
|
||||||
private val comic_author: String,
|
private val authors: String,
|
||||||
private val comic_cover: String,
|
private val cover: String,
|
||||||
) {
|
) {
|
||||||
fun toSManga() = SManga.create().apply {
|
fun toSManga() = SManga.create().apply {
|
||||||
url = getMangaUrl(id.toString())
|
url = getMangaUrl(id.toString())
|
||||||
title = comic_name
|
title = name
|
||||||
author = comic_author.formatList()
|
author = authors
|
||||||
thumbnail_url = comic_cover
|
thumbnail_url = cover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class SearchResultDto(
|
||||||
|
val comicList: List<MangaDtoV1>,
|
||||||
|
val totalNum: Int,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class ResponseDto<T>(
|
||||||
|
val errmsg: String = "",
|
||||||
|
val data: T,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -107,11 +107,11 @@ class Dmzj : ConfigurableSource, HttpSource() {
|
|||||||
val id = query.removePrefix(PREFIX_ID_SEARCH).removeSuffix(".html")
|
val id = query.removePrefix(PREFIX_ID_SEARCH).removeSuffix(".html")
|
||||||
Observable.fromCallable { searchMangaById(id) }
|
Observable.fromCallable { searchMangaById(id) }
|
||||||
} else {
|
} else {
|
||||||
val request = GET(ApiSearch.textSearchUrl(query), headers)
|
val request = GET(ApiSearch.searchUrlV1(page, query), headers)
|
||||||
Observable.fromCallable {
|
Observable.fromCallable {
|
||||||
// this API fails randomly, and might return empty list
|
// this API fails randomly, and might return empty list
|
||||||
repeat(5) {
|
repeat(5) {
|
||||||
val result = ApiSearch.parsePage(client.newCall(request).execute())
|
val result = ApiSearch.parsePageV1(client.newCall(request).execute())
|
||||||
if (result.mangas.isNotEmpty()) return@fromCallable result
|
if (result.mangas.isNotEmpty()) return@fromCallable result
|
||||||
}
|
}
|
||||||
throw Exception("搜索出错或无结果")
|
throw Exception("搜索出错或无结果")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user