DeviantArt: Always use desktop user agent, only allow valid search queries (#6899)

* Always use desktop user agent, only allow valid search queries

* Re-add trailing comma
This commit is contained in:
DokterKaj 2024-12-30 23:42:01 +08:00 committed by Draff
parent bd0f21c65e
commit 6c67e88e5b
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 11 additions and 5 deletions

View File

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

View File

@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
@ -24,6 +25,10 @@ class DeviantArt : HttpSource() {
override val lang = "all" override val lang = "all"
override val supportsLatest = false override val supportsLatest = false
override fun headersBuilder() = Headers.Builder().apply {
add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0")
}
private val backendBaseUrl = "https://backend.deviantart.com" private val backendBaseUrl = "https://backend.deviantart.com"
private fun backendBuilder() = backendBaseUrl.toHttpUrl().newBuilder() private fun backendBuilder() = backendBaseUrl.toHttpUrl().newBuilder()
@ -48,10 +53,11 @@ class DeviantArt : HttpSource() {
} }
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
require(query.startsWith("gallery:")) { SEARCH_FORMAT_MSG } val matchGroups = requireNotNull(
val querySegments = query.substringAfter(":").split("/") Regex("""gallery:([\w-]+)(?:/(\d+))?""").matchEntire(query)?.groupValues,
val username = querySegments[0] ) { SEARCH_FORMAT_MSG }
val folderId = querySegments.getOrElse(1) { "all" } val username = matchGroups[1]
val folderId = matchGroups[2].ifEmpty { "all" }
return GET("$baseUrl/$username/gallery/$folderId", headers) return GET("$baseUrl/$username/gallery/$folderId", headers)
} }