FoamGirl: Fix pages loading (#6146)
* Fix loading pages * Use regex * Cleanup * Remove NUMB_REGEX Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com> * Remove extra return Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com> * Refactoring pageList Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com> * Refactoring 'getPagesListByNumber' --------- Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com>
This commit is contained in:
parent
855a25518b
commit
ea99590719
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'FoamGirl'
|
extName = 'FoamGirl'
|
||||||
extClass = '.FoamGirl'
|
extClass = '.FoamGirl'
|
||||||
extVersionCode = 1
|
extVersionCode = 2
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||||
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
|
@ -65,22 +67,43 @@ class FoamGirl() : ParsedHttpSource() {
|
||||||
override fun searchMangaSelector() = popularMangaSelector()
|
override fun searchMangaSelector() = popularMangaSelector()
|
||||||
|
|
||||||
override fun pageListParse(document: Document): List<Page> {
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val pages = mutableListOf<Page>()
|
|
||||||
val imageCount = document.select(".post_title_topimg").text().substringAfter("(").substringBefore("P").toInt()
|
val imageCount = document.select(".post_title_topimg").text().substringAfter("(").substringBefore("P").toInt()
|
||||||
val imageUrl = document.select(".imageclick-imgbox").attr("href").toHttpUrl()
|
val imageUrl = document.select(".imageclick-imgbox").attr("href").toHttpUrl()
|
||||||
val imagePrefix = imageUrl.pathSegments.last().substringBefore(".").toLong() / 10
|
val baseIndex = imageUrl.pathSegments.last().substringBefore(".")
|
||||||
for (i in 0 until imageCount) {
|
|
||||||
pages.add(
|
return if (baseIndex.isNumber()) {
|
||||||
|
getPagesListByNumber(imageCount, imageUrl, baseIndex)
|
||||||
|
} else {
|
||||||
|
getPageListByDocument(document)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getPagesListByNumber(imageCount: Int, imageUrl: HttpUrl, baseIndex: String): List<Page> {
|
||||||
|
val imagePrefix = baseIndex.toLong() / 10
|
||||||
|
return (0 until imageCount).map { index ->
|
||||||
Page(
|
Page(
|
||||||
i,
|
index,
|
||||||
imageUrl = imageUrl.newBuilder().apply {
|
imageUrl = imageUrl.newBuilder().apply {
|
||||||
removePathSegment(imageUrl.pathSize - 1)
|
removePathSegment(imageUrl.pathSize - 1)
|
||||||
addPathSegment("${imagePrefix}${i + 2}.jpg")
|
addPathSegment("${imagePrefix}${index + 2}.jpg")
|
||||||
}.build().toString(),
|
}.build().toString(),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return pages
|
}
|
||||||
|
|
||||||
|
private fun getPageListByDocument(document: Document): List<Page> {
|
||||||
|
val pages = document.select("#image_div img").mapIndexed { index, element ->
|
||||||
|
Page(index, imageUrl = element.absUrl("src"))
|
||||||
|
}.toList()
|
||||||
|
|
||||||
|
val nextPageUrl = document.selectFirst(".page-numbers[title=Next]")
|
||||||
|
?.absUrl("href")
|
||||||
|
?.takeIf { HAS_NEXT_PAGE_REGEX in it }
|
||||||
|
?: return pages
|
||||||
|
|
||||||
|
return client.newCall(GET(nextPageUrl, headers)).execute().asJsoup().let {
|
||||||
|
pages + getPageListByDocument(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element) = SChapter.create().apply {
|
override fun chapterFromElement(element: Element) = SChapter.create().apply {
|
||||||
|
@ -119,7 +142,10 @@ class FoamGirl() : ParsedHttpSource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.isNumber() = isNotEmpty() && all { it.isDigit() }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val HAS_NEXT_PAGE_REGEX = """(\d+_\d+)""".toRegex()
|
||||||
private val DATE_FORMAT by lazy {
|
private val DATE_FORMAT by lazy {
|
||||||
SimpleDateFormat("yyyy.M.d", Locale.ENGLISH)
|
SimpleDateFormat("yyyy.M.d", Locale.ENGLISH)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue