From fcc13a63edaff4ff408088afc174b38e09c94a1b Mon Sep 17 00:00:00 2001 From: DokterKaj <54882101+DokterKaj@users.noreply.github.com> Date: Sat, 14 Jun 2025 16:49:22 +0800 Subject: [PATCH] DeviantArt: Preserve token in multi-image posts (#9151) * DeviantArt: Preserve token in multi-image posts * DeviantArt: Use keiyoushi.utils.tryParse * DeviantArt: Make when block nicer * DeviantArt: No need for two variables * DeviantArt: Only find firstImageUrl if needed * DeviantArt: Use if expression for less indenting --- src/all/deviantart/build.gradle | 2 +- .../extension/all/deviantart/DeviantArt.kt | 35 ++++++++----------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/all/deviantart/build.gradle b/src/all/deviantart/build.gradle index b580099a4..fad191014 100644 --- a/src/all/deviantart/build.gradle +++ b/src/all/deviantart/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'DeviantArt' extClass = '.DeviantArt' - extVersionCode = 8 + extVersionCode = 9 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 bd760f5f5..164c2e307 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 @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.asJsoup import keiyoushi.utils.getPreferencesLazy +import keiyoushi.utils.tryParse import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request @@ -20,7 +21,6 @@ import okhttp3.Response import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.parser.Parser -import java.text.ParseException import java.text.SimpleDateFormat import java.util.Locale @@ -43,14 +43,6 @@ class DeviantArt : HttpSource(), ConfigurableSource { SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH) } - private fun parseDate(dateStr: String?): Long { - return try { - dateFormat.parse(dateStr ?: "")!!.time - } catch (_: ParseException) { - 0L - } - } - override fun popularMangaRequest(page: Int): Request { throw UnsupportedOperationException(SEARCH_FORMAT_MSG) } @@ -94,9 +86,9 @@ class DeviantArt : HttpSource(), ConfigurableSource { return SManga.create().apply { setUrlWithoutDomain(response.request.url.toString()) author = document.title().substringBefore(" ") - title = when (artistInTitle) { - true -> "$author - $galleryName" - false -> galleryName + title = when { + artistInTitle -> "$author - $galleryName" + else -> galleryName } description = gallery?.selectFirst(".legacy-journal")?.wholeText() thumbnail_url = gallery?.selectFirst("img[property=contentUrl]")?.absUrl("src") @@ -142,7 +134,7 @@ class DeviantArt : HttpSource(), ConfigurableSource { SChapter.create().apply { setUrlWithoutDomain(it.selectFirst("link")!!.text()) name = it.selectFirst("title")!!.text() - date_upload = parseDate(it.selectFirst("pubDate")?.text()) + date_upload = dateFormat.tryParse(it.selectFirst("pubDate")?.text()) scanlator = it.selectFirst("media|credit")?.text() } } @@ -162,16 +154,17 @@ class DeviantArt : HttpSource(), ConfigurableSource { override fun pageListParse(response: Response): List { val document = response.asJsoup() - val firstImageUrl = document.selectFirst("img[fetchpriority=high]")?.absUrl("src") - return when (val buttons = document.selectFirst("[draggable=false]")?.children()) { - null -> listOf(Page(0, imageUrl = firstImageUrl)) - else -> buttons.mapIndexed { i, button -> + val buttons = document.selectFirst("[draggable=false]")?.children() + return if (buttons == null) { + val imageUrl = document.selectFirst("img[fetchpriority=high]")?.absUrl("src") + listOf(Page(0, imageUrl = imageUrl)) + } else { + buttons.mapIndexed { i, button -> // Remove everything past "/v1/" to get original instead of thumbnail - val imageUrl = button.selectFirst("img")?.absUrl("src")?.substringBefore("/v1/") + // But need to preserve the query parameter where the token is + val imageUrl = button.selectFirst("img")?.absUrl("src") + ?.replaceFirst(Regex("""/v1(/.*)?(?=\?)"""), "") Page(i, imageUrl = imageUrl) - }.also { - // First image needs token to get original, which is included in firstImageUrl - it[0].imageUrl = firstImageUrl } } }