Danbooru: Fix crash and titles (#2954)

Fix crash
This commit is contained in:
bapeey 2024-05-10 22:45:26 -05:00 committed by Draff
parent 307540a2aa
commit 6ed5e31f37
2 changed files with 35 additions and 37 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Danbooru' extName = 'Danbooru'
extClass = '.Danbooru' extClass = '.Danbooru'
extVersionCode = 1 extVersionCode = 2
isNsfw = true isNsfw = true
} }

View File

@ -47,54 +47,52 @@ class Danbooru : ParsedHttpSource() {
override fun popularMangaSelector(): String = override fun popularMangaSelector(): String =
searchMangaSelector() searchMangaSelector()
override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = Request( override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
url = "$baseUrl/pools/gallery".toHttpUrl().newBuilder().run { val url = "$baseUrl/pools/gallery".toHttpUrl().newBuilder()
setEncodedQueryParameter("search[category]", "series")
url.setEncodedQueryParameter("search[category]", "series")
filters.forEach { filters.forEach {
when (it) { when (it) {
is FilterTags -> if (it.state.isNotBlank()) { is FilterTags -> if (it.state.isNotBlank()) {
addQueryParameter("search[post_tags_match]", it.state) url.addQueryParameter("search[post_tags_match]", it.state)
} }
is FilterDescription -> if (it.state.isNotBlank()) { is FilterDescription -> if (it.state.isNotBlank()) {
addQueryParameter("search[description_matches]", it.state) url.addQueryParameter("search[description_matches]", it.state)
} }
is FilterIsDeleted -> if (it.state) { is FilterIsDeleted -> if (it.state) {
addEncodedQueryParameter("search[is_deleted]", "true") url.addEncodedQueryParameter("search[is_deleted]", "true")
} }
is FilterCategory -> { is FilterCategory -> {
setEncodedQueryParameter("search[category]", it.selected) url.setEncodedQueryParameter("search[category]", it.selected)
} }
is FilterOrder -> if (it.selected != null) { is FilterOrder -> if (it.selected != null) {
addEncodedQueryParameter("search[order]", it.selected) url.addEncodedQueryParameter("search[order]", it.selected)
} }
else -> throw IllegalStateException("Unrecognized filter") else -> throw IllegalStateException("Unrecognized filter")
} }
} }
addEncodedQueryParameter("page", page.toString()) url.addEncodedQueryParameter("page", page.toString())
if (query.isNotBlank()) { if (query.isNotBlank()) {
addQueryParameter("search[name_contains]", query) url.addQueryParameter("search[name_contains]", query)
} }
build() return GET(url.build(), headers)
}, }
headers = headers,
)
override fun searchMangaSelector(): String = override fun searchMangaSelector(): String =
".post-preview" "article.post-preview"
override fun searchMangaFromElement(element: Element) = SManga.create().apply { override fun searchMangaFromElement(element: Element) = SManga.create().apply {
url = element.selectFirst(".post-preview-link")?.attr("href")!! url = element.selectFirst(".post-preview-link")?.attr("href")!!
title = element.selectFirst(".desc")?.text() ?: "" title = element.selectFirst("div.text-center")?.text() ?: ""
thumbnail_url = element.selectFirst("source")?.attr("srcset") thumbnail_url = element.selectFirst("source")?.attr("srcset")
?.substringAfterLast(',')?.trim() ?.substringAfterLast(',')?.trim()