From b0eda7b44d75153ad4af4b4181561574580c3d8f Mon Sep 17 00:00:00 2001 From: DokterKaj <54882101+DokterKaj@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:44:54 +0800 Subject: [PATCH] DeviantArt: Support multi-image posts (#7305) * Support multi-image posts * Get substring before "/v1/" for better reliability * Minor tweaks --- src/all/deviantart/build.gradle | 2 +- .../extension/all/deviantart/DeviantArt.kt | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/all/deviantart/build.gradle b/src/all/deviantart/build.gradle index 464ba363d..afdd9f7b5 100644 --- a/src/all/deviantart/build.gradle +++ b/src/all/deviantart/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'DeviantArt' extClass = '.DeviantArt' - extVersionCode = 3 + extVersionCode = 4 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 ac041baec..0150b59a5 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 @@ -123,15 +123,14 @@ class DeviantArt : HttpSource() { nextUrl = newDocument.selectFirst("[rel=next]")?.absUrl("href") } - return indexChapterList(chapterList.toList()) + return chapterList.toList().also(::indexChapterList) } private fun parseToChapterList(document: Document): List { val items = document.select("item") return items.map { - val chapter = SChapter.create() - chapter.setUrlWithoutDomain(it.selectFirst("link")!!.text()) - chapter.apply { + SChapter.create().apply { + setUrlWithoutDomain(it.selectFirst("link")!!.text()) name = it.selectFirst("title")!!.text() date_upload = parseDate(it.selectFirst("pubDate")?.text()) scanlator = it.selectFirst("media|credit")?.text() @@ -139,24 +138,34 @@ class DeviantArt : HttpSource() { } } - private fun indexChapterList(chapterList: List): List { + private fun indexChapterList(chapterList: List) { // DeviantArt allows users to arrange galleries arbitrarily so we will // primitively index the list by checking the first and last dates - return if (chapterList.first().date_upload > chapterList.last().date_upload) { - chapterList.mapIndexed { i, chapter -> - chapter.apply { chapter_number = chapterList.size - i.toFloat() } + if (chapterList.first().date_upload > chapterList.last().date_upload) { + chapterList.forEachIndexed { i, chapter -> + chapter.chapter_number = chapterList.size - i.toFloat() } } else { - chapterList.mapIndexed { i, chapter -> - chapter.apply { chapter_number = i.toFloat() + 1 } + chapterList.forEachIndexed { i, chapter -> + chapter.chapter_number = i.toFloat() + 1 } } } override fun pageListParse(response: Response): List { val document = response.asJsoup() - val imageUrl = document.selectFirst("img[fetchpriority=high]")?.absUrl("src") - return listOf(Page(0, imageUrl = imageUrl)) + val firstImageUrl = document.selectFirst("img[fetchpriority=high]")?.absUrl("src") + val buttons = document.selectFirst("[draggable=false]")?.children() + return buttons?.mapIndexed { i, button -> + // Remove everything past "/v1/" to get original instead of thumbnail + val imageUrl = button.selectFirst("img")?.absUrl("src")?.substringBefore("/v1/") + Page(i, imageUrl = imageUrl) + }?.also { + // First image needs token to get original, which is included in firstImageUrl + it[0].imageUrl = firstImageUrl + } + // If there are no buttons then chapter only has one page + ?: listOf(Page(0, imageUrl = firstImageUrl)) } override fun imageUrlParse(response: Response): String {