diff --git a/src/en/asurascans/build.gradle b/src/en/asurascans/build.gradle index 871119a47..e0bcfdb04 100644 --- a/src/en/asurascans/build.gradle +++ b/src/en/asurascans/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Asura Scans' extClass = '.AsuraScans' - extVersionCode = 41 + extVersionCode = 42 } apply from: "$rootDir/common.gradle" diff --git a/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt b/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt index f6069d74b..fb640134f 100644 --- a/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt +++ b/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScans.kt @@ -245,7 +245,9 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { override fun chapterFromElement(element: Element) = SChapter.create().apply { setUrlWithoutDomain(element.selectFirst("a")!!.attr("abs:href").toPermSlugIfNeeded()) - name = element.selectFirst("h3")!!.text() + val chNumber = element.selectFirst("h3 > a")!!.ownText() + val chTitle = element.select("h3 > a > span").joinToString(" ") { it.ownText() } + name = if (chTitle.isBlank()) chNumber else "$chNumber - $chTitle" date_upload = try { val text = element.selectFirst("h3 + h3")!!.ownText() val cleanText = text.replace(CLEAN_DATE_REGEX, "$1") @@ -265,9 +267,11 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { } override fun pageListParse(document: Document): List { - return document.select("div > img[alt*=chapter]").mapIndexed { i, element -> - Page(i, imageUrl = element.attr("abs:src")) - } + val scriptData = document.select("script:containsData(self.__next_f.push)") + .joinToString("") { it.data().substringAfter("\"").substringBeforeLast("\"") } + val pagesData = PAGES_REGEX.find(scriptData)?.groupValues?.get(1) ?: throw Exception("Failed to find chapter pages") + val pageList = json.decodeFromString>(pagesData.unescape()).sortedBy { it.order } + return pageList.mapIndexed { i, page -> Page(i, imageUrl = page.url) } } override fun imageUrlParse(document: Document) = throw UnsupportedOperationException() @@ -311,7 +315,13 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource { return this.replace(slug, absSlug) } + private fun String.unescape(): String { + return UNESCAPE_REGEX.replace(this, "$1") + } + companion object { + private val UNESCAPE_REGEX = """\\(.)""".toRegex() + private val PAGES_REGEX = """\\"pages\\":(\[.*?])""".toRegex() private val CLEAN_DATE_REGEX = """(\d+)(st|nd|rd|th)""".toRegex() private val OLD_FORMAT_MANGA_REGEX = """^/manga/(\d+-)?([^/]+)/?$""".toRegex() private val OLD_FORMAT_CHAPTER_REGEX = """^/(\d+-)?[^/]*-chapter-\d+(-\d+)*/?$""".toRegex() diff --git a/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScansDto.kt b/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScansDto.kt index e40081ca7..b89ab68da 100644 --- a/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScansDto.kt +++ b/src/en/asurascans/src/eu/kanade/tachiyomi/extension/en/asurascans/AsuraScansDto.kt @@ -14,3 +14,9 @@ class FilterItemDto( val id: Int, val name: String, ) + +@Serializable +class PageDto( + val order: Int, + val url: String, +)