From 6c67e88e5b09dd4b3d78b3308373dab2e809d7d0 Mon Sep 17 00:00:00 2001 From: DokterKaj <54882101+DokterKaj@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:42:01 +0800 Subject: [PATCH] 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 --- src/all/deviantart/build.gradle | 2 +- .../extension/all/deviantart/DeviantArt.kt | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/all/deviantart/build.gradle b/src/all/deviantart/build.gradle index 81534ca6a..464ba363d 100644 --- a/src/all/deviantart/build.gradle +++ b/src/all/deviantart/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'DeviantArt' extClass = '.DeviantArt' - extVersionCode = 2 + extVersionCode = 3 isNsfw = true } diff --git a/src/all/deviantart/src/eu/kanade/tachiyomi/extension/all/deviantart/DeviantArt.kt b/src/all/deviantart/src/eu/kanade/tachiyomi/extension/all/deviantart/DeviantArt.kt index 5c56b1444..ac041baec 100644 --- a/src/all/deviantart/src/eu/kanade/tachiyomi/extension/all/deviantart/DeviantArt.kt +++ b/src/all/deviantart/src/eu/kanade/tachiyomi/extension/all/deviantart/DeviantArt.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup +import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request import okhttp3.Response @@ -24,6 +25,10 @@ class DeviantArt : HttpSource() { override val lang = "all" 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 fun backendBuilder() = backendBaseUrl.toHttpUrl().newBuilder() @@ -48,10 +53,11 @@ class DeviantArt : HttpSource() { } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - require(query.startsWith("gallery:")) { SEARCH_FORMAT_MSG } - val querySegments = query.substringAfter(":").split("/") - val username = querySegments[0] - val folderId = querySegments.getOrElse(1) { "all" } + val matchGroups = requireNotNull( + Regex("""gallery:([\w-]+)(?:/(\d+))?""").matchEntire(query)?.groupValues, + ) { SEARCH_FORMAT_MSG } + val username = matchGroups[1] + val folderId = matchGroups[2].ifEmpty { "all" } return GET("$baseUrl/$username/gallery/$folderId", headers) }