TwoKinds: Account for special chapters (#14408)
* TwoKinds: Account for special chapters * Fix duplicated pages, trim last chapter in 20 pages manga
This commit is contained in:
parent
e7f692d8a2
commit
073ee70a00
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'keenspot'
|
extName = 'keenspot'
|
||||||
pkgNameSuffix = 'en.keenspot'
|
pkgNameSuffix = 'en.keenspot'
|
||||||
extClass = '.KeenspotFactory'
|
extClass = '.KeenspotFactory'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.util.asJsoup
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
class TwoKinds : HttpSource() {
|
class TwoKinds : HttpSource() {
|
||||||
|
|
||||||
|
@ -83,41 +84,46 @@ class TwoKinds : HttpSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListRequest(manga: SManga): Request {
|
override fun chapterListRequest(manga: SManga): Request {
|
||||||
return GET(baseUrl, headers)
|
return GET("$baseUrl/archive/", headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListParse(response: Response): List<SChapter> = throw Exception("Not used")
|
override fun chapterListParse(response: Response): List<SChapter> = throw Exception("Not used")
|
||||||
|
|
||||||
|
data class TwoKindsPage(val url: String, val name: String)
|
||||||
|
|
||||||
fun chapterListParse(response: Response, manga: SManga): List<SChapter> {
|
fun chapterListParse(response: Response, manga: SManga): List<SChapter> {
|
||||||
val document = response.asJsoup()
|
val document = response.asJsoup()
|
||||||
|
|
||||||
val lastPage = document.select(".navprev").first().attr("href").split("/")[2].toInt() + 1
|
val pages = document.select(".chapter-links")
|
||||||
|
.flatMap { season -> season.select("> a") }
|
||||||
|
.map { a ->
|
||||||
|
// /comic/1185halloween/ -> 1185halloween
|
||||||
|
val urlPart = a.attr("href").split("/")[2]
|
||||||
|
val name = a.selectFirst("span").text()
|
||||||
|
|
||||||
val chapters = mutableListOf<SChapter>()
|
TwoKindsPage(urlPart, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1 page per chapter
|
||||||
if (manga.url == "1") {
|
if (manga.url == "1") {
|
||||||
for (i in 1..lastPage) {
|
return pages.map { page ->
|
||||||
chapters.add(
|
SChapter.create().apply {
|
||||||
SChapter.create().apply() {
|
url = "1-${page.url}"
|
||||||
url = "1-$i"
|
name = "Page ${page.name}"
|
||||||
name = "Page $i"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i in 1..lastPage step 20) {
|
|
||||||
chapters.add(
|
|
||||||
SChapter.create().apply() {
|
|
||||||
url = "20-$i"
|
|
||||||
if (i + 20 > lastPage)
|
|
||||||
name = "Pages $i-$lastPage"
|
|
||||||
else
|
|
||||||
name = "Pages $i-${i + 20}"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
}.reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 20 pages per chapter
|
||||||
|
val chapters = mutableListOf<SChapter>()
|
||||||
|
for (i in pages.indices step 20) {
|
||||||
|
chapters.add(
|
||||||
|
SChapter.create().apply {
|
||||||
|
url = "20-${pages[i].url}"
|
||||||
|
name = "Pages ${pages[i].name}-${pages[min(pages.size, i + 20) - 1].name}"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
return chapters.reversed()
|
return chapters.reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,15 +135,29 @@ class TwoKinds : HttpSource() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val pages = mutableListOf<Page>()
|
val firstPage = chapter.url.substringAfter("-")
|
||||||
val firstPage = chapter.url.substringAfter("-").toInt()
|
val document = client.newCall(chapterListRequest(SManga.create())).execute().asJsoup()
|
||||||
|
|
||||||
for (i in firstPage..firstPage + 19) {
|
val pages = document.select(".chapter-links")
|
||||||
pages.add(
|
.flatMap { season -> season.select("> a") }
|
||||||
Page(i - firstPage, baseUrl + "/comic/$i/")
|
.map { a ->
|
||||||
)
|
// /comic/1185halloween/ -> 1185halloween
|
||||||
|
val urlPart = a.attr("href").split("/")[2]
|
||||||
|
val name = a.selectFirst("span").text()
|
||||||
|
|
||||||
|
TwoKindsPage(urlPart, name)
|
||||||
}
|
}
|
||||||
return Observable.just(pages)
|
|
||||||
|
val firstPageIdx = pages.indexOfFirst { it.url == firstPage }
|
||||||
|
val lastPageIdx = min(pages.size, firstPageIdx + 20)
|
||||||
|
|
||||||
|
return Observable.just(
|
||||||
|
pages
|
||||||
|
.subList(firstPageIdx, lastPageIdx)
|
||||||
|
.mapIndexed { idx, page ->
|
||||||
|
Page(idx, baseUrl + "/comic/${page.url}/")
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue