diff --git a/src/en/keenspot/build.gradle b/src/en/keenspot/build.gradle index 96c494faf..12f570acc 100644 --- a/src/en/keenspot/build.gradle +++ b/src/en/keenspot/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'keenspot' pkgNameSuffix = 'en.keenspot' extClass = '.KeenspotFactory' - extVersionCode = 2 + extVersionCode = 3 } apply from: "$rootDir/common.gradle" diff --git a/src/en/keenspot/src/eu/kanade/tachiyomi/extension/en/keenspot/TwoKinds.kt b/src/en/keenspot/src/eu/kanade/tachiyomi/extension/en/keenspot/TwoKinds.kt index 9d97a3b32..03a6eeb9f 100644 --- a/src/en/keenspot/src/eu/kanade/tachiyomi/extension/en/keenspot/TwoKinds.kt +++ b/src/en/keenspot/src/eu/kanade/tachiyomi/extension/en/keenspot/TwoKinds.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Request import okhttp3.Response import rx.Observable +import kotlin.math.min class TwoKinds : HttpSource() { @@ -83,41 +84,46 @@ class TwoKinds : HttpSource() { } override fun chapterListRequest(manga: SManga): Request { - return GET(baseUrl, headers) + return GET("$baseUrl/archive/", headers) } override fun chapterListParse(response: Response): List = throw Exception("Not used") + data class TwoKindsPage(val url: String, val name: String) + fun chapterListParse(response: Response, manga: SManga): List { 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() + TwoKindsPage(urlPart, name) + } + // 1 page per chapter if (manga.url == "1") { - for (i in 1..lastPage) { - chapters.add( - SChapter.create().apply() { - url = "1-$i" - 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}" - } - ) - } + return pages.map { page -> + SChapter.create().apply { + url = "1-${page.url}" + name = "Page ${page.name}" + } + }.reversed() } + // 20 pages per chapter + val chapters = mutableListOf() + 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() } @@ -129,15 +135,29 @@ class TwoKinds : HttpSource() { ) ) } else { - val pages = mutableListOf() - val firstPage = chapter.url.substringAfter("-").toInt() + val firstPage = chapter.url.substringAfter("-") + val document = client.newCall(chapterListRequest(SManga.create())).execute().asJsoup() - for (i in firstPage..firstPage + 19) { - pages.add( - Page(i - firstPage, baseUrl + "/comic/$i/") - ) - } - return Observable.just(pages) + 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() + + TwoKindsPage(urlPart, name) + } + + 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}/") + } + ) } }