EroMuse - fix missing chapters (#4105)

This commit is contained in:
Mike 2020-08-13 03:06:27 -04:00 committed by GitHub
parent 560bbfb16a
commit 56198e2661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 25 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'EroMuse (8muses and Erofus)'
pkgNameSuffix = 'all.eromuse'
extClass = '.EroMuseFactory'
extVersionCode = 1
extVersionCode = 2
libVersion = '1.2'
containsNsfw = true
}

View File

@ -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,17 +214,18 @@ 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<SChapter> {
val document = response.asJsoup()
// Linked albums
val chapters = document.select(linkedChapterSelector)
fun parseChapters(document: Document, isFirstPage: Boolean, chapters: ArrayDeque<SChapter>): List<SChapter> {
// Linked chapters
document.select(linkedChapterSelector)
.mapNotNull {
chapters.addFirst(
SChapter.create().apply {
name = it.text()
setUrlWithoutDomain(it.attr("href"))
}
)
}
.reversed()
.toMutableList()
if (isFirstPage) {
// Self
document.select(pageThumbnailSelector).firstOrNull()?.let {
chapters.add(
@ -230,9 +235,14 @@ open class EroMuse(override val name: String, override val baseUrl: String) : Ht
}
)
}
}
document.nextPageOrNull()?.let { url -> parseChapters(client.newCall(GET(url, headers)).execute().asJsoup(), false, chapters) }
return chapters
}
return parseChapters(response.asJsoup(), true, ArrayDeque())
}
// Pages
protected open val pageThumbnailPathSegment = "/th/"