diff --git a/src/all/eromuse/build.gradle b/src/all/eromuse/build.gradle index 904f0b549..696cea80b 100644 --- a/src/all/eromuse/build.gradle +++ b/src/all/eromuse/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'EroMuse (8muses and Erofus)' pkgNameSuffix = 'all.eromuse' extClass = '.EroMuseFactory' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' containsNsfw = true } diff --git a/src/all/eromuse/src/eu/kanade/tachiyomi/extension/all/eromuse/EroMuse.kt b/src/all/eromuse/src/eu/kanade/tachiyomi/extension/all/eromuse/EroMuse.kt index 8ff8ba023..37aab49d4 100644 --- a/src/all/eromuse/src/eu/kanade/tachiyomi/extension/all/eromuse/EroMuse.kt +++ b/src/all/eromuse/src/eu/kanade/tachiyomi/extension/all/eromuse/EroMuse.kt @@ -51,12 +51,13 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht protected open val topLevelPathSegments = listOf("album", "Various-Authors") private val pageQueryRegex = Regex("""page=\d+""") - private fun Document.addNextPageToStack() { - this.select(nextPageSelector).firstOrNull()?.text()?.toIntOrNull()?.let { int -> - val nextPage = if (stackItem.url.contains(pageQueryRegex)) { - stackItem.url.replace(pageQueryRegex, "page=$int") + private fun Document.nextPageOrNull(): String? { + val url = this.location() + return this.select(nextPageSelector).firstOrNull()?.text()?.toIntOrNull()?.let { int -> + if (url.contains(pageQueryRegex)) { + url.replace(pageQueryRegex, "page=$int") } else { - val httpUrl = HttpUrl.parse(stackItem.url)!! + val httpUrl = HttpUrl.parse(url)!! val builder = if (httpUrl.pathSegments().last().toIntOrNull() is Int) { httpUrl.newBuilder().removePathSegment(httpUrl.pathSegments().lastIndex) } else { @@ -64,10 +65,13 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht } builder.addPathSegment(int.toString()).toString() } - pageStack.add(StackItem(nextPage, stackItem.pageType)) } } + private fun Document.addNextPageToStack() { + this.nextPageOrNull()?.let { pageStack.add(StackItem(it, stackItem.pageType)) } + } + protected fun Element.imgAttr(): String = if (this.hasAttr("data-src")) this.attr("abs:data-src") else this.attr("abs:src") private fun mangaFromElement(element: Element): SManga { @@ -210,27 +214,33 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht protected open val pageThumbnailSelector = "a.c-tile:has(img)[href*=/comics/picture/] img" override fun chapterListParse(response: Response): List { - val document = response.asJsoup() - // Linked albums - val chapters = document.select(linkedChapterSelector) - .mapNotNull { - SChapter.create().apply { - name = it.text() - setUrlWithoutDomain(it.attr("href")) + fun parseChapters(document: Document, isFirstPage: Boolean, chapters: ArrayDeque): List { + // Linked chapters + document.select(linkedChapterSelector) + .mapNotNull { + chapters.addFirst( + SChapter.create().apply { + name = it.text() + setUrlWithoutDomain(it.attr("href")) + } + ) + } + if (isFirstPage) { + // Self + document.select(pageThumbnailSelector).firstOrNull()?.let { + chapters.add( + SChapter.create().apply { + name = "Chapter" + setUrlWithoutDomain(response.request().url().toString()) + } + ) } } - .reversed() - .toMutableList() - // Self - document.select(pageThumbnailSelector).firstOrNull()?.let { - chapters.add( - SChapter.create().apply { - name = "Chapter" - setUrlWithoutDomain(response.request().url().toString()) - } - ) + document.nextPageOrNull()?.let { url -> parseChapters(client.newCall(GET(url, headers)).execute().asJsoup(), false, chapters) } + return chapters } - return chapters + + return parseChapters(response.asJsoup(), true, ArrayDeque()) } // Pages