Skip to content

Commit

Permalink
AsuraScans: Fix pages not found (#6134)
Browse files Browse the repository at this point in the history
* fix chapter pages

* fix chapter name

* merge nextjs chunks
  • Loading branch information
bapeey authored Nov 19, 2024
1 parent 8c9d539 commit d187423
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/en/asurascans/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Asura Scans'
extClass = '.AsuraScans'
extVersionCode = 41
extVersionCode = 42
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -265,9 +267,11 @@ class AsuraScans : ParsedHttpSource(), ConfigurableSource {
}

override fun pageListParse(document: Document): List<Page> {
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<List<PageDto>>(pagesData.unescape()).sortedBy { it.order }
return pageList.mapIndexed { i, page -> Page(i, imageUrl = page.url) }
}

override fun imageUrlParse(document: Document) = throw UnsupportedOperationException()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ class FilterItemDto(
val id: Int,
val name: String,
)

@Serializable
class PageDto(
val order: Int,
val url: String,
)

0 comments on commit d187423

Please sign in to comment.